sugar-fragment.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. const t = __importStar(require("@babel/types"));
  23. const utils_1 = require("./utils");
  24. const transformFragment = (path, Fragment) => {
  25. const children = path.get('children') || [];
  26. return t.jsxElement(t.jsxOpeningElement(Fragment, []), t.jsxClosingElement(Fragment), children.map(({ node }) => node), false);
  27. };
  28. exports.default = ({
  29. JSXFragment: {
  30. enter(path, state) {
  31. const fragmentCallee = (0, utils_1.createIdentifier)(state, utils_1.FRAGMENT);
  32. path.replaceWith(transformFragment(path, t.isIdentifier(fragmentCallee)
  33. ? t.jsxIdentifier(fragmentCallee.name)
  34. : t.jsxMemberExpression(t.jsxIdentifier(fragmentCallee.object.name), t.jsxIdentifier(fragmentCallee.property.name))));
  35. },
  36. },
  37. });
  38. //# sourceMappingURL=sugar-fragment.js.map