lazy.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.lazyImportsHook = void 0;
  6. var _core = require("@babel/core");
  7. var _helperModuleTransforms = require("@babel/helper-module-transforms");
  8. const lazyImportsHook = lazy => ({
  9. name: `${"@babel/plugin-transform-modules-commonjs"}/lazy`,
  10. version: "7.25.9",
  11. getWrapperPayload(source, metadata) {
  12. if ((0, _helperModuleTransforms.isSideEffectImport)(metadata) || metadata.reexportAll) {
  13. return null;
  14. }
  15. if (lazy === true) {
  16. return source.includes(".") ? null : "lazy/function";
  17. }
  18. if (Array.isArray(lazy)) {
  19. return !lazy.includes(source) ? null : "lazy/function";
  20. }
  21. if (typeof lazy === "function") {
  22. return lazy(source) ? "lazy/function" : null;
  23. }
  24. },
  25. buildRequireWrapper(name, init, payload, referenced) {
  26. if (payload === "lazy/function") {
  27. if (!referenced) return false;
  28. return _core.template.statement.ast`
  29. function ${name}() {
  30. const data = ${init};
  31. ${name} = function(){ return data; };
  32. return data;
  33. }
  34. `;
  35. }
  36. },
  37. wrapReference(ref, payload) {
  38. if (payload === "lazy/function") return _core.types.callExpression(ref, []);
  39. }
  40. });
  41. exports.lazyImportsHook = lazyImportsHook;
  42. //# sourceMappingURL=lazy.js.map