1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.buildDynamicImport = buildDynamicImport;
|
---|
7 | var _core = require("@babel/core");
|
---|
8 | {
|
---|
9 | exports.getDynamicImportSource = function getDynamicImportSource(node) {
|
---|
10 | const [source] = node.arguments;
|
---|
11 | return _core.types.isStringLiteral(source) || _core.types.isTemplateLiteral(source) ? source : _core.template.expression.ast`\`\${${source}}\``;
|
---|
12 | };
|
---|
13 | }
|
---|
14 | function buildDynamicImport(node, deferToThen, wrapWithPromise, builder) {
|
---|
15 | const specifier = _core.types.isCallExpression(node) ? node.arguments[0] : node.source;
|
---|
16 | if (_core.types.isStringLiteral(specifier) || _core.types.isTemplateLiteral(specifier) && specifier.quasis.length === 0) {
|
---|
17 | if (deferToThen) {
|
---|
18 | return _core.template.expression.ast`
|
---|
19 | Promise.resolve().then(() => ${builder(specifier)})
|
---|
20 | `;
|
---|
21 | } else return builder(specifier);
|
---|
22 | }
|
---|
23 | const specifierToString = _core.types.isTemplateLiteral(specifier) ? _core.types.identifier("specifier") : _core.types.templateLiteral([_core.types.templateElement({
|
---|
24 | raw: ""
|
---|
25 | }), _core.types.templateElement({
|
---|
26 | raw: ""
|
---|
27 | })], [_core.types.identifier("specifier")]);
|
---|
28 | if (deferToThen) {
|
---|
29 | return _core.template.expression.ast`
|
---|
30 | (specifier =>
|
---|
31 | new Promise(r => r(${specifierToString}))
|
---|
32 | .then(s => ${builder(_core.types.identifier("s"))})
|
---|
33 | )(${specifier})
|
---|
34 | `;
|
---|
35 | } else if (wrapWithPromise) {
|
---|
36 | return _core.template.expression.ast`
|
---|
37 | (specifier =>
|
---|
38 | new Promise(r => r(${builder(specifierToString)}))
|
---|
39 | )(${specifier})
|
---|
40 | `;
|
---|
41 | } else {
|
---|
42 | return _core.template.expression.ast`
|
---|
43 | (specifier => ${builder(specifierToString)})(${specifier})
|
---|
44 | `;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | //# sourceMappingURL=dynamic-import.js.map
|
---|