Added jsx-self babel transform plugin

This commit is contained in:
jim
2016-06-20 16:22:59 -07:00
parent b2390cca02
commit 7d0c4ecf17
9 changed files with 111 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
/**
* This adds {fileName, lineNumber} annotations to React component definitions
* and to jsx tag literals.
*
*
* == JSX Literals ==
*
* <sometag />
*
* becomes:
*
* <sometag __self={this} />
*/
const TRACE_ID = "__self";
export default function ({ types: t }) {
let visitor = {
JSXOpeningElement(node) {
const id = t.jSXIdentifier(TRACE_ID);
const trace = t.identifier("this");
node.container.openingElement.attributes.push(t.jSXAttribute(id, t.jSXExpressionContainer(trace)));
}
};
return {
visitor
};
}