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