Added jsx-self babel transform plugin
This commit is contained in:
30
packages/babel-plugin-transform-react-jsx-self/src/index.js
Normal file
30
packages/babel-plugin-transform-react-jsx-self/src/index.js
Normal 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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user