@babel/plugin-transform-modules-systemjs
Advanced tools
Comparing version 7.21.4-esm.3 to 7.21.4-esm.4
148
lib/index.js
@@ -1,14 +0,7 @@ | ||
"use strict"; | ||
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(` | ||
import { declare } from "@babel/helper-plugin-utils"; | ||
import hoistVariables from "@babel/helper-hoist-variables"; | ||
import { template, types as t } from "@babel/core"; | ||
import { buildDynamicImport, getModuleName, rewriteThis } from "@babel/helper-module-transforms"; | ||
import { isIdentifierName } from "@babel/helper-validator-identifier"; | ||
const buildTemplate = template.statement(` | ||
SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) { | ||
@@ -23,3 +16,3 @@ "use strict"; | ||
`); | ||
const buildExportAll = _core.template.statement(` | ||
const buildExportAll = template.statement(` | ||
for (var KEY in TARGET) { | ||
@@ -39,3 +32,3 @@ if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY]; | ||
`; | ||
function getExportSpecifierName(node, stringSpecifiers) { | ||
export function getExportSpecifierName(node, stringSpecifiers) { | ||
if (node.type === "Identifier") { | ||
@@ -45,3 +38,3 @@ return node.name; | ||
const stringValue = node.value; | ||
if (!(0, _helperValidatorIdentifier.isIdentifierName)(stringValue)) { | ||
if (!isIdentifierName(stringValue)) { | ||
stringSpecifiers.add(stringValue); | ||
@@ -58,3 +51,3 @@ } | ||
if (exportNames.length === 1) { | ||
statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.stringLiteral(exportNames[0]), exportValues[0]]))); | ||
statements.push(t.expressionStatement(t.callExpression(exportIdent, [t.stringLiteral(exportNames[0]), exportValues[0]]))); | ||
} else { | ||
@@ -65,12 +58,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(t.objectProperty(stringSpecifiers.has(exportName) ? t.stringLiteral(exportName) : t.identifier(exportName), exportValue)); | ||
} | ||
statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.objectExpression(objectProperties)]))); | ||
statements.push(t.expressionStatement(t.callExpression(exportIdent, [t.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(t.variableDeclaration("var", [t.variableDeclarator(t.identifier(exportObj), t.objectExpression([]))])); | ||
statements.push(buildExportAll({ | ||
KEY: path.scope.generateUidIdentifier("key"), | ||
EXPORT_OBJ: _core.types.identifier(exportObj), | ||
EXPORT_OBJ: t.identifier(exportObj), | ||
TARGET: exportStarTarget | ||
@@ -81,9 +74,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(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier(exportObj), t.identifier(exportName)), exportValue))); | ||
} | ||
statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.identifier(exportObj)]))); | ||
statements.push(t.expressionStatement(t.callExpression(exportIdent, [t.identifier(exportObj)]))); | ||
} | ||
return statements; | ||
} | ||
var _default = (0, _helperPluginUtils.declare)((api, options) => { | ||
export default declare((api, options) => { | ||
api.assertVersion(7); | ||
@@ -109,6 +102,6 @@ const { | ||
for (const exportedName of exportedNames) { | ||
exprs.push(this.buildCall(exportedName, _core.types.identifier(name)).expression); | ||
exprs.push(this.buildCall(exportedName, t.identifier(name)).expression); | ||
} | ||
} | ||
path.replaceWith(_core.types.sequenceExpression(exprs)); | ||
path.replaceWith(t.sequenceExpression(exprs)); | ||
return; | ||
@@ -122,7 +115,7 @@ } | ||
let node = path.node; | ||
const isPostUpdateExpression = _core.types.isUpdateExpression(node, { | ||
const isPostUpdateExpression = t.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 = t.binaryExpression(node.operator[0], t.unaryExpression("+", t.cloneNode(node.argument)), t.numericLiteral(1)); | ||
} | ||
@@ -133,3 +126,3 @@ for (const exportedName of exportedNames) { | ||
if (isPostUpdateExpression) { | ||
node = _core.types.sequenceExpression([node, path.node]); | ||
node = t.sequenceExpression([node, path.node]); | ||
} | ||
@@ -146,3 +139,3 @@ path.replaceWith(node); | ||
CallExpression(path, state) { | ||
if (_core.types.isImport(path.node.callee)) { | ||
if (t.isImport(path.node.callee)) { | ||
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) { | ||
@@ -153,3 +146,3 @@ { | ||
} | ||
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 => t.callExpression(t.memberExpression(t.identifier(state.contextIdent), t.identifier("import")), [specifier]))); | ||
} | ||
@@ -159,3 +152,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(t.memberExpression(t.identifier(state.contextIdent), t.identifier("meta"))); | ||
} | ||
@@ -165,3 +158,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(t.memberExpression(t.identifier(state.contextIdent), t.identifier("id"))); | ||
} | ||
@@ -174,3 +167,3 @@ }, | ||
if (!allowTopLevelThis) { | ||
(0, _helperModuleTransforms.rewriteThis)(path); | ||
rewriteThis(path); | ||
} | ||
@@ -213,3 +206,3 @@ }, | ||
function buildExportCall(name, val) { | ||
return _core.types.expressionStatement(_core.types.callExpression(_core.types.identifier(exportIdent), [_core.types.stringLiteral(name), val])); | ||
return t.expressionStatement(t.callExpression(t.identifier(exportIdent), [t.stringLiteral(name), val])); | ||
} | ||
@@ -224,4 +217,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(t.cloneNode(path.node.id)); | ||
path.replaceWith(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(path.node.id), t.toExpression(path.node)))); | ||
} else if (path.isVariableDeclaration()) { | ||
@@ -234,3 +227,3 @@ path.node.kind = "var"; | ||
scope.removeBinding(name); | ||
variableIds.push(_core.types.identifier(name)); | ||
variableIds.push(t.identifier(name)); | ||
} | ||
@@ -243,3 +236,3 @@ path.remove(); | ||
const declar = path.node.declaration; | ||
if (_core.types.isClassDeclaration(declar)) { | ||
if (t.isClassDeclaration(declar)) { | ||
const id = declar.id; | ||
@@ -249,11 +242,11 @@ if (id) { | ||
exportValues.push(scope.buildUndefinedNode()); | ||
variableIds.push(_core.types.cloneNode(id)); | ||
variableIds.push(t.cloneNode(id)); | ||
addExportName(id.name, "default"); | ||
path.replaceWith(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(id), _core.types.toExpression(declar)))); | ||
path.replaceWith(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(id), t.toExpression(declar)))); | ||
} else { | ||
exportNames.push("default"); | ||
exportValues.push(_core.types.toExpression(declar)); | ||
exportValues.push(t.toExpression(declar)); | ||
removedPaths.push(path); | ||
} | ||
} else if (_core.types.isFunctionDeclaration(declar)) { | ||
} else if (t.isFunctionDeclaration(declar)) { | ||
const id = declar.id; | ||
@@ -263,7 +256,7 @@ if (id) { | ||
exportNames.push("default"); | ||
exportValues.push(_core.types.cloneNode(id)); | ||
exportValues.push(t.cloneNode(id)); | ||
addExportName(id.name, "default"); | ||
} else { | ||
exportNames.push("default"); | ||
exportValues.push(_core.types.toExpression(declar)); | ||
exportValues.push(t.toExpression(declar)); | ||
} | ||
@@ -278,3 +271,3 @@ removedPaths.push(path); | ||
path.replaceWith(declar); | ||
if (_core.types.isFunction(declar)) { | ||
if (t.isFunction(declar)) { | ||
const name = declar.id.name; | ||
@@ -284,16 +277,16 @@ addExportName(name, name); | ||
exportNames.push(name); | ||
exportValues.push(_core.types.cloneNode(declar.id)); | ||
exportValues.push(t.cloneNode(declar.id)); | ||
removedPaths.push(path); | ||
} else if (_core.types.isClass(declar)) { | ||
} else if (t.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(t.cloneNode(declar.id)); | ||
path.replaceWith(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(declar.id), t.toExpression(declar)))); | ||
addExportName(name, name); | ||
} else { | ||
if (_core.types.isVariableDeclaration(declar)) { | ||
if (t.isVariableDeclaration(declar)) { | ||
declar.kind = "var"; | ||
} | ||
for (const name of Object.keys(_core.types.getBindingIdentifiers(declar))) { | ||
for (const name of Object.keys(t.getBindingIdentifiers(declar))) { | ||
addExportName(name, name); | ||
@@ -317,5 +310,5 @@ } | ||
const exportedName = getExportSpecifierName(exported, stringSpecifiers); | ||
if (binding && _core.types.isFunctionDeclaration(binding.path.node)) { | ||
if (binding && t.isFunctionDeclaration(binding.path.node)) { | ||
exportNames.push(exportedName); | ||
exportValues.push(_core.types.cloneNode(local)); | ||
exportValues.push(t.cloneNode(local)); | ||
} else if (!binding) { | ||
@@ -338,12 +331,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 (t.isImportNamespaceSpecifier(specifier)) { | ||
setterBody.push(t.expressionStatement(t.assignmentExpression("=", specifier.local, t.identifier(target)))); | ||
} else if (t.isImportDefaultSpecifier(specifier)) { | ||
specifier = t.importSpecifier(specifier.local, t.identifier("default")); | ||
} | ||
if (_core.types.isImportSpecifier(specifier)) { | ||
if (t.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(t.expressionStatement(t.assignmentExpression("=", specifier.local, t.memberExpression(t.identifier(target), specifier.imported, imported.type === "StringLiteral")))); | ||
} | ||
@@ -356,18 +349,18 @@ } | ||
for (const node of specifiers.exports) { | ||
if (_core.types.isExportAllDeclaration(node)) { | ||
if (t.isExportAllDeclaration(node)) { | ||
hasExportStar = true; | ||
} else if (_core.types.isExportSpecifier(node)) { | ||
} else if (t.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))); | ||
exportValues.push(t.memberExpression(t.identifier(target), node.local, t.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, t.identifier(exportIdent), exportNames, exportValues, hasExportStar ? t.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(t.stringLiteral(specifiers.key)); | ||
setters.push(t.functionExpression(null, [t.identifier(target)], t.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 = t.stringLiteral(moduleName); | ||
hoistVariables(path, (id, name, hasInit) => { | ||
variableIds.push(id); | ||
@@ -382,6 +375,6 @@ if (!hasInit && name in exportMap) { | ||
if (variableIds.length) { | ||
beforeBody.unshift(_core.types.variableDeclaration("var", variableIds.map(id => _core.types.variableDeclarator(id)))); | ||
beforeBody.unshift(t.variableDeclaration("var", variableIds.map(id => t.variableDeclarator(id)))); | ||
} | ||
if (exportNames.length) { | ||
beforeBody.push(...constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, null, stringSpecifiers)); | ||
beforeBody.push(...constructExportCall(path, t.identifier(exportIdent), exportNames, exportValues, null, stringSpecifiers)); | ||
} | ||
@@ -408,10 +401,10 @@ path.traverse(reassignmentVisitor, { | ||
path.node.body = [buildTemplate({ | ||
SYSTEM_REGISTER: _core.types.memberExpression(_core.types.identifier(systemGlobal), _core.types.identifier("register")), | ||
SYSTEM_REGISTER: t.memberExpression(t.identifier(systemGlobal), t.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: t.arrayExpression(setters), | ||
EXECUTE: t.functionExpression(null, [], t.blockStatement(path.node.body), false, hasTLA), | ||
SOURCES: t.arrayExpression(sources), | ||
EXPORT_IDENTIFIER: t.identifier(exportIdent), | ||
CONTEXT_IDENTIFIER: t.identifier(contextIdent) | ||
})]; | ||
@@ -423,4 +416,3 @@ } | ||
}); | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/plugin-transform-modules-systemjs", | ||
"version": "7.21.4-esm.3", | ||
"version": "7.21.4-esm.4", | ||
"description": "This plugin transforms ES2015 modules to SystemJS", | ||
@@ -16,6 +16,6 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-hoist-variables": "7.21.4-esm.3", | ||
"@babel/helper-module-transforms": "7.21.4-esm.3", | ||
"@babel/helper-plugin-utils": "7.21.4-esm.3", | ||
"@babel/helper-validator-identifier": "7.21.4-esm.3" | ||
"@babel/helper-hoist-variables": "7.21.4-esm.4", | ||
"@babel/helper-module-transforms": "7.21.4-esm.4", | ||
"@babel/helper-plugin-utils": "7.21.4-esm.4", | ||
"@babel/helper-validator-identifier": "7.21.4-esm.4" | ||
}, | ||
@@ -29,4 +29,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "7.21.4-esm.3", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.3", | ||
"@babel/core": "7.21.4-esm.4", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.4", | ||
"@babel/plugin-syntax-dynamic-import": "^7.8.3" | ||
@@ -33,0 +33,0 @@ }, |
Sorry, the diff of this file is not supported yet
6
63038
389
+ Added@babel/code-frame@7.21.4-esm.4(transitive)
+ Added@babel/generator@7.21.4-esm.4(transitive)
+ Added@babel/helper-environment-visitor@7.21.4-esm.4(transitive)
+ Added@babel/helper-function-name@7.21.4-esm.4(transitive)
+ Added@babel/helper-hoist-variables@7.21.4-esm.4(transitive)
+ Added@babel/helper-module-imports@7.21.4-esm.4(transitive)
+ Added@babel/helper-module-transforms@7.21.4-esm.4(transitive)
+ Added@babel/helper-plugin-utils@7.21.4-esm.4(transitive)
+ Added@babel/helper-simple-access@7.21.4-esm.4(transitive)
+ Added@babel/helper-split-export-declaration@7.21.4-esm.4(transitive)
+ Added@babel/helper-string-parser@7.21.4-esm.4(transitive)
+ Added@babel/helper-validator-identifier@7.21.4-esm.4(transitive)
+ Added@babel/highlight@7.21.4-esm.4(transitive)
+ Added@babel/parser@7.21.4-esm.4(transitive)
+ Added@babel/template@7.21.4-esm.4(transitive)
+ Added@babel/traverse@7.21.4-esm.4(transitive)
+ Added@babel/types@7.21.4-esm.4(transitive)
- Removed@babel/code-frame@7.21.4-esm.3(transitive)
- Removed@babel/generator@7.21.4-esm.3(transitive)
- Removed@babel/helper-environment-visitor@7.21.4-esm.3(transitive)
- Removed@babel/helper-function-name@7.21.4-esm.3(transitive)
- Removed@babel/helper-hoist-variables@7.21.4-esm.3(transitive)
- Removed@babel/helper-module-imports@7.21.4-esm.3(transitive)
- Removed@babel/helper-module-transforms@7.21.4-esm.3(transitive)
- Removed@babel/helper-plugin-utils@7.21.4-esm.3(transitive)
- Removed@babel/helper-simple-access@7.21.4-esm.3(transitive)
- Removed@babel/helper-split-export-declaration@7.21.4-esm.3(transitive)
- Removed@babel/helper-string-parser@7.21.4-esm.3(transitive)
- Removed@babel/helper-validator-identifier@7.21.4-esm.3(transitive)
- Removed@babel/highlight@7.21.4-esm.3(transitive)
- Removed@babel/parser@7.21.4-esm.3(transitive)
- Removed@babel/template@7.21.4-esm.3(transitive)
- Removed@babel/traverse@7.21.4-esm.3(transitive)
- Removed@babel/types@7.21.4-esm.3(transitive)