diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
| commit | aa773172311dcada759dfbaac485f4bc6e00bc21 (patch) | |
| tree | ca6d9a5eff3ab8f689f9acb4f0df791d9486813d /node_modules/@babel/plugin-transform-modules-commonjs/lib | |
| parent | c5a5384e846f242e901e859fe600d695d8990a9a (diff) | |
added babel
Diffstat (limited to 'node_modules/@babel/plugin-transform-modules-commonjs/lib')
8 files changed, 299 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/dynamic-import.js b/node_modules/@babel/plugin-transform-modules-commonjs/lib/dynamic-import.js new file mode 100644 index 00000000..ac6c9ecd --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/dynamic-import.js @@ -0,0 +1,16 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.transformDynamicImport = transformDynamicImport; +var _core = require("@babel/core"); +var _helperModuleTransforms = require("@babel/helper-module-transforms"); +const requireNoInterop = source => _core.template.expression.ast`require(${source})`; +const requireInterop = (source, file) => _core.types.callExpression(file.addHelper("interopRequireWildcard"), [requireNoInterop(source)]); +function transformDynamicImport(path, noInterop, file) { + const buildRequire = noInterop ? requireNoInterop : requireInterop; + path.replaceWith((0, _helperModuleTransforms.buildDynamicImport)(path.node, true, false, specifier => buildRequire(specifier, file))); +} + +//# sourceMappingURL=dynamic-import.js.map diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/dynamic-import.js.map b/node_modules/@babel/plugin-transform-modules-commonjs/lib/dynamic-import.js.map new file mode 100644 index 00000000..e1997c58 --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/dynamic-import.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_core","require","_helperModuleTransforms","requireNoInterop","source","template","expression","ast","requireInterop","file","t","callExpression","addHelper","transformDynamicImport","path","noInterop","buildRequire","replaceWith","buildDynamicImport","node","specifier"],"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 type { NodePath } from \"@babel/traverse\";\nimport { types as t, template, type File } from \"@babel/core\";\nimport { buildDynamicImport } from \"@babel/helper-module-transforms\";\n\nconst requireNoInterop = (source: t.Expression) =>\n template.expression.ast`require(${source})`;\n\nconst requireInterop = (source: t.Expression, file: File) =>\n t.callExpression(file.addHelper(\"interopRequireWildcard\"), [\n requireNoInterop(source),\n ]);\n\nexport function transformDynamicImport(\n path: NodePath<t.CallExpression | t.ImportExpression>,\n noInterop: boolean,\n file: File,\n) {\n const buildRequire = noInterop ? requireNoInterop : requireInterop;\n\n path.replaceWith(\n buildDynamicImport(path.node, true, false, specifier =>\n buildRequire(specifier, file),\n ),\n );\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AAEA,MAAME,gBAAgB,GAAIC,MAAoB,IAC5CC,cAAQ,CAACC,UAAU,CAACC,GAAI,WAAUH,MAAO,GAAE;AAE7C,MAAMI,cAAc,GAAGA,CAACJ,MAAoB,EAAEK,IAAU,KACtDC,WAAC,CAACC,cAAc,CAACF,IAAI,CAACG,SAAS,CAAC,wBAAwB,CAAC,EAAE,CACzDT,gBAAgB,CAACC,MAAM,CAAC,CACzB,CAAC;AAEG,SAASS,sBAAsBA,CACpCC,IAAqD,EACrDC,SAAkB,EAClBN,IAAU,EACV;EACA,MAAMO,YAAY,GAAGD,SAAS,GAAGZ,gBAAgB,GAAGK,cAAc;EAElEM,IAAI,CAACG,WAAW,CACd,IAAAC,0CAAkB,EAACJ,IAAI,CAACK,IAAI,EAAE,IAAI,EAAE,KAAK,EAAEC,SAAS,IAClDJ,YAAY,CAACI,SAAS,EAAEX,IAAI,CAC9B,CACF,CAAC;AACH"}
\ No newline at end of file diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/hooks.js b/node_modules/@babel/plugin-transform-modules-commonjs/lib/hooks.js new file mode 100644 index 00000000..af92a650 --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/hooks.js @@ -0,0 +1,37 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.defineCommonJSHook = defineCommonJSHook; +exports.makeInvokers = makeInvokers; +const commonJSHooksKey = "@babel/plugin-transform-modules-commonjs/customWrapperPlugin"; +function defineCommonJSHook(file, hook) { + let hooks = file.get(commonJSHooksKey); + if (!hooks) file.set(commonJSHooksKey, hooks = []); + hooks.push(hook); +} +function findMap(arr, cb) { + if (arr) { + for (const el of arr) { + const res = cb(el); + if (res != null) return res; + } + } +} +function makeInvokers(file) { + const hooks = file.get(commonJSHooksKey); + return { + getWrapperPayload(...args) { + return findMap(hooks, hook => hook.getWrapperPayload == null ? void 0 : hook.getWrapperPayload(...args)); + }, + wrapReference(...args) { + return findMap(hooks, hook => hook.wrapReference == null ? void 0 : hook.wrapReference(...args)); + }, + buildRequireWrapper(...args) { + return findMap(hooks, hook => hook.buildRequireWrapper == null ? void 0 : hook.buildRequireWrapper(...args)); + } + }; +} + +//# sourceMappingURL=hooks.js.map diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/hooks.js.map b/node_modules/@babel/plugin-transform-modules-commonjs/lib/hooks.js.map new file mode 100644 index 00000000..8cf1ab6c --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/hooks.js.map @@ -0,0 +1 @@ +{"version":3,"names":["commonJSHooksKey","defineCommonJSHook","file","hook","hooks","get","set","push","findMap","arr","cb","el","res","makeInvokers","getWrapperPayload","args","wrapReference","buildRequireWrapper"],"sources":["../src/hooks.ts"],"sourcesContent":["import type { types as t, File } from \"@babel/core\";\nimport type { isSideEffectImport } from \"@babel/helper-module-transforms\";\n\nconst commonJSHooksKey =\n \"@babel/plugin-transform-modules-commonjs/customWrapperPlugin\";\n\ntype SourceMetadata = Parameters<typeof isSideEffectImport>[0];\n\n// A hook exposes a set of function that can customize how `require()` calls and\n// references to the imported bindings are handled. These functions can either\n// return a result, or return `null` to delegate to the next hook.\nexport interface CommonJSHook {\n name: string;\n version: string;\n wrapReference?(ref: t.Expression, payload: unknown): t.CallExpression | null;\n // Optionally wrap a `require` call. If this function returns `false`, the\n // `require` call is removed from the generated code.\n buildRequireWrapper?(\n name: string,\n init: t.Expression,\n payload: unknown,\n referenced: boolean,\n ): t.Statement | false | null;\n getWrapperPayload?(\n source: string,\n metadata: SourceMetadata,\n importNodes: t.Node[],\n ): string | null;\n}\n\nexport function defineCommonJSHook(file: File, hook: CommonJSHook) {\n let hooks = file.get(commonJSHooksKey);\n if (!hooks) file.set(commonJSHooksKey, (hooks = []));\n hooks.push(hook);\n}\n\nfunction findMap<T, U>(arr: T[] | null, cb: (el: T) => U): U | null {\n if (arr) {\n for (const el of arr) {\n const res = cb(el);\n if (res != null) return res;\n }\n }\n}\n\nexport function makeInvokers(\n file: File,\n): Pick<\n CommonJSHook,\n \"wrapReference\" | \"getWrapperPayload\" | \"buildRequireWrapper\"\n> {\n const hooks: CommonJSHook[] | null = file.get(commonJSHooksKey);\n\n return {\n getWrapperPayload(...args) {\n return findMap(hooks, hook => hook.getWrapperPayload?.(...args));\n },\n wrapReference(...args) {\n return findMap(hooks, hook => hook.wrapReference?.(...args));\n },\n buildRequireWrapper(...args) {\n return findMap(hooks, hook => hook.buildRequireWrapper?.(...args));\n },\n };\n}\n"],"mappings":";;;;;;;AAGA,MAAMA,gBAAgB,GACpB,8DAA8D;AA0BzD,SAASC,kBAAkBA,CAACC,IAAU,EAAEC,IAAkB,EAAE;EACjE,IAAIC,KAAK,GAAGF,IAAI,CAACG,GAAG,CAACL,gBAAgB,CAAC;EACtC,IAAI,CAACI,KAAK,EAAEF,IAAI,CAACI,GAAG,CAACN,gBAAgB,EAAGI,KAAK,GAAG,EAAG,CAAC;EACpDA,KAAK,CAACG,IAAI,CAACJ,IAAI,CAAC;AAClB;AAEA,SAASK,OAAOA,CAAOC,GAAe,EAAEC,EAAgB,EAAY;EAClE,IAAID,GAAG,EAAE;IACP,KAAK,MAAME,EAAE,IAAIF,GAAG,EAAE;MACpB,MAAMG,GAAG,GAAGF,EAAE,CAACC,EAAE,CAAC;MAClB,IAAIC,GAAG,IAAI,IAAI,EAAE,OAAOA,GAAG;IAC7B;EACF;AACF;AAEO,SAASC,YAAYA,CAC1BX,IAAU,EAIV;EACA,MAAME,KAA4B,GAAGF,IAAI,CAACG,GAAG,CAACL,gBAAgB,CAAC;EAE/D,OAAO;IACLc,iBAAiBA,CAAC,GAAGC,IAAI,EAAE;MACzB,OAAOP,OAAO,CAACJ,KAAK,EAAED,IAAI,IAAIA,IAAI,CAACW,iBAAiB,oBAAtBX,IAAI,CAACW,iBAAiB,CAAG,GAAGC,IAAI,CAAC,CAAC;IAClE,CAAC;IACDC,aAAaA,CAAC,GAAGD,IAAI,EAAE;MACrB,OAAOP,OAAO,CAACJ,KAAK,EAAED,IAAI,IAAIA,IAAI,CAACa,aAAa,oBAAlBb,IAAI,CAACa,aAAa,CAAG,GAAGD,IAAI,CAAC,CAAC;IAC9D,CAAC;IACDE,mBAAmBA,CAAC,GAAGF,IAAI,EAAE;MAC3B,OAAOP,OAAO,CAACJ,KAAK,EAAED,IAAI,IAAIA,IAAI,CAACc,mBAAmB,oBAAxBd,IAAI,CAACc,mBAAmB,CAAG,GAAGF,IAAI,CAAC,CAAC;IACpE;EACF,CAAC;AACH"}
\ No newline at end of file diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js b/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js new file mode 100644 index 00000000..fe3cf756 --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js @@ -0,0 +1,198 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +Object.defineProperty(exports, "defineCommonJSHook", { + enumerable: true, + get: function () { + return _hooks.defineCommonJSHook; + } +}); +var _helperPluginUtils = require("@babel/helper-plugin-utils"); +var _helperModuleTransforms = require("@babel/helper-module-transforms"); +var _helperSimpleAccess = require("@babel/helper-simple-access"); +var _core = require("@babel/core"); +var _dynamicImport = require("./dynamic-import.js"); +var _lazy = require("./lazy.js"); +var _hooks = require("./hooks.js"); +var _default = (0, _helperPluginUtils.declare)((api, options) => { + var _api$assumption, _api$assumption2, _api$assumption3; + api.assertVersion(7); + const { + strictNamespace = false, + mjsStrictNamespace = strictNamespace, + allowTopLevelThis, + strict, + strictMode, + noInterop, + importInterop, + lazy = false, + allowCommonJSExports = true, + loose = false + } = options; + const constantReexports = (_api$assumption = api.assumption("constantReexports")) != null ? _api$assumption : loose; + const enumerableModuleMeta = (_api$assumption2 = api.assumption("enumerableModuleMeta")) != null ? _api$assumption2 : loose; + const noIncompleteNsImportDetection = (_api$assumption3 = api.assumption("noIncompleteNsImportDetection")) != null ? _api$assumption3 : false; + if (typeof lazy !== "boolean" && typeof lazy !== "function" && (!Array.isArray(lazy) || !lazy.every(item => typeof item === "string"))) { + throw new Error(`.lazy must be a boolean, array of strings, or a function`); + } + if (typeof strictNamespace !== "boolean") { + throw new Error(`.strictNamespace must be a boolean, or undefined`); + } + if (typeof mjsStrictNamespace !== "boolean") { + throw new Error(`.mjsStrictNamespace must be a boolean, or undefined`); + } + const getAssertion = localName => _core.template.expression.ast` + (function(){ + throw new Error( + "The CommonJS '" + "${localName}" + "' variable is not available in ES6 modules." + + "Consider setting setting sourceType:script or sourceType:unambiguous in your " + + "Babel config for this file."); + })() + `; + const moduleExportsVisitor = { + ReferencedIdentifier(path) { + const localName = path.node.name; + if (localName !== "module" && localName !== "exports") return; + const localBinding = path.scope.getBinding(localName); + const rootBinding = this.scope.getBinding(localName); + if (rootBinding !== localBinding || path.parentPath.isObjectProperty({ + value: path.node + }) && path.parentPath.parentPath.isObjectPattern() || path.parentPath.isAssignmentExpression({ + left: path.node + }) || path.isAssignmentExpression({ + left: path.node + })) { + return; + } + path.replaceWith(getAssertion(localName)); + }, + UpdateExpression(path) { + const arg = path.get("argument"); + if (!arg.isIdentifier()) return; + const localName = arg.node.name; + if (localName !== "module" && localName !== "exports") return; + const localBinding = path.scope.getBinding(localName); + const rootBinding = this.scope.getBinding(localName); + if (rootBinding !== localBinding) return; + path.replaceWith(_core.types.assignmentExpression(path.node.operator[0] + "=", arg.node, getAssertion(localName))); + }, + AssignmentExpression(path) { + const left = path.get("left"); + if (left.isIdentifier()) { + const localName = left.node.name; + if (localName !== "module" && localName !== "exports") return; + const localBinding = path.scope.getBinding(localName); + const rootBinding = this.scope.getBinding(localName); + if (rootBinding !== localBinding) return; + const right = path.get("right"); + right.replaceWith(_core.types.sequenceExpression([right.node, getAssertion(localName)])); + } else if (left.isPattern()) { + const ids = left.getOuterBindingIdentifiers(); + const localName = Object.keys(ids).filter(localName => { + if (localName !== "module" && localName !== "exports") return false; + return this.scope.getBinding(localName) === path.scope.getBinding(localName); + })[0]; + if (localName) { + const right = path.get("right"); + right.replaceWith(_core.types.sequenceExpression([right.node, getAssertion(localName)])); + } + } + } + }; + return { + name: "transform-modules-commonjs", + pre() { + this.file.set("@babel/plugin-transform-modules-*", "commonjs"); + if (lazy) (0, _hooks.defineCommonJSHook)(this.file, (0, _lazy.lazyImportsHook)(lazy)); + }, + visitor: { + ["CallExpression" + (api.types.importExpression ? "|ImportExpression" : "")](path) { + if (!this.file.has("@babel/plugin-proposal-dynamic-import")) return; + if (path.isCallExpression() && !_core.types.isImport(path.node.callee)) return; + let { + scope + } = path; + do { + scope.rename("require"); + } while (scope = scope.parent); + (0, _dynamicImport.transformDynamicImport)(path, noInterop, this.file); + }, + Program: { + exit(path, state) { + if (!(0, _helperModuleTransforms.isModule)(path)) return; + path.scope.rename("exports"); + path.scope.rename("module"); + path.scope.rename("require"); + path.scope.rename("__filename"); + path.scope.rename("__dirname"); + if (!allowCommonJSExports) { + { + (0, _helperSimpleAccess.default)(path, new Set(["module", "exports"]), false); + } + path.traverse(moduleExportsVisitor, { + scope: path.scope + }); + } + let moduleName = (0, _helperModuleTransforms.getModuleName)(this.file.opts, options); + if (moduleName) moduleName = _core.types.stringLiteral(moduleName); + const hooks = (0, _hooks.makeInvokers)(this.file); + const { + meta, + headers + } = (0, _helperModuleTransforms.rewriteModuleStatementsAndPrepareHeader)(path, { + exportName: "exports", + constantReexports, + enumerableModuleMeta, + strict, + strictMode, + allowTopLevelThis, + noInterop, + importInterop, + wrapReference: hooks.wrapReference, + getWrapperPayload: hooks.getWrapperPayload, + esNamespaceOnly: typeof state.filename === "string" && /\.mjs$/.test(state.filename) ? mjsStrictNamespace : strictNamespace, + noIncompleteNsImportDetection, + filename: this.file.opts.filename + }); + for (const [source, metadata] of meta.source) { + const loadExpr = _core.types.callExpression(_core.types.identifier("require"), [_core.types.stringLiteral(source)]); + let header; + if ((0, _helperModuleTransforms.isSideEffectImport)(metadata)) { + if (lazy && metadata.wrap === "function") { + throw new Error("Assertion failure"); + } + header = _core.types.expressionStatement(loadExpr); + } else { + var _header; + const init = (0, _helperModuleTransforms.wrapInterop)(path, loadExpr, metadata.interop) || loadExpr; + if (metadata.wrap) { + const res = hooks.buildRequireWrapper(metadata.name, init, metadata.wrap, metadata.referenced); + if (res === false) continue;else header = res; + } + (_header = header) != null ? _header : header = _core.template.statement.ast` + var ${metadata.name} = ${init}; + `; + } + header.loc = metadata.loc; + headers.push(header); + headers.push(...(0, _helperModuleTransforms.buildNamespaceInitStatements)(meta, metadata, constantReexports, hooks.wrapReference)); + } + (0, _helperModuleTransforms.ensureStatementsHoisted)(headers); + path.unshiftContainer("body", headers); + path.get("body").forEach(path => { + if (headers.indexOf(path.node) === -1) return; + if (path.isVariableDeclaration()) { + path.scope.registerDeclaration(path); + } + }); + } + } + } + }; +}); +exports.default = _default; + +//# sourceMappingURL=index.js.map diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js.map b/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js.map new file mode 100644 index 00000000..dd6e5591 --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_helperPluginUtils","require","_helperModuleTransforms","_helperSimpleAccess","_core","_dynamicImport","_lazy","_hooks","_default","declare","api","options","_api$assumption","_api$assumption2","_api$assumption3","assertVersion","strictNamespace","mjsStrictNamespace","allowTopLevelThis","strict","strictMode","noInterop","importInterop","lazy","allowCommonJSExports","loose","constantReexports","assumption","enumerableModuleMeta","noIncompleteNsImportDetection","Array","isArray","every","item","Error","getAssertion","localName","template","expression","ast","moduleExportsVisitor","ReferencedIdentifier","path","node","name","localBinding","scope","getBinding","rootBinding","parentPath","isObjectProperty","value","isObjectPattern","isAssignmentExpression","left","replaceWith","UpdateExpression","arg","get","isIdentifier","t","assignmentExpression","operator","AssignmentExpression","right","sequenceExpression","isPattern","ids","getOuterBindingIdentifiers","Object","keys","filter","pre","file","set","defineCommonJSHook","lazyImportsHook","visitor","types","importExpression","has","isCallExpression","isImport","callee","rename","parent","transformDynamicImport","Program","exit","state","isModule","simplifyAccess","Set","traverse","moduleName","getModuleName","opts","stringLiteral","hooks","makeInvokers","meta","headers","rewriteModuleStatementsAndPrepareHeader","exportName","wrapReference","getWrapperPayload","esNamespaceOnly","filename","test","source","metadata","loadExpr","callExpression","identifier","header","isSideEffectImport","wrap","expressionStatement","_header","init","wrapInterop","interop","res","buildRequireWrapper","referenced","statement","loc","push","buildNamespaceInitStatements","ensureStatementsHoisted","unshiftContainer","forEach","indexOf","isVariableDeclaration","registerDeclaration","exports","default"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport {\n isModule,\n rewriteModuleStatementsAndPrepareHeader,\n type RewriteModuleStatementsAndPrepareHeaderOptions,\n isSideEffectImport,\n buildNamespaceInitStatements,\n ensureStatementsHoisted,\n wrapInterop,\n getModuleName,\n} from \"@babel/helper-module-transforms\";\nimport simplifyAccess from \"@babel/helper-simple-access\";\nimport { template, types as t, type PluginPass } from \"@babel/core\";\nimport type { PluginOptions } from \"@babel/helper-module-transforms\";\nimport type { Visitor, Scope, NodePath } from \"@babel/traverse\";\n\nimport { transformDynamicImport } from \"./dynamic-import.ts\";\nimport { lazyImportsHook } from \"./lazy.ts\";\n\nimport { defineCommonJSHook, makeInvokers } from \"./hooks.ts\";\nexport { defineCommonJSHook };\n\nexport interface Options extends PluginOptions {\n allowCommonJSExports?: boolean;\n allowTopLevelThis?: boolean;\n importInterop?: RewriteModuleStatementsAndPrepareHeaderOptions[\"importInterop\"];\n lazy?: RewriteModuleStatementsAndPrepareHeaderOptions[\"lazy\"];\n loose?: boolean;\n mjsStrictNamespace?: boolean;\n noInterop?: boolean;\n strict?: boolean;\n strictMode?: boolean;\n strictNamespace?: boolean;\n}\n\nexport default declare((api, options: Options) => {\n api.assertVersion(7);\n\n const {\n // 'true' for imports to strictly have .default, instead of having\n // destructuring-like behavior for their properties. This matches the behavior\n // of the initial Node.js (v12) behavior when importing a CommonJS without\n // the __esMoule property.\n // .strictNamespace is for non-mjs files, mjsStrictNamespace if for mjs files.\n strictNamespace = false,\n mjsStrictNamespace = strictNamespace,\n\n allowTopLevelThis,\n strict,\n strictMode,\n noInterop,\n importInterop,\n lazy = false,\n // Defaulting to 'true' for now. May change before 7.x major.\n allowCommonJSExports = true,\n loose = false,\n } = options;\n\n const constantReexports = api.assumption(\"constantReexports\") ?? loose;\n const enumerableModuleMeta = api.assumption(\"enumerableModuleMeta\") ?? loose;\n const noIncompleteNsImportDetection =\n api.assumption(\"noIncompleteNsImportDetection\") ?? false;\n\n if (\n typeof lazy !== \"boolean\" &&\n typeof lazy !== \"function\" &&\n (!Array.isArray(lazy) || !lazy.every(item => typeof item === \"string\"))\n ) {\n throw new Error(`.lazy must be a boolean, array of strings, or a function`);\n }\n\n if (typeof strictNamespace !== \"boolean\") {\n throw new Error(`.strictNamespace must be a boolean, or undefined`);\n }\n if (typeof mjsStrictNamespace !== \"boolean\") {\n throw new Error(`.mjsStrictNamespace must be a boolean, or undefined`);\n }\n\n const getAssertion = (localName: string) => template.expression.ast`\n (function(){\n throw new Error(\n \"The CommonJS '\" + \"${localName}\" + \"' variable is not available in ES6 modules.\" +\n \"Consider setting setting sourceType:script or sourceType:unambiguous in your \" +\n \"Babel config for this file.\");\n })()\n `;\n\n const moduleExportsVisitor: Visitor<{ scope: Scope }> = {\n ReferencedIdentifier(path) {\n const localName = path.node.name;\n if (localName !== \"module\" && localName !== \"exports\") return;\n\n const localBinding = path.scope.getBinding(localName);\n const rootBinding = this.scope.getBinding(localName);\n\n if (\n // redeclared in this scope\n rootBinding !== localBinding ||\n (path.parentPath.isObjectProperty({ value: path.node }) &&\n path.parentPath.parentPath.isObjectPattern()) ||\n path.parentPath.isAssignmentExpression({ left: path.node }) ||\n path.isAssignmentExpression({ left: path.node })\n ) {\n return;\n }\n\n path.replaceWith(getAssertion(localName));\n },\n\n UpdateExpression(path) {\n const arg = path.get(\"argument\");\n if (!arg.isIdentifier()) return;\n const localName = arg.node.name;\n if (localName !== \"module\" && localName !== \"exports\") return;\n\n const localBinding = path.scope.getBinding(localName);\n const rootBinding = this.scope.getBinding(localName);\n\n // redeclared in this scope\n if (rootBinding !== localBinding) return;\n\n path.replaceWith(\n t.assignmentExpression(\n path.node.operator[0] + \"=\",\n arg.node,\n getAssertion(localName),\n ),\n );\n },\n\n AssignmentExpression(path) {\n const left = path.get(\"left\");\n if (left.isIdentifier()) {\n const localName = left.node.name;\n if (localName !== \"module\" && localName !== \"exports\") return;\n\n const localBinding = path.scope.getBinding(localName);\n const rootBinding = this.scope.getBinding(localName);\n\n // redeclared in this scope\n if (rootBinding !== localBinding) return;\n\n const right = path.get(\"right\");\n right.replaceWith(\n t.sequenceExpression([right.node, getAssertion(localName)]),\n );\n } else if (left.isPattern()) {\n const ids = left.getOuterBindingIdentifiers();\n const localName = Object.keys(ids).filter(localName => {\n if (localName !== \"module\" && localName !== \"exports\") return false;\n\n return (\n this.scope.getBinding(localName) ===\n path.scope.getBinding(localName)\n );\n })[0];\n\n if (localName) {\n const right = path.get(\"right\");\n right.replaceWith(\n t.sequenceExpression([right.node, getAssertion(localName)]),\n );\n }\n }\n },\n };\n\n return {\n name: \"transform-modules-commonjs\",\n\n pre() {\n this.file.set(\"@babel/plugin-transform-modules-*\", \"commonjs\");\n\n if (lazy) defineCommonJSHook(this.file, lazyImportsHook(lazy));\n },\n\n visitor: {\n [\"CallExpression\" +\n (api.types.importExpression ? \"|ImportExpression\" : \"\")](\n this: PluginPass,\n path: NodePath<t.CallExpression | t.ImportExpression>,\n ) {\n if (!this.file.has(\"@babel/plugin-proposal-dynamic-import\")) return;\n if (path.isCallExpression() && !t.isImport(path.node.callee)) return;\n\n let { scope } = path;\n do {\n scope.rename(\"require\");\n } while ((scope = scope.parent));\n\n transformDynamicImport(path, noInterop, this.file);\n },\n\n Program: {\n exit(path, state) {\n if (!isModule(path)) return;\n\n // Rename the bindings auto-injected into the scope so there is no\n // risk of conflict between the bindings.\n path.scope.rename(\"exports\");\n path.scope.rename(\"module\");\n path.scope.rename(\"require\");\n path.scope.rename(\"__filename\");\n path.scope.rename(\"__dirname\");\n\n // Rewrite references to 'module' and 'exports' to throw exceptions.\n // These objects are specific to CommonJS and are not available in\n // real ES6 implementations.\n if (!allowCommonJSExports) {\n if (process.env.BABEL_8_BREAKING) {\n simplifyAccess(path, new Set([\"module\", \"exports\"]));\n } else {\n // @ts-ignore(Babel 7 vs Babel 8) The third param has been removed in Babel 8.\n simplifyAccess(path, new Set([\"module\", \"exports\"]), false);\n }\n path.traverse(moduleExportsVisitor, {\n scope: path.scope,\n });\n }\n\n let moduleName = getModuleName(this.file.opts, options);\n // @ts-expect-error todo(flow->ts): do not reuse variables\n if (moduleName) moduleName = t.stringLiteral(moduleName);\n\n const hooks = makeInvokers(this.file);\n\n const { meta, headers } = rewriteModuleStatementsAndPrepareHeader(\n path,\n {\n exportName: \"exports\",\n constantReexports,\n enumerableModuleMeta,\n strict,\n strictMode,\n allowTopLevelThis,\n noInterop,\n importInterop,\n wrapReference: hooks.wrapReference,\n getWrapperPayload: hooks.getWrapperPayload,\n esNamespaceOnly:\n typeof state.filename === \"string\" &&\n /\\.mjs$/.test(state.filename)\n ? mjsStrictNamespace\n : strictNamespace,\n noIncompleteNsImportDetection,\n filename: this.file.opts.filename,\n },\n );\n\n for (const [source, metadata] of meta.source) {\n const loadExpr = t.callExpression(t.identifier(\"require\"), [\n t.stringLiteral(source),\n ]);\n\n let header: t.Statement;\n if (isSideEffectImport(metadata)) {\n if (lazy && metadata.wrap === \"function\") {\n throw new Error(\"Assertion failure\");\n }\n\n header = t.expressionStatement(loadExpr);\n } else {\n const init =\n wrapInterop(path, loadExpr, metadata.interop) || loadExpr;\n\n if (metadata.wrap) {\n const res = hooks.buildRequireWrapper(\n metadata.name,\n init,\n metadata.wrap,\n metadata.referenced,\n );\n if (res === false) continue;\n else header = res;\n }\n header ??= template.statement.ast`\n var ${metadata.name} = ${init};\n `;\n }\n header.loc = metadata.loc;\n\n headers.push(header);\n headers.push(\n ...buildNamespaceInitStatements(\n meta,\n metadata,\n constantReexports,\n hooks.wrapReference,\n ),\n );\n }\n\n ensureStatementsHoisted(headers);\n path.unshiftContainer(\"body\", headers);\n path.get(\"body\").forEach(path => {\n if (headers.indexOf(path.node) === -1) return;\n if (path.isVariableDeclaration()) {\n path.scope.registerDeclaration(path);\n }\n });\n },\n },\n },\n };\n});\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AAUA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAIA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAA8D,IAAAO,QAAA,GAgB/C,IAAAC,0BAAO,EAAC,CAACC,GAAG,EAAEC,OAAgB,KAAK;EAAA,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AAS,CAACtF,GAAI;AAChD,sBAAsBuE,QAAQ,CAAClE,IAAK,MAAK2E,IAAK;AAC9C,eAAe;YACH;YACAL,MAAM,CAACY,GAAG,GAAGhB,QAAQ,CAACgB,GAAG;YAEzBzB,OAAO,CAAC0B,IAAI,CAACb,MAAM,CAAC;YACpBb,OAAO,CAAC0B,IAAI,CACV,GAAG,IAAAC,oDAA4B,EAC7B5B,IAAI,EACJU,QAAQ,EACRpF,iBAAiB,EACjBwE,KAAK,CAACM,aACR,CACF,CAAC;UACH;UAEA,IAAAyB,+CAAuB,EAAC5B,OAAO,CAAC;UAChC3D,IAAI,CAACwF,gBAAgB,CAAC,MAAM,EAAE7B,OAAO,CAAC;UACtC3D,IAAI,CAACgB,GAAG,CAAC,MAAM,CAAC,CAACyE,OAAO,CAACzF,IAAI,IAAI;YAC/B,IAAI2D,OAAO,CAAC+B,OAAO,CAAC1F,IAAI,CAACC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;YACvC,IAAID,IAAI,CAAC2F,qBAAqB,CAAC,CAAC,EAAE;cAChC3F,IAAI,CAACI,KAAK,CAACwF,mBAAmB,CAAC5F,IAAI,CAAC;YACtC;UACF,CAAC,CAAC;QACJ;MACF;IACF;EACF,CAAC;AACH,CAAC,CAAC;AAAA6F,OAAA,CAAAC,OAAA,GAAAhI,QAAA"}
\ No newline at end of file diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/lazy.js b/node_modules/@babel/plugin-transform-modules-commonjs/lib/lazy.js new file mode 100644 index 00000000..fb62ea2b --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/lazy.js @@ -0,0 +1,44 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.lazyImportsHook = void 0; +var _core = require("@babel/core"); +var _helperModuleTransforms = require("@babel/helper-module-transforms"); +const lazyImportsHook = lazy => ({ + name: `${"@babel/plugin-transform-modules-commonjs"}/lazy`, + version: "7.23.0", + getWrapperPayload(source, metadata) { + if ((0, _helperModuleTransforms.isSideEffectImport)(metadata) || metadata.reexportAll) { + return null; + } + if (lazy === true) { + return /\./.test(source) ? null : "lazy/function"; + } + if (Array.isArray(lazy)) { + return lazy.indexOf(source) === -1 ? null : "lazy/function"; + } + if (typeof lazy === "function") { + return lazy(source) ? "lazy/function" : null; + } + }, + buildRequireWrapper(name, init, payload, referenced) { + if (payload === "lazy/function") { + if (!referenced) return false; + return _core.template.statement.ast` + function ${name}() { + const data = ${init}; + ${name} = function(){ return data; }; + return data; + } + `; + } + }, + wrapReference(ref, payload) { + if (payload === "lazy/function") return _core.types.callExpression(ref, []); + } +}); +exports.lazyImportsHook = lazyImportsHook; + +//# sourceMappingURL=lazy.js.map diff --git a/node_modules/@babel/plugin-transform-modules-commonjs/lib/lazy.js.map b/node_modules/@babel/plugin-transform-modules-commonjs/lib/lazy.js.map new file mode 100644 index 00000000..b37235b6 --- /dev/null +++ b/node_modules/@babel/plugin-transform-modules-commonjs/lib/lazy.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_core","require","_helperModuleTransforms","lazyImportsHook","lazy","name","version","getWrapperPayload","source","metadata","isSideEffectImport","reexportAll","test","Array","isArray","indexOf","buildRequireWrapper","init","payload","referenced","template","statement","ast","wrapReference","ref","t","callExpression","exports"],"sources":["../src/lazy.ts"],"sourcesContent":["import { template, types as t } from \"@babel/core\";\nimport { isSideEffectImport } from \"@babel/helper-module-transforms\";\nimport type { CommonJSHook } from \"./hooks.ts\";\n\ntype Lazy = boolean | string[] | ((source: string) => boolean);\n\nexport const lazyImportsHook = (lazy: Lazy): CommonJSHook => ({\n name: `${PACKAGE_JSON.name}/lazy`,\n version: PACKAGE_JSON.version,\n getWrapperPayload(source, metadata) {\n if (isSideEffectImport(metadata) || metadata.reexportAll) {\n return null;\n }\n if (lazy === true) {\n // 'true' means that local relative files are eagerly loaded and\n // dependency modules are loaded lazily.\n return /\\./.test(source) ? null : \"lazy/function\";\n }\n if (Array.isArray(lazy)) {\n return lazy.indexOf(source) === -1 ? null : \"lazy/function\";\n }\n if (typeof lazy === \"function\") {\n return lazy(source) ? \"lazy/function\" : null;\n }\n },\n buildRequireWrapper(name, init, payload, referenced) {\n if (payload === \"lazy/function\") {\n if (!referenced) return false;\n return template.statement.ast`\n function ${name}() {\n const data = ${init};\n ${name} = function(){ return data; };\n return data;\n }\n `;\n }\n },\n wrapReference(ref, payload) {\n if (payload === \"lazy/function\") return t.callExpression(ref, []);\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AAKO,MAAME,eAAe,GAAIC,IAAU,KAAoB;EAC5DC,IAAI,EAAG,6CAAoB,OAAM;EACjCC,OAAO,UAAsB;EAC7BC,iBAAiBA,CAACC,MAAM,EAAEC,QAAQ,EAAE;IAClC,IAAI,IAAAC,0CAAkB,EAACD,QAAQ,CAAC,IAAIA,QAAQ,CAACE,WAAW,EAAE;MACxD,OAAO,IAAI;IACb;IACA,IAAIP,IAAI,KAAK,IAAI,EAAE;MAGjB,OAAO,IAAI,CAACQ,IAAI,CAACJ,MAAM,CAAC,GAAG,IAAI,GAAG,eAAe;IACnD;IACA,IAAIK,KAAK,CAACC,OAAO,CAACV,IAAI,CAAC,EAAE;MACvB,OAAOA,IAAI,CAACW,OAAO,CAACP,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,GAAG,eAAe;IAC7D;IACA,IAAI,OAAOJ,IAAI,KAAK,UAAU,EAAE;MAC9B,OAAOA,IAAI,CAACI,MAAM,CAAC,GAAG,eAAe,GAAG,IAAI;IAC9C;EACF,CAAC;EACDQ,mBAAmBA,CAACX,IAAI,EAAEY,IAAI,EAAEC,OAAO,EAAEC,UAAU,EAAE;IACnD,IAAID,OAAO,KAAK,eAAe,EAAE;MAC/B,IAAI,CAACC,UAAU,EAAE,OAAO,KAAK;MAC7B,OAAOC,cAAQ,CAACC,SAAS,CAACC,GAAI;AACpC,mBAAmBjB,IAAK;A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