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.2 to 7.21.4-esm.3

18

lib/dynamic-import.js

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

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) {
"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(buildDynamicImport(path.node, true, false, specifier => buildRequire(specifier, file)));
path.replaceWith((0, _helperModuleTransforms.buildDynamicImport)(path.node, true, false, specifier => buildRequire(specifier, file)));
}
//# sourceMappingURL=dynamic-import.js.map

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

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) => {
"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) => {
var _api$assumption, _api$assumption2, _api$assumption3;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -28,5 +28,5 @@ "keywords": [

"devDependencies": {
"@babel/core": "7.21.4-esm.2",
"@babel/helper-plugin-test-runner": "7.21.4-esm.2",
"@babel/plugin-external-helpers": "7.21.4-esm.2",
"@babel/core": "7.21.4-esm.3",
"@babel/helper-plugin-test-runner": "7.21.4-esm.3",
"@babel/plugin-external-helpers": "7.21.4-esm.3",
"@babel/plugin-syntax-class-static-block": "^7.14.5",

@@ -33,0 +33,0 @@ "@babel/plugin-syntax-object-rest-spread": "^7.8.3"

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