Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-modules-systemjs

Package Overview
Dependencies
59
Maintainers
4
Versions
92
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.22.5 to 8.0.0-alpha.0

157

lib/index.js

@@ -1,14 +0,8 @@

"use strict";
import { declare } from '@babel/helper-plugin-utils';
import hoistVariables from '@babel/helper-hoist-variables';
import { template, types } from '@babel/core';
import { buildDynamicImport, rewriteThis, getModuleName } from '@babel/helper-module-transforms';
import { isIdentifierName } from '@babel/helper-validator-identifier';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.getExportSpecifierName = getExportSpecifierName;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperHoistVariables = require("@babel/helper-hoist-variables");
var _core = require("@babel/core");
var _helperModuleTransforms = require("@babel/helper-module-transforms");
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
const buildTemplate = _core.template.statement(`
const buildTemplate = template.statement(`
SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {

@@ -23,3 +17,3 @@ "use strict";

`);
const buildExportAll = _core.template.statement(`
const buildExportAll = template.statement(`
for (var KEY in TARGET) {

@@ -29,7 +23,2 @@ if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY];

`);
const MISSING_PLUGIN_WARNING = `\
WARNING: Dynamic import() transformation must be enabled using the
@babel/plugin-transform-dynamic-import plugin. Babel 8 will
no longer transform import() without using that plugin.
`;
const MISSING_PLUGIN_ERROR = `\

@@ -45,3 +34,3 @@ ERROR: Dynamic import() transformation must be enabled using the

const stringValue = node.value;
if (!(0, _helperValidatorIdentifier.isIdentifierName)(stringValue)) {
if (!isIdentifierName(stringValue)) {
stringSpecifiers.add(stringValue);

@@ -58,3 +47,3 @@ }

if (exportNames.length === 1) {
statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.stringLiteral(exportNames[0]), exportValues[0]])));
statements.push(types.expressionStatement(types.callExpression(exportIdent, [types.stringLiteral(exportNames[0]), exportValues[0]])));
} else {

@@ -65,12 +54,12 @@ const objectProperties = [];

const exportValue = exportValues[i];
objectProperties.push(_core.types.objectProperty(stringSpecifiers.has(exportName) ? _core.types.stringLiteral(exportName) : _core.types.identifier(exportName), exportValue));
objectProperties.push(types.objectProperty(stringSpecifiers.has(exportName) ? types.stringLiteral(exportName) : types.identifier(exportName), exportValue));
}
statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.objectExpression(objectProperties)])));
statements.push(types.expressionStatement(types.callExpression(exportIdent, [types.objectExpression(objectProperties)])));
}
} else {
const exportObj = path.scope.generateUid("exportObj");
statements.push(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(exportObj), _core.types.objectExpression([]))]));
statements.push(types.variableDeclaration("var", [types.variableDeclarator(types.identifier(exportObj), types.objectExpression([]))]));
statements.push(buildExportAll({
KEY: path.scope.generateUidIdentifier("key"),
EXPORT_OBJ: _core.types.identifier(exportObj),
EXPORT_OBJ: types.identifier(exportObj),
TARGET: exportStarTarget

@@ -81,9 +70,9 @@ }));

const exportValue = exportValues[i];
statements.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.memberExpression(_core.types.identifier(exportObj), _core.types.identifier(exportName)), exportValue)));
statements.push(types.expressionStatement(types.assignmentExpression("=", types.memberExpression(types.identifier(exportObj), types.identifier(exportName)), exportValue)));
}
statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.identifier(exportObj)])));
statements.push(types.expressionStatement(types.callExpression(exportIdent, [types.identifier(exportObj)])));
}
return statements;
}
var _default = (0, _helperPluginUtils.declare)((api, options) => {
var index = declare((api, options) => {
api.assertVersion(7);

@@ -109,6 +98,6 @@ const {

for (const exportedName of exportedNames) {
exprs.push(this.buildCall(exportedName, _core.types.identifier(name)).expression);
exprs.push(this.buildCall(exportedName, types.identifier(name)).expression);
}
}
path.replaceWith(_core.types.sequenceExpression(exprs));
path.replaceWith(types.sequenceExpression(exprs));
return;

@@ -122,7 +111,7 @@ }

let node = path.node;
const isPostUpdateExpression = _core.types.isUpdateExpression(node, {
const isPostUpdateExpression = types.isUpdateExpression(node, {
prefix: false
});
if (isPostUpdateExpression) {
node = _core.types.binaryExpression(node.operator[0], _core.types.unaryExpression("+", _core.types.cloneNode(node.argument)), _core.types.numericLiteral(1));
node = types.binaryExpression(node.operator[0], types.unaryExpression("+", types.cloneNode(node.argument)), types.numericLiteral(1));
}

@@ -133,3 +122,3 @@ for (const exportedName of exportedNames) {

if (isPostUpdateExpression) {
node = _core.types.sequenceExpression([node, path.node]);
node = types.sequenceExpression([node, path.node]);
}

@@ -146,9 +135,9 @@ path.replaceWith(node);

CallExpression(path, state) {
if (_core.types.isImport(path.node.callee)) {
if (types.isImport(path.node.callee)) {
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) {
{
console.warn(MISSING_PLUGIN_WARNING);
throw new Error(MISSING_PLUGIN_ERROR);
}
}
path.replaceWith((0, _helperModuleTransforms.buildDynamicImport)(path.node, false, true, specifier => _core.types.callExpression(_core.types.memberExpression(_core.types.identifier(state.contextIdent), _core.types.identifier("import")), [specifier])));
path.replaceWith(buildDynamicImport(path.node, false, true, specifier => types.callExpression(types.memberExpression(types.identifier(state.contextIdent), types.identifier("import")), [specifier])));
}

@@ -158,3 +147,3 @@ },

if (path.node.meta.name === "import" && path.node.property.name === "meta") {
path.replaceWith(_core.types.memberExpression(_core.types.identifier(state.contextIdent), _core.types.identifier("meta")));
path.replaceWith(types.memberExpression(types.identifier(state.contextIdent), types.identifier("meta")));
}

@@ -164,3 +153,3 @@ },

if (path.node.name === "__moduleName" && !path.scope.hasBinding("__moduleName")) {
path.replaceWith(_core.types.memberExpression(_core.types.identifier(state.contextIdent), _core.types.identifier("id")));
path.replaceWith(types.memberExpression(types.identifier(state.contextIdent), types.identifier("id")));
}

@@ -173,3 +162,3 @@ },

if (!allowTopLevelThis) {
(0, _helperModuleTransforms.rewriteThis)(path);
rewriteThis(path);
}

@@ -212,3 +201,3 @@ },

function buildExportCall(name, val) {
return _core.types.expressionStatement(_core.types.callExpression(_core.types.identifier(exportIdent), [_core.types.stringLiteral(name), val]));
return types.expressionStatement(types.callExpression(types.identifier(exportIdent), [types.stringLiteral(name), val]));
}

@@ -223,4 +212,4 @@ const exportNames = [];

} else if (path.isClassDeclaration()) {
variableIds.push(_core.types.cloneNode(path.node.id));
path.replaceWith(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(path.node.id), _core.types.toExpression(path.node))));
variableIds.push(types.cloneNode(path.node.id));
path.replaceWith(types.expressionStatement(types.assignmentExpression("=", types.cloneNode(path.node.id), types.toExpression(path.node))));
} else if (path.isVariableDeclaration()) {

@@ -233,3 +222,3 @@ path.node.kind = "var";

scope.removeBinding(name);
variableIds.push(_core.types.identifier(name));
variableIds.push(types.identifier(name));
}

@@ -242,3 +231,3 @@ path.remove();

const declar = path.node.declaration;
if (_core.types.isClassDeclaration(declar)) {
if (types.isClassDeclaration(declar)) {
const id = declar.id;

@@ -248,11 +237,11 @@ if (id) {

exportValues.push(scope.buildUndefinedNode());
variableIds.push(_core.types.cloneNode(id));
variableIds.push(types.cloneNode(id));
addExportName(id.name, "default");
path.replaceWith(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(id), _core.types.toExpression(declar))));
path.replaceWith(types.expressionStatement(types.assignmentExpression("=", types.cloneNode(id), types.toExpression(declar))));
} else {
exportNames.push("default");
exportValues.push(_core.types.toExpression(declar));
exportValues.push(types.toExpression(declar));
removedPaths.push(path);
}
} else if (_core.types.isFunctionDeclaration(declar)) {
} else if (types.isFunctionDeclaration(declar)) {
const id = declar.id;

@@ -262,7 +251,7 @@ if (id) {

exportNames.push("default");
exportValues.push(_core.types.cloneNode(id));
exportValues.push(types.cloneNode(id));
addExportName(id.name, "default");
} else {
exportNames.push("default");
exportValues.push(_core.types.toExpression(declar));
exportValues.push(types.toExpression(declar));
}

@@ -277,3 +266,3 @@ removedPaths.push(path);

path.replaceWith(declar);
if (_core.types.isFunction(declar)) {
if (types.isFunction(declar)) {
const name = declar.id.name;

@@ -283,16 +272,16 @@ addExportName(name, name);

exportNames.push(name);
exportValues.push(_core.types.cloneNode(declar.id));
exportValues.push(types.cloneNode(declar.id));
removedPaths.push(path);
} else if (_core.types.isClass(declar)) {
} else if (types.isClass(declar)) {
const name = declar.id.name;
exportNames.push(name);
exportValues.push(scope.buildUndefinedNode());
variableIds.push(_core.types.cloneNode(declar.id));
path.replaceWith(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(declar.id), _core.types.toExpression(declar))));
variableIds.push(types.cloneNode(declar.id));
path.replaceWith(types.expressionStatement(types.assignmentExpression("=", types.cloneNode(declar.id), types.toExpression(declar))));
addExportName(name, name);
} else {
if (_core.types.isVariableDeclaration(declar)) {
if (types.isVariableDeclaration(declar)) {
declar.kind = "var";
}
for (const name of Object.keys(_core.types.getBindingIdentifiers(declar))) {
for (const name of Object.keys(types.getBindingIdentifiers(declar))) {
addExportName(name, name);

@@ -303,3 +292,3 @@ }

const specifiers = path.node.specifiers;
if (specifiers != null && specifiers.length) {
if (specifiers?.length) {
if (path.node.source) {

@@ -317,5 +306,5 @@ pushModule(path.node.source.value, "exports", specifiers);

const exportedName = getExportSpecifierName(exported, stringSpecifiers);
if (binding && _core.types.isFunctionDeclaration(binding.path.node)) {
if (binding && types.isFunctionDeclaration(binding.path.node)) {
exportNames.push(exportedName);
exportValues.push(_core.types.cloneNode(local));
exportValues.push(types.cloneNode(local));
} else if (!binding) {

@@ -338,12 +327,12 @@ nodes.push(buildExportCall(exportedName, local));

for (let specifier of specifiers.imports) {
if (_core.types.isImportNamespaceSpecifier(specifier)) {
setterBody.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", specifier.local, _core.types.identifier(target))));
} else if (_core.types.isImportDefaultSpecifier(specifier)) {
specifier = _core.types.importSpecifier(specifier.local, _core.types.identifier("default"));
if (types.isImportNamespaceSpecifier(specifier)) {
setterBody.push(types.expressionStatement(types.assignmentExpression("=", specifier.local, types.identifier(target))));
} else if (types.isImportDefaultSpecifier(specifier)) {
specifier = types.importSpecifier(specifier.local, types.identifier("default"));
}
if (_core.types.isImportSpecifier(specifier)) {
if (types.isImportSpecifier(specifier)) {
const {
imported
} = specifier;
setterBody.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", specifier.local, _core.types.memberExpression(_core.types.identifier(target), specifier.imported, imported.type === "StringLiteral"))));
setterBody.push(types.expressionStatement(types.assignmentExpression("=", specifier.local, types.memberExpression(types.identifier(target), specifier.imported, imported.type === "StringLiteral"))));
}

@@ -356,18 +345,18 @@ }

for (const node of specifiers.exports) {
if (_core.types.isExportAllDeclaration(node)) {
if (types.isExportAllDeclaration(node)) {
hasExportStar = true;
} else if (_core.types.isExportSpecifier(node)) {
} else if (types.isExportSpecifier(node)) {
const exportedName = getExportSpecifierName(node.exported, stringSpecifiers);
exportNames.push(exportedName);
exportValues.push(_core.types.memberExpression(_core.types.identifier(target), node.local, _core.types.isStringLiteral(node.local)));
} else {}
exportValues.push(types.memberExpression(types.identifier(target), node.local, types.isStringLiteral(node.local)));
} else ;
}
setterBody.push(...constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, hasExportStar ? _core.types.identifier(target) : null, stringSpecifiers));
setterBody.push(...constructExportCall(path, types.identifier(exportIdent), exportNames, exportValues, hasExportStar ? types.identifier(target) : null, stringSpecifiers));
}
sources.push(_core.types.stringLiteral(specifiers.key));
setters.push(_core.types.functionExpression(null, [_core.types.identifier(target)], _core.types.blockStatement(setterBody)));
sources.push(types.stringLiteral(specifiers.key));
setters.push(types.functionExpression(null, [types.identifier(target)], types.blockStatement(setterBody)));
});
let moduleName = (0, _helperModuleTransforms.getModuleName)(this.file.opts, options);
if (moduleName) moduleName = _core.types.stringLiteral(moduleName);
(0, _helperHoistVariables.default)(path, (id, name, hasInit) => {
let moduleName = getModuleName(this.file.opts, options);
if (moduleName) moduleName = types.stringLiteral(moduleName);
hoistVariables(path, (id, name, hasInit) => {
variableIds.push(id);

@@ -382,6 +371,6 @@ if (!hasInit && name in exportMap) {

if (variableIds.length) {
beforeBody.unshift(_core.types.variableDeclaration("var", variableIds.map(id => _core.types.variableDeclarator(id))));
beforeBody.unshift(types.variableDeclaration("var", variableIds.map(id => types.variableDeclarator(id))));
}
if (exportNames.length) {
beforeBody.push(...constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, null, stringSpecifiers));
beforeBody.push(...constructExportCall(path, types.identifier(exportIdent), exportNames, exportValues, null, stringSpecifiers));
}

@@ -408,10 +397,10 @@ path.traverse(reassignmentVisitor, {

path.node.body = [buildTemplate({
SYSTEM_REGISTER: _core.types.memberExpression(_core.types.identifier(systemGlobal), _core.types.identifier("register")),
SYSTEM_REGISTER: types.memberExpression(types.identifier(systemGlobal), types.identifier("register")),
BEFORE_BODY: beforeBody,
MODULE_NAME: moduleName,
SETTERS: _core.types.arrayExpression(setters),
EXECUTE: _core.types.functionExpression(null, [], _core.types.blockStatement(path.node.body), false, hasTLA),
SOURCES: _core.types.arrayExpression(sources),
EXPORT_IDENTIFIER: _core.types.identifier(exportIdent),
CONTEXT_IDENTIFIER: _core.types.identifier(contextIdent)
SETTERS: types.arrayExpression(setters),
EXECUTE: types.functionExpression(null, [], types.blockStatement(path.node.body), false, hasTLA),
SOURCES: types.arrayExpression(sources),
EXPORT_IDENTIFIER: types.identifier(exportIdent),
CONTEXT_IDENTIFIER: types.identifier(contextIdent)
})];

@@ -423,4 +412,4 @@ }

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

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

"dependencies": {
"@babel/helper-hoist-variables": "^7.22.5",
"@babel/helper-module-transforms": "^7.22.5",
"@babel/helper-plugin-utils": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.5"
"@babel/helper-hoist-variables": "^8.0.0-alpha.0",
"@babel/helper-module-transforms": "^8.0.0-alpha.0",
"@babel/helper-plugin-utils": "^8.0.0-alpha.0",
"@babel/helper-validator-identifier": "^8.0.0-alpha.0"
},

@@ -26,7 +26,7 @@ "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/core": "^8.0.0-alpha.0",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3"

@@ -36,6 +36,10 @@ },

"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-systemjs

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

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

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