Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-modules-commonjs

Package Overview
Dependencies
54
Maintainers
4
Versions
93
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.21.4-esm to 7.21.4-esm.1

18

lib/dynamic-import.js

@@ -1,16 +0,10 @@

"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) {
import { types as t, template } from "@babel/core";
import { buildDynamicImport } from "@babel/helper-module-transforms";
const requireNoInterop = source => template.expression.ast`require(${source})`;
const requireInterop = (source, file) => t.callExpression(file.addHelper("interopRequireWildcard"), [requireNoInterop(source)]);
export function transformDynamicImport(path, noInterop, file) {
const buildRequire = noInterop ? requireNoInterop : requireInterop;
path.replaceWith((0, _helperModuleTransforms.buildDynamicImport)(path.node, true, false, specifier => buildRequire(specifier, file)));
path.replaceWith(buildDynamicImport(path.node, true, false, specifier => buildRequire(specifier, file)));
}
//# sourceMappingURL=dynamic-import.js.map

@@ -1,13 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
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");
var _default = (0, _helperPluginUtils.declare)((api, options) => {
import { declare } from "@babel/helper-plugin-utils";
import { isModule, rewriteModuleStatementsAndPrepareHeader, isSideEffectImport, buildNamespaceInitStatements, ensureStatementsHoisted, wrapInterop, getModuleName } from "@babel/helper-module-transforms";
import simplifyAccess from "@babel/helper-simple-access";
import { template, types as t } from "@babel/core";
import { transformDynamicImport } from "./dynamic-import.js";
export default declare((api, options) => {
var _api$assumption, _api$assumption2, _api$assumption3;

@@ -39,3 +33,3 @@ api.assertVersion(7);

}
const getAssertion = localName => _core.template.expression.ast`
const getAssertion = localName => template.expression.ast`
(function(){

@@ -73,3 +67,3 @@ throw new Error(

if (rootBinding !== localBinding) return;
path.replaceWith(_core.types.assignmentExpression(path.node.operator[0] + "=", arg.node, getAssertion(localName)));
path.replaceWith(t.assignmentExpression(path.node.operator[0] + "=", arg.node, getAssertion(localName)));
},

@@ -85,3 +79,3 @@ AssignmentExpression(path) {

const right = path.get("right");
right.replaceWith(_core.types.sequenceExpression([right.node, getAssertion(localName)]));
right.replaceWith(t.sequenceExpression([right.node, getAssertion(localName)]));
} else if (left.isPattern()) {

@@ -95,3 +89,3 @@ const ids = left.getOuterBindingIdentifiers();

const right = path.get("right");
right.replaceWith(_core.types.sequenceExpression([right.node, getAssertion(localName)]));
right.replaceWith(t.sequenceExpression([right.node, getAssertion(localName)]));
}

@@ -109,3 +103,3 @@ }

if (!this.file.has("@babel/plugin-proposal-dynamic-import")) return;
if (!_core.types.isImport(path.node.callee)) return;
if (!t.isImport(path.node.callee)) return;
let {

@@ -117,7 +111,7 @@ scope

} while (scope = scope.parent);
(0, _dynamicImport.transformDynamicImport)(path, noInterop, this.file);
transformDynamicImport(path, noInterop, this.file);
},
Program: {
exit(path, state) {
if (!(0, _helperModuleTransforms.isModule)(path)) return;
if (!isModule(path)) return;
path.scope.rename("exports");

@@ -129,3 +123,3 @@ path.scope.rename("module");

if (!allowCommonJSExports) {
(0, _helperSimpleAccess.default)(path, new Set(["module", "exports"]), false);
simplifyAccess(path, new Set(["module", "exports"]), false);
path.traverse(moduleExportsVisitor, {

@@ -135,8 +129,8 @@ scope: path.scope

}
let moduleName = (0, _helperModuleTransforms.getModuleName)(this.file.opts, options);
if (moduleName) moduleName = _core.types.stringLiteral(moduleName);
let moduleName = getModuleName(this.file.opts, options);
if (moduleName) moduleName = t.stringLiteral(moduleName);
const {
meta,
headers
} = (0, _helperModuleTransforms.rewriteModuleStatementsAndPrepareHeader)(path, {
} = rewriteModuleStatementsAndPrepareHeader(path, {
exportName: "exports",

@@ -156,7 +150,7 @@ constantReexports,

for (const [source, metadata] of meta.source) {
const loadExpr = _core.types.callExpression(_core.types.identifier("require"), [_core.types.stringLiteral(source)]);
const loadExpr = t.callExpression(t.identifier("require"), [t.stringLiteral(source)]);
let header;
if ((0, _helperModuleTransforms.isSideEffectImport)(metadata)) {
if (isSideEffectImport(metadata)) {
if (metadata.lazy) throw new Error("Assertion failure");
header = _core.types.expressionStatement(loadExpr);
header = t.expressionStatement(loadExpr);
} else {

@@ -166,5 +160,5 @@ if (metadata.lazy && !metadata.referenced) {

}
const init = (0, _helperModuleTransforms.wrapInterop)(path, loadExpr, metadata.interop) || loadExpr;
const init = wrapInterop(path, loadExpr, metadata.interop) || loadExpr;
if (metadata.lazy) {
header = _core.template.statement.ast`
header = template.statement.ast`
function ${metadata.name}() {

@@ -177,3 +171,3 @@ const data = ${init};

} else {
header = _core.template.statement.ast`
header = template.statement.ast`
var ${metadata.name} = ${init};

@@ -185,5 +179,5 @@ `;

headers.push(header);
headers.push(...(0, _helperModuleTransforms.buildNamespaceInitStatements)(meta, metadata, constantReexports));
headers.push(...buildNamespaceInitStatements(meta, metadata, constantReexports));
}
(0, _helperModuleTransforms.ensureStatementsHoisted)(headers);
ensureStatementsHoisted(headers);
path.unshiftContainer("body", headers);

@@ -201,4 +195,3 @@ path.get("body").forEach(path => {

});
exports.default = _default;
//# sourceMappingURL=index.js.map
{
"name": "@babel/plugin-transform-modules-commonjs",
"version": "7.21.4-esm",
"version": "7.21.4-esm.1",
"description": "This plugin transforms ES2015 modules to CommonJS",

@@ -16,5 +16,5 @@ "repository": {

"dependencies": {
"@babel/helper-module-transforms": "^7.21.4-esm",
"@babel/helper-plugin-utils": "^7.21.4-esm",
"@babel/helper-simple-access": "^7.21.4-esm"
"@babel/helper-module-transforms": "^7.21.4-esm.1",
"@babel/helper-plugin-utils": "^7.21.4-esm.1",
"@babel/helper-simple-access": "^7.21.4-esm.1"
},

@@ -25,8 +25,8 @@ "keywords": [

"peerDependencies": {
"@babel/core": "^7.0.0-0 || 7.21.4-esm"
"@babel/core": "^7.0.0-0 || 7.21.4-esm.1"
},
"devDependencies": {
"@babel/core": "^7.21.4-esm",
"@babel/helper-plugin-test-runner": "^7.21.4-esm",
"@babel/plugin-external-helpers": "^7.21.4-esm",
"@babel/core": "^7.21.4-esm.1",
"@babel/helper-plugin-test-runner": "^7.21.4-esm.1",
"@babel/plugin-external-helpers": "^7.21.4-esm.1",
"@babel/plugin-syntax-class-static-block": "^7.14.5",

@@ -40,3 +40,3 @@ "@babel/plugin-syntax-object-rest-spread": "^7.8.3"

"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
"type": "module"
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc