Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-modules-commonjs

Package Overview
Dependencies
Maintainers
4
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-modules-commonjs - npm Package Compare versions

Comparing version 7.22.15 to 7.23.0

lib/hooks.js

45

lib/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc