@babel/plugin-transform-modules-commonjs
Advanced tools
Comparing version 7.22.15 to 7.23.0
@@ -7,2 +7,8 @@ "use strict"; | ||
exports.default = void 0; | ||
Object.defineProperty(exports, "defineCommonJSHook", { | ||
enumerable: true, | ||
get: function () { | ||
return _hooks.defineCommonJSHook; | ||
} | ||
}); | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
@@ -13,2 +19,4 @@ var _helperModuleTransforms = require("@babel/helper-module-transforms"); | ||
var _dynamicImport = require("./dynamic-import.js"); | ||
var _lazy = require("./lazy.js"); | ||
var _hooks = require("./hooks.js"); | ||
var _default = (0, _helperPluginUtils.declare)((api, options) => { | ||
@@ -103,7 +111,8 @@ var _api$assumption, _api$assumption2, _api$assumption3; | ||
this.file.set("@babel/plugin-transform-modules-*", "commonjs"); | ||
if (lazy) (0, _hooks.defineCommonJSHook)(this.file, (0, _lazy.lazyImportsHook)(lazy)); | ||
}, | ||
visitor: { | ||
CallExpression(path) { | ||
["CallExpression" + (api.types.importExpression ? "|ImportExpression" : "")](path) { | ||
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) return; | ||
if (!_core.types.isImport(path.node.callee)) return; | ||
if (path.isCallExpression() && !_core.types.isImport(path.node.callee)) return; | ||
let { | ||
@@ -135,2 +144,3 @@ scope | ||
if (moduleName) moduleName = _core.types.stringLiteral(moduleName); | ||
const hooks = (0, _hooks.makeInvokers)(this.file); | ||
const { | ||
@@ -148,3 +158,4 @@ meta, | ||
importInterop, | ||
lazy, | ||
wrapReference: hooks.wrapReference, | ||
getWrapperPayload: hooks.getWrapperPayload, | ||
esNamespaceOnly: typeof state.filename === "string" && /\.mjs$/.test(state.filename) ? mjsStrictNamespace : strictNamespace, | ||
@@ -158,26 +169,20 @@ noIncompleteNsImportDetection, | ||
if ((0, _helperModuleTransforms.isSideEffectImport)(metadata)) { | ||
if (metadata.lazy) throw new Error("Assertion failure"); | ||
if (lazy && metadata.wrap === "function") { | ||
throw new Error("Assertion failure"); | ||
} | ||
header = _core.types.expressionStatement(loadExpr); | ||
} else { | ||
if (metadata.lazy && !metadata.referenced) { | ||
continue; | ||
} | ||
var _header; | ||
const init = (0, _helperModuleTransforms.wrapInterop)(path, loadExpr, metadata.interop) || loadExpr; | ||
if (metadata.lazy) { | ||
header = _core.template.statement.ast` | ||
function ${metadata.name}() { | ||
const data = ${init}; | ||
${metadata.name} = function(){ return data; }; | ||
return data; | ||
} | ||
`; | ||
} else { | ||
header = _core.template.statement.ast` | ||
var ${metadata.name} = ${init}; | ||
`; | ||
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)); | ||
headers.push(...(0, _helperModuleTransforms.buildNamespaceInitStatements)(meta, metadata, constantReexports, hooks.wrapReference)); | ||
} | ||
@@ -184,0 +189,0 @@ (0, _helperModuleTransforms.ensureStatementsHoisted)(headers); |
{ | ||
"name": "@babel/plugin-transform-modules-commonjs", | ||
"version": "7.22.15", | ||
"version": "7.23.0", | ||
"description": "This plugin transforms ES2015 modules to CommonJS", | ||
@@ -16,3 +16,3 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-module-transforms": "^7.22.15", | ||
"@babel/helper-module-transforms": "^7.23.0", | ||
"@babel/helper-plugin-utils": "^7.22.5", | ||
@@ -28,3 +28,3 @@ "@babel/helper-simple-access": "^7.22.5" | ||
"devDependencies": { | ||
"@babel/core": "^7.22.15", | ||
"@babel/core": "^7.23.0", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
@@ -31,0 +31,0 @@ "@babel/plugin-external-helpers": "^7.22.5" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42369
11
287
+ Added@babel/code-frame@7.24.7(transitive)
+ Added@babel/compat-data@7.25.4(transitive)
+ Added@babel/core@7.25.2(transitive)
+ Added@babel/generator@7.25.6(transitive)
+ Added@babel/helper-compilation-targets@7.25.2(transitive)
+ Added@babel/helper-module-imports@7.24.7(transitive)
+ Added@babel/helper-module-transforms@7.25.2(transitive)
+ Added@babel/helper-plugin-utils@7.24.8(transitive)
+ Added@babel/helper-simple-access@7.24.7(transitive)
+ Added@babel/helper-string-parser@7.24.8(transitive)
+ Added@babel/helper-validator-identifier@7.24.7(transitive)
+ Added@babel/helper-validator-option@7.24.8(transitive)
+ Added@babel/helpers@7.25.6(transitive)
+ Added@babel/highlight@7.24.7(transitive)
+ Added@babel/parser@7.25.6(transitive)
+ Added@babel/template@7.25.0(transitive)
+ Added@babel/traverse@7.25.6(transitive)
+ Added@babel/types@7.25.6(transitive)
+ Addedcaniuse-lite@1.0.30001664(transitive)
+ Addedelectron-to-chromium@1.5.29(transitive)
+ Addedjsesc@2.5.2(transitive)
- Removed@babel/code-frame@7.25.7(transitive)
- Removed@babel/compat-data@7.25.7(transitive)
- Removed@babel/core@7.25.7(transitive)
- Removed@babel/generator@7.25.7(transitive)
- Removed@babel/helper-compilation-targets@7.25.7(transitive)
- Removed@babel/helper-module-imports@7.25.7(transitive)
- Removed@babel/helper-module-transforms@7.25.7(transitive)
- Removed@babel/helper-plugin-utils@7.25.7(transitive)
- Removed@babel/helper-simple-access@7.25.7(transitive)
- Removed@babel/helper-string-parser@7.25.7(transitive)
- Removed@babel/helper-validator-identifier@7.25.7(transitive)
- Removed@babel/helper-validator-option@7.25.7(transitive)
- Removed@babel/helpers@7.25.7(transitive)
- Removed@babel/highlight@7.25.7(transitive)
- Removed@babel/parser@7.25.7(transitive)
- Removed@babel/template@7.25.7(transitive)
- Removed@babel/traverse@7.25.7(transitive)
- Removed@babel/types@7.25.7(transitive)
- Removedcaniuse-lite@1.0.30001667(transitive)
- Removedelectron-to-chromium@1.5.32(transitive)
- Removedjsesc@3.0.2(transitive)