@babel/plugin-transform-modules-systemjs
Advanced tools
Comparing version 7.10.5 to 7.12.0
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.getExportSpecifierName = getExportSpecifierName; | ||
exports.default = void 0; | ||
@@ -19,2 +20,4 @@ | ||
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -28,5 +31,3 @@ | ||
setters: SETTERS, | ||
execute: function () { | ||
BODY; | ||
} | ||
execute: EXECUTE, | ||
}; | ||
@@ -46,3 +47,19 @@ }); | ||
function constructExportCall(path, exportIdent, exportNames, exportValues, exportStarTarget) { | ||
function getExportSpecifierName(node, stringSpecifiers) { | ||
if (node.type === "Identifier") { | ||
return node.name; | ||
} else if (node.type === "StringLiteral") { | ||
const stringValue = node.value; | ||
if (!(0, _helperValidatorIdentifier.isIdentifierName)(stringValue)) { | ||
stringSpecifiers.add(stringValue); | ||
} | ||
return stringValue; | ||
} else { | ||
throw new Error(`Expected export specifier to be either Identifier or StringLiteral, got ${node.type}`); | ||
} | ||
} | ||
function constructExportCall(path, exportIdent, exportNames, exportValues, exportStarTarget, stringSpecifiers) { | ||
const statements = []; | ||
@@ -58,3 +75,3 @@ | ||
const exportValue = exportValues[i]; | ||
objectProperties.push(_core.types.objectProperty(_core.types.identifier(exportName), exportValue)); | ||
objectProperties.push(_core.types.objectProperty(stringSpecifiers.has(exportName) ? _core.types.stringLiteral(exportName) : _core.types.identifier(exportName), exportValue)); | ||
} | ||
@@ -176,2 +193,3 @@ | ||
state.contextIdent = path.scope.generateUid("context"); | ||
state.stringSpecifiers = new Set(); | ||
@@ -186,3 +204,6 @@ if (!allowTopLevelThis) { | ||
const exportIdent = scope.generateUid("export"); | ||
const contextIdent = state.contextIdent; | ||
const { | ||
contextIdent, | ||
stringSpecifiers | ||
} = state; | ||
const exportMap = Object.create(null); | ||
@@ -316,12 +337,17 @@ const modules = []; | ||
for (const specifier of specifiers) { | ||
const binding = scope.getBinding(specifier.local.name); | ||
const { | ||
local, | ||
exported | ||
} = specifier; | ||
const binding = scope.getBinding(local.name); | ||
const exportedName = getExportSpecifierName(exported, stringSpecifiers); | ||
if (binding && _core.types.isFunctionDeclaration(binding.path.node)) { | ||
exportNames.push(specifier.exported.name); | ||
exportValues.push(_core.types.cloneNode(specifier.local)); | ||
exportNames.push(exportedName); | ||
exportValues.push(_core.types.cloneNode(local)); | ||
} else if (!binding) { | ||
nodes.push(buildExportCall(specifier.exported.name, specifier.local)); | ||
nodes.push(buildExportCall(exportedName, local)); | ||
} | ||
addExportName(specifier.local.name, specifier.exported.name); | ||
addExportName(local.name, exportedName); | ||
} | ||
@@ -350,3 +376,6 @@ | ||
if (_core.types.isImportSpecifier(specifier)) { | ||
setterBody.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", specifier.local, _core.types.memberExpression(_core.types.identifier(target), specifier.imported)))); | ||
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")))); | ||
} | ||
@@ -364,8 +393,9 @@ } | ||
} else if (_core.types.isExportSpecifier(node)) { | ||
exportNames.push(node.exported.name); | ||
exportValues.push(_core.types.memberExpression(_core.types.identifier(target), node.local)); | ||
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 {} | ||
} | ||
setterBody = setterBody.concat(constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, hasExportStar ? _core.types.identifier(target) : null)); | ||
setterBody = setterBody.concat(constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, hasExportStar ? _core.types.identifier(target) : null, stringSpecifiers)); | ||
} | ||
@@ -381,5 +411,7 @@ | ||
if (!hasInit) { | ||
exportNames.push(name); | ||
exportValues.push(scope.buildUndefinedNode()); | ||
if (!hasInit && name in exportMap) { | ||
for (const exported of exportMap[name]) { | ||
exportNames.push(exported); | ||
exportValues.push(scope.buildUndefinedNode()); | ||
} | ||
} | ||
@@ -393,3 +425,3 @@ }, null); | ||
if (exportNames.length) { | ||
beforeBody = beforeBody.concat(constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, null)); | ||
beforeBody = beforeBody.concat(constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, null, stringSpecifiers)); | ||
} | ||
@@ -407,2 +439,15 @@ | ||
let hasTLA = false; | ||
path.traverse({ | ||
AwaitExpression(path) { | ||
hasTLA = true; | ||
path.stop(); | ||
}, | ||
Function(path) { | ||
path.skip(); | ||
}, | ||
noScope: true | ||
}); | ||
path.node.body = [buildTemplate({ | ||
@@ -413,4 +458,4 @@ SYSTEM_REGISTER: _core.types.memberExpression(_core.types.identifier(systemGlobal), _core.types.identifier("register")), | ||
SETTERS: _core.types.arrayExpression(setters), | ||
EXECUTE: _core.types.functionExpression(null, [], _core.types.blockStatement(path.node.body), false, hasTLA), | ||
SOURCES: _core.types.arrayExpression(sources), | ||
BODY: path.node.body, | ||
EXPORT_IDENTIFIER: _core.types.identifier(exportIdent), | ||
@@ -417,0 +462,0 @@ CONTEXT_IDENTIFIER: _core.types.identifier(contextIdent) |
{ | ||
"name": "@babel/plugin-transform-modules-systemjs", | ||
"version": "7.10.5", | ||
"version": "7.12.0", | ||
"description": "This plugin transforms ES2015 modules to SystemJS", | ||
@@ -17,4 +17,5 @@ "repository": { | ||
"@babel/helper-hoist-variables": "^7.10.4", | ||
"@babel/helper-module-transforms": "^7.10.5", | ||
"@babel/helper-module-transforms": "^7.12.0", | ||
"@babel/helper-plugin-utils": "^7.10.4", | ||
"@babel/helper-validator-identifier": "^7.10.4", | ||
"babel-plugin-dynamic-import-node": "^2.3.3" | ||
@@ -29,7 +30,6 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.10.5", | ||
"@babel/core": "^7.12.0", | ||
"@babel/helper-plugin-test-runner": "^7.10.4", | ||
"@babel/plugin-syntax-dynamic-import": "^7.8.0" | ||
}, | ||
"gitHead": "f7964a9ac51356f7df6404a25b27ba1cffba1ba7" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20411
382
6