securityos/node_modules/@babel/helper-module-transforms/lib/dynamic-import.js.map

1 line
3.6 KiB
Plaintext
Raw Normal View History

2024-09-06 15:32:35 +00:00
{"version":3,"names":["getDynamicImportSource","node","source","arguments","t","isStringLiteral","isTemplateLiteral","template","expression","ast","buildDynamicImport","deferToThen","wrapWithPromise","builder","specifier","quasis","length","specifierToString","identifier","templateLiteral","templateElement","raw"],"sources":["../src/dynamic-import.ts"],"sourcesContent":["// Heavily inspired by\n// https://github.com/airbnb/babel-plugin-dynamic-import-node/blob/master/src/utils.js\n\nimport * as t from \"@babel/types\";\nimport template from \"@babel/template\";\n\n// TODO(Babel 8): Remove this\nexport function getDynamicImportSource(\n node: t.CallExpression,\n): t.StringLiteral | t.TemplateLiteral {\n const [source] = node.arguments;\n\n return t.isStringLiteral(source) || t.isTemplateLiteral(source)\n ? source\n : (template.expression.ast`\\`\\${${source}}\\`` as t.TemplateLiteral);\n}\n\nexport function buildDynamicImport(\n node: t.CallExpression,\n deferToThen: boolean,\n wrapWithPromise: boolean,\n builder: (specifier: t.Expression) => t.Expression,\n): t.Expression {\n const [specifier] = node.arguments;\n\n if (\n t.isStringLiteral(specifier) ||\n (t.isTemplateLiteral(specifier) && specifier.quasis.length === 0)\n ) {\n if (deferToThen) {\n return template.expression.ast`\n Promise.resolve().then(() => ${builder(specifier)})\n `;\n } else return builder(specifier);\n }\n\n const specifierToString = t.isTemplateLiteral(specifier)\n ? t.identifier(\"specifier\")\n : t.templateLiteral(\n [t.templateElement({ raw: \"\" }), t.templateElement({ raw: \"\" })],\n [t.identifier(\"specifier\")],\n );\n\n if (deferToThen) {\n return template.expression.ast`\n (specifier =>\n new Promise(r => r(${specifierToString}))\n .then(s => ${builder(t.identifier(\"s\"))})\n )(${specifier})\n `;\n } else if (wrapWithPromise) {\n return template.expression.ast`\n (specifier =>\n new Promise(r => r(${builder(specifierToString)}))\n )(${specifier})\n `;\n } else {\n return template.expression.ast`\n (specifier => ${builder(specifierToString)})(${specifier})\n `;\n }\n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