Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babel/plugin-transform-modules-commonjs

Package Overview
Dependencies
Maintainers
4
Versions
103
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.5 to 8.0.0-alpha.0

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,14 +0,14 @@

"use strict";
import { declare } from '@babel/helper-plugin-utils';
import { buildDynamicImport, isModule, getModuleName, rewriteModuleStatementsAndPrepareHeader, isSideEffectImport, wrapInterop, buildNamespaceInitStatements, ensureStatementsHoisted } from '@babel/helper-module-transforms';
import simplifyAccess from '@babel/helper-simple-access';
import { template, types } from '@babel/core';
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;
const requireNoInterop = source => template.expression.ast`require(${source})`;
const requireInterop = (source, file) => 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)));
}
var index = declare((api, options) => {
api.assertVersion(7);

@@ -27,5 +27,5 @@ const {

} = options;
const constantReexports = (_api$assumption = api.assumption("constantReexports")) != null ? _api$assumption : loose;
const enumerableModuleMeta = (_api$assumption2 = api.assumption("enumerableModuleMeta")) != null ? _api$assumption2 : loose;
const noIncompleteNsImportDetection = (_api$assumption3 = api.assumption("noIncompleteNsImportDetection")) != null ? _api$assumption3 : false;
const constantReexports = api.assumption("constantReexports") ?? loose;
const enumerableModuleMeta = api.assumption("enumerableModuleMeta") ?? loose;
const noIncompleteNsImportDetection = api.assumption("noIncompleteNsImportDetection") ?? false;
if (typeof lazy !== "boolean" && typeof lazy !== "function" && (!Array.isArray(lazy) || !lazy.every(item => typeof item === "string"))) {

@@ -40,3 +40,3 @@ throw new Error(`.lazy must be a boolean, array of strings, or a function`);

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

@@ -74,3 +74,3 @@ throw new Error(

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

@@ -86,3 +86,3 @@ AssignmentExpression(path) {

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

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

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

@@ -110,3 +110,3 @@ }

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

@@ -118,7 +118,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");

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

{
(0, _helperSimpleAccess.default)(path, new Set(["module", "exports"]), false);
simplifyAccess(path, new Set(["module", "exports"]));
}

@@ -138,8 +138,8 @@ path.traverse(moduleExportsVisitor, {

}
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 = types.stringLiteral(moduleName);
const {
meta,
headers
} = (0, _helperModuleTransforms.rewriteModuleStatementsAndPrepareHeader)(path, {
} = rewriteModuleStatementsAndPrepareHeader(path, {
exportName: "exports",

@@ -159,7 +159,7 @@ constantReexports,

for (const [source, metadata] of meta.source) {
const loadExpr = _core.types.callExpression(_core.types.identifier("require"), [_core.types.stringLiteral(source)]);
const loadExpr = types.callExpression(types.identifier("require"), [types.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 = types.expressionStatement(loadExpr);
} else {

@@ -169,5 +169,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}() {

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

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

@@ -188,5 +188,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);

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

});
exports.default = _default;
export { index as default };
//# sourceMappingURL=index.js.map
{
"name": "@babel/plugin-transform-modules-commonjs",
"version": "7.22.5",
"version": "8.0.0-alpha.0",
"description": "This plugin transforms ES2015 modules to CommonJS",

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

"dependencies": {
"@babel/helper-module-transforms": "^7.22.5",
"@babel/helper-plugin-utils": "^7.22.5",
"@babel/helper-simple-access": "^7.22.5"
"@babel/helper-module-transforms": "^8.0.0-alpha.0",
"@babel/helper-plugin-utils": "^8.0.0-alpha.0",
"@babel/helper-simple-access": "^8.0.0-alpha.0"
},

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

"peerDependencies": {
"@babel/core": "^7.0.0-0"
"@babel/core": "^8.0.0-alpha.0"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/helper-plugin-test-runner": "^7.22.5",
"@babel/plugin-external-helpers": "^7.22.5",
"@babel/core": "^8.0.0-alpha.0",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0",
"@babel/plugin-external-helpers": "^8.0.0-alpha.0",
"@babel/plugin-syntax-class-static-block": "^7.14.5",

@@ -37,6 +37,10 @@ "@babel/plugin-syntax-object-rest-spread": "^7.8.3"

"engines": {
"node": ">=6.9.0"
"node": "^16.20.0 || ^18.16.0 || >=20.0.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
"exports": {
".": "./lib/index.js",
"./package.json": "./package.json"
},
"type": "module"
}

@@ -5,3 +5,3 @@ # @babel/plugin-transform-modules-commonjs

See our website [@babel/plugin-transform-modules-commonjs](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs) for more information.
See our website [@babel/plugin-transform-modules-commonjs](https://babeljs.io/docs/babel-plugin-transform-modules-commonjs) for more information.

@@ -8,0 +8,0 @@ ## Install

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