You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
20 KiB

2 months ago
{"version":3,"names":["_helperPluginUtils","require","_helperModuleTransforms","_helperSimpleAccess","_core","_dynamicImport","_lazy","_hooks","_default","exports","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","find","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","includes","isVariableDeclaration","registerDeclaration"],"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 } from \"@babel/core\";\nimport type { PluginPass, Visitor, Scope, NodePath } from \"@babel/core\";\nimport type { PluginOptions } from \"@babel/helper-module-transforms\";\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(REQUIRED_VERSION(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(\"enumerab