@babel/helper-module-transforms
Advanced tools
Comparing version 7.24.8 to 7.24.9
120
lib/index.js
@@ -55,17 +55,2 @@ "use strict"; | ||
var _getModuleName = require("./get-module-name.js"); | ||
const { | ||
booleanLiteral, | ||
callExpression, | ||
cloneNode, | ||
directive, | ||
directiveLiteral, | ||
expressionStatement, | ||
identifier, | ||
isIdentifier, | ||
memberExpression, | ||
stringLiteral, | ||
valueToNode, | ||
variableDeclaration, | ||
variableDeclarator | ||
} = _core.types; | ||
{ | ||
@@ -109,3 +94,3 @@ exports.getDynamicImportSource = require("./dynamic-import").getDynamicImportSource; | ||
if (!hasStrict) { | ||
path.unshiftContainer("directives", directive(directiveLiteral("use strict"))); | ||
path.unshiftContainer("directives", _core.types.directive(_core.types.directiveLiteral("use strict"))); | ||
} | ||
@@ -138,3 +123,3 @@ } | ||
if (type === "node-namespace") { | ||
return callExpression(programPath.hub.addHelper("interopRequireWildcard"), [expr, booleanLiteral(true)]); | ||
return _core.types.callExpression(programPath.hub.addHelper("interopRequireWildcard"), [expr, _core.types.booleanLiteral(true)]); | ||
} else if (type === "node-default") { | ||
@@ -151,3 +136,3 @@ return null; | ||
} | ||
return callExpression(programPath.hub.addHelper(helper), [expr]); | ||
return _core.types.callExpression(programPath.hub.addHelper(helper), [expr]); | ||
} | ||
@@ -157,3 +142,3 @@ function buildNamespaceInitStatements(metadata, sourceMetadata, constantReexports = false, wrapReference = Lazy.wrapReference) { | ||
const statements = []; | ||
const srcNamespaceId = identifier(sourceMetadata.name); | ||
const srcNamespaceId = _core.types.identifier(sourceMetadata.name); | ||
for (const localName of sourceMetadata.importsNamespace) { | ||
@@ -163,3 +148,3 @@ if (localName === sourceMetadata.name) continue; | ||
NAME: localName, | ||
SOURCE: cloneNode(srcNamespaceId) | ||
SOURCE: _core.types.cloneNode(srcNamespaceId) | ||
})); | ||
@@ -182,7 +167,7 @@ } | ||
NAME: exportName, | ||
NAMESPACE: cloneNode(srcNamespace) | ||
NAMESPACE: _core.types.cloneNode(srcNamespace) | ||
})); | ||
} | ||
if (sourceMetadata.reexportAll) { | ||
const statement = buildNamespaceReexport(metadata, cloneNode(srcNamespace), constantReexports); | ||
const statement = buildNamespaceReexport(metadata, _core.types.cloneNode(srcNamespace), constantReexports); | ||
statement.loc = sourceMetadata.reexportAll.loc; | ||
@@ -194,11 +179,27 @@ statements.push(statement); | ||
const ReexportTemplate = { | ||
constant: _core.template.statement`EXPORTS.EXPORT_NAME = NAMESPACE_IMPORT;`, | ||
constantComputed: _core.template.statement`EXPORTS["EXPORT_NAME"] = NAMESPACE_IMPORT;`, | ||
spec: _core.template.statement` | ||
Object.defineProperty(EXPORTS, "EXPORT_NAME", { | ||
enumerable: true, | ||
get: function() { | ||
return NAMESPACE_IMPORT; | ||
}, | ||
}); | ||
constant: ({ | ||
exports, | ||
exportName, | ||
namespaceImport | ||
}) => _core.template.statement.ast` | ||
${exports}.${exportName} = ${namespaceImport}; | ||
`, | ||
constantComputed: ({ | ||
exports, | ||
exportName, | ||
namespaceImport | ||
}) => _core.template.statement.ast` | ||
${exports}["${exportName}"] = ${namespaceImport}; | ||
`, | ||
spec: ({ | ||
exports, | ||
exportName, | ||
namespaceImport | ||
}) => _core.template.statement.ast` | ||
Object.defineProperty(${exports}, "${exportName}", { | ||
enumerable: true, | ||
get: function() { | ||
return ${namespaceImport}; | ||
}, | ||
}); | ||
` | ||
@@ -208,3 +209,3 @@ }; | ||
var _wrapReference2; | ||
let namespace = identifier(metadata.name); | ||
let namespace = _core.types.identifier(metadata.name); | ||
namespace = (_wrapReference2 = wrapReference(namespace, metadata.wrap)) != null ? _wrapReference2 : namespace; | ||
@@ -215,14 +216,14 @@ const { | ||
return Array.from(metadata.reexports, ([exportName, importName]) => { | ||
let NAMESPACE_IMPORT = cloneNode(namespace); | ||
let namespaceImport = _core.types.cloneNode(namespace); | ||
if (importName === "default" && metadata.interop === "node-default") {} else if (stringSpecifiers.has(importName)) { | ||
NAMESPACE_IMPORT = memberExpression(NAMESPACE_IMPORT, stringLiteral(importName), true); | ||
namespaceImport = _core.types.memberExpression(namespaceImport, _core.types.stringLiteral(importName), true); | ||
} else { | ||
NAMESPACE_IMPORT = memberExpression(NAMESPACE_IMPORT, identifier(importName)); | ||
namespaceImport = _core.types.memberExpression(namespaceImport, _core.types.identifier(importName)); | ||
} | ||
const astNodes = { | ||
EXPORTS: meta.exportName, | ||
EXPORT_NAME: exportName, | ||
NAMESPACE_IMPORT | ||
exports: meta.exportName, | ||
exportName, | ||
namespaceImport | ||
}; | ||
if (constantReexports || isIdentifier(NAMESPACE_IMPORT)) { | ||
if (constantReexports || _core.types.isIdentifier(namespaceImport)) { | ||
if (stringSpecifiers.has(exportName)) { | ||
@@ -303,3 +304,3 @@ return ReexportTemplate.constantComputed(astNodes); | ||
name: name.name, | ||
statement: variableDeclaration("var", [variableDeclarator(name, valueToNode(exportedVars))]) | ||
statement: _core.types.variableDeclaration("var", [_core.types.variableDeclarator(name, _core.types.valueToNode(exportedVars))]) | ||
}; | ||
@@ -311,3 +312,3 @@ } | ||
if (data.kind === "import") {} else if (data.kind === "hoisted") { | ||
initStatements.push([data.names[0], buildInitStatement(metadata, data.names, identifier(localName))]); | ||
initStatements.push([data.names[0], buildInitStatement(metadata, data.names, _core.types.identifier(localName))]); | ||
} else if (!noIncompleteNsImportDetection) { | ||
@@ -367,5 +368,22 @@ for (const exportName of data.names) { | ||
const InitTemplate = { | ||
computed: _core.template.expression`EXPORTS["NAME"] = VALUE`, | ||
default: _core.template.expression`EXPORTS.NAME = VALUE`, | ||
define: _core.template.expression`Object.defineProperty(EXPORTS, "NAME", { enumerable:true, value: void 0, writable: true })["NAME"] = VALUE` | ||
computed: ({ | ||
exports, | ||
name, | ||
value | ||
}) => _core.template.expression.ast`${exports}["${name}"] = ${value}`, | ||
default: ({ | ||
exports, | ||
name, | ||
value | ||
}) => _core.template.expression.ast`${exports}.${name} = ${value}`, | ||
define: ({ | ||
exports, | ||
name, | ||
value | ||
}) => _core.template.expression.ast` | ||
Object.defineProperty(${exports}, "${name}", { | ||
enumerable: true, | ||
value: void 0, | ||
writable: true | ||
})["${name}"] = ${value}` | ||
}; | ||
@@ -375,14 +393,14 @@ function buildInitStatement(metadata, exportNames, initExpr) { | ||
stringSpecifiers, | ||
exportName: EXPORTS | ||
exportName: exports | ||
} = metadata; | ||
return expressionStatement(exportNames.reduce((acc, exportName) => { | ||
return _core.types.expressionStatement(exportNames.reduce((value, name) => { | ||
const params = { | ||
EXPORTS, | ||
NAME: exportName, | ||
VALUE: acc | ||
exports, | ||
name, | ||
value | ||
}; | ||
if (exportName === "__proto__") { | ||
if (name === "__proto__") { | ||
return InitTemplate.define(params); | ||
} | ||
if (stringSpecifiers.has(exportName)) { | ||
if (stringSpecifiers.has(name)) { | ||
return InitTemplate.computed(params); | ||
@@ -389,0 +407,0 @@ } |
@@ -10,23 +10,2 @@ "use strict"; | ||
var _helperSimpleAccess = require("@babel/helper-simple-access"); | ||
const { | ||
assignmentExpression, | ||
cloneNode, | ||
expressionStatement, | ||
getOuterBindingIdentifiers, | ||
identifier, | ||
isArrowFunctionExpression, | ||
isClassExpression, | ||
isFunctionExpression, | ||
isIdentifier, | ||
isMemberExpression, | ||
isVariableDeclaration, | ||
jsxIdentifier, | ||
jsxMemberExpression, | ||
memberExpression, | ||
numericLiteral, | ||
sequenceExpression, | ||
stringLiteral, | ||
variableDeclaration, | ||
variableDeclarator | ||
} = _core.types; | ||
function isInType(path) { | ||
@@ -100,3 +79,3 @@ do { | ||
} | ||
let namespace = identifier(meta.name); | ||
let namespace = _core.types.identifier(meta.name); | ||
if (meta.wrap) { | ||
@@ -110,3 +89,3 @@ var _wrapReference2; | ||
const computed = metadata.stringSpecifiers.has(importName); | ||
return memberExpression(namespace, computed ? stringLiteral(importName) : identifier(importName), computed); | ||
return _core.types.memberExpression(namespace, computed ? _core.types.stringLiteral(importName) : _core.types.identifier(importName), computed); | ||
} | ||
@@ -133,3 +112,3 @@ }; | ||
if (exportNames.length > 0) { | ||
const statement = expressionStatement(buildBindingExportAssignmentExpression(metadata, exportNames, identifier(localName), path.scope)); | ||
const statement = _core.types.expressionStatement(buildBindingExportAssignmentExpression(metadata, exportNames, _core.types.identifier(localName), path.scope)); | ||
statement._blockHoist = path.node._blockHoist; | ||
@@ -153,3 +132,3 @@ requeueInParent(path.insertAfter(statement)[0]); | ||
} = decl.node; | ||
if (isIdentifier(id) && exported.has(id.name) && !isArrowFunctionExpression(init) && (!isFunctionExpression(init) || init.id) && (!isClassExpression(init) || init.id)) { | ||
if (_core.types.isIdentifier(id) && exported.has(id.name) && !_core.types.isArrowFunctionExpression(init) && (!_core.types.isFunctionExpression(init) || init.id) && (!_core.types.isClassExpression(init) || init.id)) { | ||
if (!init) { | ||
@@ -167,3 +146,3 @@ if (isVar) { | ||
if (exported.has(localName)) { | ||
const statement = expressionStatement(buildBindingExportAssignmentExpression(metadata, exported.get(localName), identifier(localName), path.scope)); | ||
const statement = _core.types.expressionStatement(buildBindingExportAssignmentExpression(metadata, exported.get(localName), _core.types.identifier(localName), path.scope)); | ||
statement._blockHoist = path.node._blockHoist; | ||
@@ -189,3 +168,3 @@ requeueInParent(path.insertAfter(statement)[0]); | ||
const computed = stringSpecifiers.has(exportName); | ||
return assignmentExpression("=", memberExpression(identifier(exportsObjectName), computed ? stringLiteral(exportName) : identifier(exportName), computed), expr); | ||
return _core.types.assignmentExpression("=", _core.types.memberExpression(_core.types.identifier(exportsObjectName), computed ? _core.types.stringLiteral(exportName) : _core.types.identifier(exportName), computed), expr); | ||
}, localExpr); | ||
@@ -228,5 +207,5 @@ }; | ||
tag: path.node | ||
})) && isMemberExpression(ref)) { | ||
path.replaceWith(sequenceExpression([numericLiteral(0), ref])); | ||
} else if (path.isJSXIdentifier() && isMemberExpression(ref)) { | ||
})) && _core.types.isMemberExpression(ref)) { | ||
path.replaceWith(_core.types.sequenceExpression([_core.types.numericLiteral(0), ref])); | ||
} else if (path.isJSXIdentifier() && _core.types.isMemberExpression(ref)) { | ||
const { | ||
@@ -236,3 +215,3 @@ object, | ||
} = ref; | ||
path.replaceWith(jsxMemberExpression(jsxIdentifier(object.name), jsxIdentifier(property.name))); | ||
path.replaceWith(_core.types.jsxMemberExpression(_core.types.jsxIdentifier(object.name), _core.types.jsxIdentifier(property.name))); | ||
} else { | ||
@@ -268,8 +247,8 @@ path.replaceWith(ref); | ||
if (importData) { | ||
path.replaceWith(assignmentExpression(update.operator[0] + "=", buildImportReference(importData, arg.node), buildImportThrow(localName))); | ||
path.replaceWith(_core.types.assignmentExpression(update.operator[0] + "=", buildImportReference(importData, arg.node), buildImportThrow(localName))); | ||
} else if (update.prefix) { | ||
path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, cloneNode(update), path.scope)); | ||
path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, _core.types.cloneNode(update), path.scope)); | ||
} else { | ||
const ref = scope.generateDeclaredUidIdentifier(localName); | ||
path.replaceWith(sequenceExpression([assignmentExpression("=", cloneNode(ref), cloneNode(update)), buildBindingExportAssignmentExpression(this.metadata, exportedNames, identifier(localName), path.scope), cloneNode(ref)])); | ||
path.replaceWith(_core.types.sequenceExpression([_core.types.assignmentExpression("=", _core.types.cloneNode(ref), _core.types.cloneNode(update)), buildBindingExportAssignmentExpression(this.metadata, exportedNames, _core.types.identifier(localName), path.scope), _core.types.cloneNode(ref)])); | ||
} | ||
@@ -307,3 +286,3 @@ } | ||
assignment.left = buildImportReference(importData, left.node); | ||
assignment.right = sequenceExpression([assignment.right, buildImportThrow(localName)]); | ||
assignment.right = _core.types.sequenceExpression([assignment.right, buildImportThrow(localName)]); | ||
} | ||
@@ -318,3 +297,3 @@ path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, assignment, path.scope)); | ||
if (id) { | ||
path.node.right = sequenceExpression([path.node.right, buildImportThrow(id)]); | ||
path.node.right = _core.types.sequenceExpression([path.node.right, buildImportThrow(id)]); | ||
} | ||
@@ -325,9 +304,9 @@ const items = []; | ||
if (exportedNames.length > 0) { | ||
items.push(buildBindingExportAssignmentExpression(this.metadata, exportedNames, identifier(localName), path.scope)); | ||
items.push(buildBindingExportAssignmentExpression(this.metadata, exportedNames, _core.types.identifier(localName), path.scope)); | ||
} | ||
}); | ||
if (items.length > 0) { | ||
let node = sequenceExpression(items); | ||
let node = _core.types.sequenceExpression(items); | ||
if (path.parentPath.isExpressionStatement()) { | ||
node = expressionStatement(node); | ||
node = _core.types.expressionStatement(node); | ||
node._blockHoist = path.parentPath.node._blockHoist; | ||
@@ -354,7 +333,7 @@ } | ||
} = this; | ||
if (!isVariableDeclaration(left)) { | ||
if (!_core.types.isVariableDeclaration(left)) { | ||
let didTransformExport = false, | ||
importConstViolationName; | ||
const loopBodyScope = path.get("body").scope; | ||
for (const name of Object.keys(getOuterBindingIdentifiers(left))) { | ||
for (const name of Object.keys(_core.types.getOuterBindingIdentifiers(left))) { | ||
if (programScope.getBinding(name) === scope.getBinding(name)) { | ||
@@ -378,9 +357,9 @@ if (exported.has(name)) { | ||
const newLoopId = scope.generateUidIdentifierBasedOnNode(left); | ||
path.get("left").replaceWith(variableDeclaration("let", [variableDeclarator(cloneNode(newLoopId))])); | ||
path.get("left").replaceWith(_core.types.variableDeclaration("let", [_core.types.variableDeclarator(_core.types.cloneNode(newLoopId))])); | ||
scope.registerDeclaration(path.get("left")); | ||
if (didTransformExport) { | ||
bodyPath.unshiftContainer("body", expressionStatement(assignmentExpression("=", left, newLoopId))); | ||
bodyPath.unshiftContainer("body", _core.types.expressionStatement(_core.types.assignmentExpression("=", left, newLoopId))); | ||
} | ||
if (importConstViolationName) { | ||
bodyPath.unshiftContainer("body", expressionStatement(buildImportThrow(importConstViolationName))); | ||
bodyPath.unshiftContainer("body", _core.types.expressionStatement(buildImportThrow(importConstViolationName))); | ||
} | ||
@@ -387,0 +366,0 @@ } |
@@ -13,13 +13,15 @@ "use strict"; | ||
} = _core.types; | ||
const rewriteThisVisitor = _core.traverse.visitors.merge([_helperEnvironmentVisitor.default, { | ||
ThisExpression(path) { | ||
path.replaceWith(unaryExpression("void", numericLiteral(0), true)); | ||
let rewriteThisVisitor; | ||
function rewriteThis(programPath) { | ||
if (!rewriteThisVisitor) { | ||
rewriteThisVisitor = _core.traverse.visitors.merge([_helperEnvironmentVisitor.default, { | ||
ThisExpression(path) { | ||
path.replaceWith(unaryExpression("void", numericLiteral(0), true)); | ||
} | ||
}]); | ||
rewriteThisVisitor.noScope = true; | ||
} | ||
}]); | ||
function rewriteThis(programPath) { | ||
(0, _core.traverse)(programPath.node, Object.assign({}, rewriteThisVisitor, { | ||
noScope: true | ||
})); | ||
(0, _core.traverse)(programPath.node, rewriteThisVisitor); | ||
} | ||
//# sourceMappingURL=rewrite-this.js.map |
{ | ||
"name": "@babel/helper-module-transforms", | ||
"version": "7.24.8", | ||
"version": "7.24.9", | ||
"description": "Babel helper functions for implementing ES6 module transformations", | ||
@@ -25,3 +25,3 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"devDependencies": { | ||
"@babel/core": "^7.24.8" | ||
"@babel/core": "^7.24.9" | ||
}, | ||
@@ -28,0 +28,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
159712
20