Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-modules-systemjs

Package Overview
Dependencies
82
Maintainers
5
Versions
92
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.0-beta.46 to 7.0.0-beta.47

222

lib/index.js

@@ -9,3 +9,3 @@ "use strict";

function _helperPluginUtils() {
var data = require("@babel/helper-plugin-utils");
const data = require("@babel/helper-plugin-utils");

@@ -20,3 +20,3 @@ _helperPluginUtils = function _helperPluginUtils() {

function _helperHoistVariables() {
var data = _interopRequireDefault(require("@babel/helper-hoist-variables"));
const data = _interopRequireDefault(require("@babel/helper-hoist-variables"));

@@ -31,3 +31,3 @@ _helperHoistVariables = function _helperHoistVariables() {

function _core() {
var data = require("@babel/core");
const data = require("@babel/core");

@@ -43,23 +43,38 @@ _core = function _core() {

var buildTemplate = (0, _core().template)("\n SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {\n \"use strict\";\n BEFORE_BODY;\n return {\n setters: SETTERS,\n execute: function () {\n BODY;\n }\n };\n });\n");
var buildExportAll = (0, _core().template)("\n for (var KEY in TARGET) {\n if (KEY !== \"default\" && KEY !== \"__esModule\") EXPORT_OBJ[KEY] = TARGET[KEY];\n }\n");
var TYPE_IMPORT = "Import";
const buildTemplate = (0, _core().template)(`
SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
"use strict";
BEFORE_BODY;
return {
setters: SETTERS,
execute: function () {
BODY;
}
};
});
`);
const buildExportAll = (0, _core().template)(`
for (var KEY in TARGET) {
if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY];
}
`);
const TYPE_IMPORT = "Import";
var _default = (0, _helperPluginUtils().declare)(function (api, options) {
var _default = (0, _helperPluginUtils().declare)((api, options) => {
api.assertVersion(7);
var _options$systemGlobal = options.systemGlobal,
systemGlobal = _options$systemGlobal === void 0 ? "System" : _options$systemGlobal;
var IGNORE_REASSIGNMENT_SYMBOL = Symbol();
var reassignmentVisitor = {
"AssignmentExpression|UpdateExpression": function AssignmentExpressionUpdateExpression(path) {
const _options$systemGlobal = options.systemGlobal,
systemGlobal = _options$systemGlobal === void 0 ? "System" : _options$systemGlobal;
const IGNORE_REASSIGNMENT_SYMBOL = Symbol();
const reassignmentVisitor = {
"AssignmentExpression|UpdateExpression"(path) {
if (path.node[IGNORE_REASSIGNMENT_SYMBOL]) return;
path.node[IGNORE_REASSIGNMENT_SYMBOL] = true;
var arg = path.get(path.isAssignmentExpression() ? "left" : "argument");
const arg = path.get(path.isAssignmentExpression() ? "left" : "argument");
if (!arg.isIdentifier()) return;
var name = arg.node.name;
const name = arg.node.name;
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;
var exportedNames = this.exports[name];
const exportedNames = this.exports[name];
if (!exportedNames) return;
var node = path.node;
var isPostUpdateExpression = path.isUpdateExpression({
let node = path.node;
const isPostUpdateExpression = path.isUpdateExpression({
prefix: false

@@ -84,3 +99,3 @@ });

var exportedName = _ref;
const exportedName = _ref;
node = this.buildCall(exportedName, node).expression;

@@ -95,6 +110,7 @@ }

}
};
return {
visitor: {
CallExpression: function CallExpression(path, state) {
CallExpression(path, state) {
if (path.node.callee.type === TYPE_IMPORT) {

@@ -104,3 +120,4 @@ path.replaceWith(_core().types.callExpression(_core().types.memberExpression(_core().types.identifier(state.contextIdent), _core().types.identifier("import")), path.node.arguments));

},
ReferencedIdentifier: function ReferencedIdentifier(path, state) {
ReferencedIdentifier(path, state) {
if (path.node.name == "__moduleName" && !path.scope.hasBinding("__moduleName")) {

@@ -110,17 +127,19 @@ path.replaceWith(_core().types.memberExpression(_core().types.identifier(state.contextIdent), _core().types.identifier("id")));

},
Program: {
enter: function enter(path, state) {
enter(path, state) {
state.contextIdent = path.scope.generateUid("context");
},
exit: function exit(path, state) {
var exportIdent = path.scope.generateUid("export");
var contextIdent = state.contextIdent;
var exportNames = Object.create(null);
var modules = [];
var beforeBody = [];
var setters = [];
var sources = [];
var variableIds = [];
var removedPaths = [];
exit(path, state) {
const exportIdent = path.scope.generateUid("export");
const contextIdent = state.contextIdent;
const exportNames = Object.create(null);
const modules = [];
let beforeBody = [];
const setters = [];
const sources = [];
const variableIds = [];
const removedPaths = [];
function addExportName(key, val) {

@@ -132,3 +151,3 @@ exportNames[key] = exportNames[key] || [];

function pushModule(source, key, specifiers) {
var module;
let module;
modules.forEach(function (m) {

@@ -155,4 +174,4 @@ if (m.key === source) {

var body = path.get("body");
var canHoist = true;
const body = path.get("body");
let canHoist = true;

@@ -171,6 +190,6 @@ for (var _iterator2 = body, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {

var _path = _ref2;
if (_path.isExportDeclaration()) _path = _path.get("declaration");
let path = _ref2;
if (path.isExportDeclaration()) path = path.get("declaration");
if (_path.isVariableDeclaration() && _path.node.kind !== "var") {
if (path.isVariableDeclaration() && path.node.kind !== "var") {
canHoist = false;

@@ -193,28 +212,26 @@ break;

var _path2 = _ref3;
const path = _ref3;
if (canHoist && _path2.isFunctionDeclaration()) {
beforeBody.push(_path2.node);
removedPaths.push(_path2);
} else if (_path2.isImportDeclaration()) {
var source = _path2.node.source.value;
pushModule(source, "imports", _path2.node.specifiers);
if (canHoist && path.isFunctionDeclaration()) {
beforeBody.push(path.node);
removedPaths.push(path);
} else if (path.isImportDeclaration()) {
const source = path.node.source.value;
pushModule(source, "imports", path.node.specifiers);
for (var name in _path2.getBindingIdentifiers()) {
_path2.scope.removeBinding(name);
for (const name in path.getBindingIdentifiers()) {
path.scope.removeBinding(name);
variableIds.push(_core().types.identifier(name));
}
_path2.remove();
} else if (_path2.isExportAllDeclaration()) {
pushModule(_path2.node.source.value, "exports", _path2.node);
path.remove();
} else if (path.isExportAllDeclaration()) {
pushModule(path.node.source.value, "exports", path.node);
path.remove();
} else if (path.isExportDefaultDeclaration()) {
const declar = path.get("declaration");
_path2.remove();
} else if (_path2.isExportDefaultDeclaration()) {
var declar = _path2.get("declaration");
if (declar.isClassDeclaration() || declar.isFunctionDeclaration()) {
var id = declar.node.id;
var nodes = [];
const id = declar.node.id;
const nodes = [];

@@ -230,54 +247,51 @@ if (id) {

if (!canHoist || declar.isClassDeclaration()) {
_path2.replaceWithMultiple(nodes);
path.replaceWithMultiple(nodes);
} else {
beforeBody = beforeBody.concat(nodes);
removedPaths.push(_path2);
removedPaths.push(path);
}
} else {
_path2.replaceWith(buildExportCall("default", declar.node));
path.replaceWith(buildExportCall("default", declar.node));
}
} else if (_path2.isExportNamedDeclaration()) {
var _declar = _path2.get("declaration");
} else if (path.isExportNamedDeclaration()) {
const declar = path.get("declaration");
if (_declar.node) {
_path2.replaceWith(_declar);
if (declar.node) {
path.replaceWith(declar);
const nodes = [];
let bindingIdentifiers;
var _nodes = [];
var bindingIdentifiers = void 0;
if (path.isFunction()) {
const node = declar.node;
const name = node.id.name;
if (_path2.isFunction()) {
var node = _declar.node;
var _name = node.id.name;
if (canHoist) {
addExportName(_name, _name);
addExportName(name, name);
beforeBody.push(node);
beforeBody.push(buildExportCall(_name, _core().types.cloneNode(node.id)));
removedPaths.push(_path2);
beforeBody.push(buildExportCall(name, _core().types.cloneNode(node.id)));
removedPaths.push(path);
} else {
var _bindingIdentifiers;
bindingIdentifiers = (_bindingIdentifiers = {}, _bindingIdentifiers[_name] = node.id, _bindingIdentifiers);
bindingIdentifiers = {
[name]: node.id
};
}
} else {
bindingIdentifiers = _declar.getBindingIdentifiers();
bindingIdentifiers = declar.getBindingIdentifiers();
}
for (var _name2 in bindingIdentifiers) {
addExportName(_name2, _name2);
_nodes.push(buildExportCall(_name2, _core().types.identifier(_name2)));
for (const name in bindingIdentifiers) {
addExportName(name, name);
nodes.push(buildExportCall(name, _core().types.identifier(name)));
}
_path2.insertAfter(_nodes);
path.insertAfter(nodes);
} else {
var specifiers = _path2.node.specifiers;
const specifiers = path.node.specifiers;
if (specifiers && specifiers.length) {
if (_path2.node.source) {
pushModule(_path2.node.source.value, "exports", specifiers);
_path2.remove();
if (path.node.source) {
pushModule(path.node.source.value, "exports", specifiers);
path.remove();
} else {
var _nodes2 = [];
const nodes = [];

@@ -296,10 +310,8 @@ for (var _iterator6 = specifiers, _isArray6 = Array.isArray(_iterator6), _i7 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {

var specifier = _ref6;
_nodes2.push(buildExportCall(specifier.exported.name, specifier.local));
const specifier = _ref6;
nodes.push(buildExportCall(specifier.exported.name, specifier.local));
addExportName(specifier.local.name, specifier.exported.name);
}
_path2.replaceWithMultiple(_nodes2);
path.replaceWithMultiple(nodes);
}

@@ -312,4 +324,4 @@ }

modules.forEach(function (specifiers) {
var setterBody = [];
var target = path.scope.generateUid(specifiers.key);
const setterBody = [];
const target = path.scope.generateUid(specifiers.key);

@@ -328,3 +340,3 @@ for (var _iterator4 = specifiers.imports, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {

var specifier = _ref4;
let specifier = _ref4;

@@ -343,3 +355,3 @@ if (_core().types.isImportNamespaceSpecifier(specifier)) {

if (specifiers.exports.length) {
var exportObj = path.scope.generateUid("exportObj");
const exportObj = path.scope.generateUid("exportObj");
setterBody.push(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(exportObj), _core().types.objectExpression([]))]));

@@ -359,3 +371,3 @@

var node = _ref5;
const node = _ref5;

@@ -379,15 +391,11 @@ if (_core().types.isExportAllDeclaration(node)) {

});
var moduleName = this.getModuleName();
let moduleName = this.getModuleName();
if (moduleName) moduleName = _core().types.stringLiteral(moduleName);
if (canHoist) {
(0, _helperHoistVariables().default)(path, function (id) {
return variableIds.push(id);
});
(0, _helperHoistVariables().default)(path, id => variableIds.push(id));
}
if (variableIds.length) {
beforeBody.unshift(_core().types.variableDeclaration("var", variableIds.map(function (id) {
return _core().types.variableDeclarator(id);
})));
beforeBody.unshift(_core().types.variableDeclaration("var", variableIds.map(id => _core().types.variableDeclarator(id))));
}

@@ -402,5 +410,4 @@

for (var _i6 = 0; _i6 < removedPaths.length; _i6++) {
var _path3 = removedPaths[_i6];
_path3.remove();
const path = removedPaths[_i6];
path.remove();
}

@@ -419,2 +426,3 @@

}
}

@@ -421,0 +429,0 @@ }

{
"name": "@babel/plugin-transform-modules-systemjs",
"version": "7.0.0-beta.46",
"version": "7.0.0-beta.47",
"description": "This plugin transforms ES2015 modules to SystemJS",

@@ -9,4 +9,4 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-modules-systemjs",

"dependencies": {
"@babel/helper-hoist-variables": "7.0.0-beta.46",
"@babel/helper-plugin-utils": "7.0.0-beta.46"
"@babel/helper-hoist-variables": "7.0.0-beta.47",
"@babel/helper-plugin-utils": "7.0.0-beta.47"
},

@@ -17,9 +17,9 @@ "keywords": [

"peerDependencies": {
"@babel/core": "7.0.0-beta.46"
"@babel/core": "7.0.0-beta.47"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.46",
"@babel/helper-plugin-test-runner": "7.0.0-beta.46",
"@babel/plugin-syntax-dynamic-import": "7.0.0-beta.46"
"@babel/core": "7.0.0-beta.47",
"@babel/helper-plugin-test-runner": "7.0.0-beta.47",
"@babel/plugin-syntax-dynamic-import": "7.0.0-beta.47"
}
}
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