From efbc2ffe6a1ee5ec38a4396305561d6515d0943e Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 30 Aug 2024 17:21:18 +0800 Subject: node fixes, updates --- .../lib/rewrite-live-references.js | 67 ++++++++-------------- 1 file changed, 23 insertions(+), 44 deletions(-) (limited to 'node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js') diff --git a/node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js b/node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js index 6ada457a..d856a197 100644 --- a/node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js +++ b/node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js @@ -7,27 +7,6 @@ exports.default = rewriteLiveReferences; var _assert = require("assert"); var _core = require("@babel/core"); 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) { do { switch (path.parent.type) { @@ -96,7 +75,7 @@ function rewriteLiveReferences(programPath, metadata, wrapReference) { } return identNode; } - let namespace = identifier(meta.name); + let namespace = _core.types.identifier(meta.name); if (meta.wrap) { var _wrapReference2; namespace = (_wrapReference2 = wrapReference(namespace, meta.wrap)) != null ? _wrapReference2 : namespace; @@ -105,7 +84,7 @@ function rewriteLiveReferences(programPath, metadata, wrapReference) { return namespace; } 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); } }; programPath.traverse(rewriteReferencesVisitor, rewriteReferencesVisitorState); @@ -127,7 +106,7 @@ const rewriteBindingInitVisitor = { const localName = id.name; const exportNames = exported.get(localName) || []; 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; requeueInParent(path.insertAfter(statement)[0]); } @@ -146,7 +125,7 @@ const rewriteBindingInitVisitor = { let { init } = 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) { if (isVar) { continue; @@ -159,7 +138,7 @@ const rewriteBindingInitVisitor = { } else { for (const localName of Object.keys(decl.getOuterBindingIdentifiers())) { 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; requeueInParent(path.insertAfter(statement)[0]); } @@ -180,7 +159,7 @@ const buildBindingExportAssignmentExpression = (metadata, exportNames, localExpr stringSpecifiers } = metadata; 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); }; const buildImportThrow = localName => { @@ -218,14 +197,14 @@ const rewriteReferencesVisitor = { callee: path.node }) || path.parentPath.isTaggedTemplateExpression({ 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 { object, property } = 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 { path.replaceWith(ref); } @@ -256,12 +235,12 @@ const rewriteReferencesVisitor = { const importData = imported.get(localName); if ((exportedNames == null ? void 0 : exportedNames.length) > 0 || importData) { 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)])); } } } @@ -294,7 +273,7 @@ const rewriteReferencesVisitor = { const assignment = path.node; if (importData) { assignment.left = buildImportReference(importData, left.node); - assignment.right = sequenceExpression([assignment.right, buildImportThrow(localName)]); + assignment.right = _core.types.sequenceExpression([assignment.right, buildImportThrow(localName)]); } path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, assignment, path.scope)); requeueInParent(path); @@ -304,19 +283,19 @@ const rewriteReferencesVisitor = { const programScopeIds = Object.keys(ids).filter(localName => scope.getBinding(localName) === path.scope.getBinding(localName)); const id = programScopeIds.find(localName => imported.has(localName)); if (id) { - path.node.right = sequenceExpression([path.node.right, buildImportThrow(id)]); + path.node.right = _core.types.sequenceExpression([path.node.right, buildImportThrow(id)]); } const items = []; programScopeIds.forEach(localName => { const exportedNames = exported.get(localName) || []; 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; } const statement = path.insertAfter(node)[0]; @@ -338,11 +317,11 @@ const rewriteReferencesVisitor = { imported, scope: programScope } = 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)) { if (exported.has(name)) { didTransformExport = true; @@ -361,13 +340,13 @@ const rewriteReferencesVisitor = { path.ensureBlock(); const bodyPath = path.get("body"); 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))); } } } -- cgit v1.2.3