lazy-modules.js 1005 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.toGetWrapperPayload = toGetWrapperPayload;
  6. exports.wrapReference = wrapReference;
  7. var _core = require("@babel/core");
  8. var _normalizeAndLoadMetadata = require("./normalize-and-load-metadata.js");
  9. function toGetWrapperPayload(lazy) {
  10. return (source, metadata) => {
  11. if (lazy === false) return null;
  12. if ((0, _normalizeAndLoadMetadata.isSideEffectImport)(metadata) || metadata.reexportAll) return null;
  13. if (lazy === true) {
  14. return source.includes(".") ? null : "lazy";
  15. }
  16. if (Array.isArray(lazy)) {
  17. return !lazy.includes(source) ? null : "lazy";
  18. }
  19. if (typeof lazy === "function") {
  20. return lazy(source) ? "lazy" : null;
  21. }
  22. throw new Error(`.lazy must be a boolean, string array, or function`);
  23. };
  24. }
  25. function wrapReference(ref, payload) {
  26. if (payload === "lazy") return _core.types.callExpression(ref, []);
  27. return null;
  28. }
  29. //# sourceMappingURL=lazy-modules.js.map