index.js 770 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _helperPluginUtils = require("@babel/helper-plugin-utils");
  7. var _core = require("@babel/core");
  8. const TRACE_ID = "__self";
  9. var _default = (0, _helperPluginUtils.declare)(api => {
  10. api.assertVersion(7);
  11. const visitor = {
  12. JSXOpeningElement({
  13. node
  14. }) {
  15. const id = _core.types.jsxIdentifier(TRACE_ID);
  16. const trace = _core.types.thisExpression();
  17. node.attributes.push(_core.types.jsxAttribute(id, _core.types.jsxExpressionContainer(trace)));
  18. }
  19. };
  20. return {
  21. name: "transform-react-jsx-self",
  22. visitor: {
  23. Program(path) {
  24. path.traverse(visitor);
  25. }
  26. }
  27. };
  28. });
  29. exports.default = _default;