Files
babel/packages/babel-plugin-transform-react-jsx-self/src/index.js
Nicolò Ribaudo a2aabbd33d Generate better builder names for JSX* and TS* (#6967)
e.g. JSXIdentifier -> jsxIdentifier.
The jSXIdentifier alias isn't removed, so this commit doesn't introduce breaking changes.
2017-12-07 12:17:40 +01:00

32 lines
587 B
JavaScript

/**
* This adds a __self={this} JSX attribute to all JSX elements, which React will use
* to generate some runtime warnings.
*
*
* == JSX Literals ==
*
* <sometag />
*
* becomes:
*
* <sometag __self={this} />
*/
import { types as t } from "@babel/core";
const TRACE_ID = "__self";
export default function() {
const visitor = {
JSXOpeningElement({ node }) {
const id = t.jsxIdentifier(TRACE_ID);
const trace = t.thisExpression();
node.attributes.push(t.jsxAttribute(id, t.jsxExpressionContainer(trace)));
},
};
return {
visitor,
};
}