@babel/traverse 7.18.13 → 7.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @babel/traverse might be problematic. Click here for more details.

Files changed (64) hide show
  1. package/lib/cache.js +3 -1
  2. package/lib/cache.js.map +1 -0
  3. package/lib/context.js +3 -1
  4. package/lib/context.js.map +1 -0
  5. package/lib/hub.js +3 -1
  6. package/lib/hub.js.map +1 -0
  7. package/lib/index.js +3 -1
  8. package/lib/index.js.map +1 -0
  9. package/lib/path/ancestry.js +3 -3
  10. package/lib/path/ancestry.js.map +1 -0
  11. package/lib/path/comments.js +3 -1
  12. package/lib/path/comments.js.map +1 -0
  13. package/lib/path/context.js +3 -1
  14. package/lib/path/context.js.map +1 -0
  15. package/lib/path/conversion.js +3 -1
  16. package/lib/path/conversion.js.map +1 -0
  17. package/lib/path/evaluation.js +8 -6
  18. package/lib/path/evaluation.js.map +1 -0
  19. package/lib/path/family.js +3 -1
  20. package/lib/path/family.js.map +1 -0
  21. package/lib/path/generated/asserts.js +1 -3
  22. package/lib/path/generated/asserts.js.map +1 -0
  23. package/lib/path/generated/validators.js +3 -0
  24. package/lib/path/generated/validators.js.map +1 -0
  25. package/lib/path/index.js +3 -1
  26. package/lib/path/index.js.map +1 -0
  27. package/lib/path/inference/index.js +3 -1
  28. package/lib/path/inference/index.js.map +1 -0
  29. package/lib/path/inference/inferer-reference.js +3 -1
  30. package/lib/path/inference/inferer-reference.js.map +1 -0
  31. package/lib/path/inference/inferers.js +3 -1
  32. package/lib/path/inference/inferers.js.map +1 -0
  33. package/lib/path/inference/util.js +3 -1
  34. package/lib/path/inference/util.js.map +1 -0
  35. package/lib/path/introspection.js +3 -1
  36. package/lib/path/introspection.js.map +1 -0
  37. package/lib/path/lib/hoister.js +3 -1
  38. package/lib/path/lib/hoister.js.map +1 -0
  39. package/lib/path/lib/removal-hooks.js +3 -4
  40. package/lib/path/lib/removal-hooks.js.map +1 -0
  41. package/lib/path/lib/virtual-types-validator.js +3 -1
  42. package/lib/path/lib/virtual-types-validator.js.map +1 -0
  43. package/lib/path/lib/virtual-types.js +3 -1
  44. package/lib/path/lib/virtual-types.js.map +1 -0
  45. package/lib/path/modification.js +3 -1
  46. package/lib/path/modification.js.map +1 -0
  47. package/lib/path/removal.js +3 -1
  48. package/lib/path/removal.js.map +1 -0
  49. package/lib/path/replacement.js +3 -1
  50. package/lib/path/replacement.js.map +1 -0
  51. package/lib/scope/binding.js +3 -1
  52. package/lib/scope/binding.js.map +1 -0
  53. package/lib/scope/index.js +3 -1
  54. package/lib/scope/index.js.map +1 -0
  55. package/lib/scope/lib/renamer.js +3 -3
  56. package/lib/scope/lib/renamer.js.map +1 -0
  57. package/lib/traverse-node.js +3 -1
  58. package/lib/traverse-node.js.map +1 -0
  59. package/lib/types.js +2 -2
  60. package/lib/types.js.map +1 -0
  61. package/lib/visitors.js +3 -1
  62. package/lib/visitors.js.map +1 -0
  63. package/package.json +5 -5
  64. package/scripts/generators/asserts.js +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"names":["arrowFunctionExpression","assertExpression","assignmentExpression","blockStatement","callExpression","cloneNode","expressionStatement","isAssignmentExpression","isCallExpression","isExpression","isIdentifier","isSequenceExpression","isSuper","thisExpression","insertBefore","nodes_","_assertUnremoved","nodes","_verifyNodeList","parentPath","isExpressionStatement","isLabeledStatement","isExportNamedDeclaration","isExportDefaultDeclaration","isDeclaration","isNodeType","isJSXElement","isForStatement","key","node","push","replaceExpressionWithStatements","Array","isArray","container","_containerInsertBefore","isStatementOrBlock","shouldInsertCurrentNode","expression","replaceWith","unshiftContainer","Error","_containerInsert","from","updateSiblingKeys","length","paths","splice","i","to","path","getSibling","context","queue","pushContext","contexts","_getQueueContexts","setScope","debug","maybeQueue","_containerInsertAfter","last","arr","isHiddenInSequenceExpression","parent","expressions","isAlmostConstantAssignment","scope","left","blockScope","getBlockParent","hasOwnBinding","name","getOwnBinding","constantViolations","insertAfter","get","map","isPattern","unshift","callee","isPure","isMethod","computed","temp","generateDeclaredUidIdentifier","pushContainer","fromIndex","incrementBy","pathCache","msg","type","NodePath","listKey","setContext","verifiedNodes","replaceWithMultiple","hoist","hoister","PathHoister","run"],"sources":["../../src/path/modification.ts"],"sourcesContent":["// This file contains methods that modify the path/node in some ways.\n\nimport { path as pathCache } from \"../cache\";\nimport PathHoister from \"./lib/hoister\";\nimport NodePath from \"./index\";\nimport {\n arrowFunctionExpression,\n assertExpression,\n assignmentExpression,\n blockStatement,\n callExpression,\n cloneNode,\n expressionStatement,\n isAssignmentExpression,\n isCallExpression,\n isExpression,\n isIdentifier,\n isSequenceExpression,\n isSuper,\n thisExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"../scope\";\n\n/**\n * Insert the provided nodes before the current one.\n */\n\nexport function insertBefore(\n this: NodePath,\n nodes_: t.Node | t.Node[],\n): NodePath[] {\n this._assertUnremoved();\n\n const nodes = this._verifyNodeList(nodes_);\n\n const { parentPath } = this;\n\n if (\n parentPath.isExpressionStatement() ||\n parentPath.isLabeledStatement() ||\n parentPath.isExportNamedDeclaration() ||\n (parentPath.isExportDefaultDeclaration() && this.isDeclaration())\n ) {\n return parentPath.insertBefore(nodes);\n } else if (\n (this.isNodeType(\"Expression\") && !this.isJSXElement()) ||\n (parentPath.isForStatement() && this.key === \"init\")\n ) {\n if (this.node) nodes.push(this.node);\n // @ts-expect-error todo(flow->ts): check that nodes is an array of statements\n return this.replaceExpressionWithStatements(nodes);\n } else if (Array.isArray(this.container)) {\n return this._containerInsertBefore(nodes);\n } else if (this.isStatementOrBlock()) {\n const node = this.node as t.Statement;\n const shouldInsertCurrentNode =\n node &&\n (!this.isExpressionStatement() ||\n (node as t.ExpressionStatement).expression != null);\n\n this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));\n return (this as NodePath<t.BlockStatement>).unshiftContainer(\n \"body\",\n // @ts-expect-error Fixme: refine nodes to t.BlockStatement[\"body\"] when this is a BlockStatement path\n nodes,\n );\n } else {\n throw new Error(\n \"We don't know what to do with this node type. \" +\n \"We were previously a Statement but we can't fit in here?\",\n );\n }\n}\n\nexport function _containerInsert<N extends t.Node>(\n this: NodePath,\n from: number,\n nodes: N[],\n): NodePath<N>[] {\n this.updateSiblingKeys(from, nodes.length);\n\n const paths: NodePath<N>[] = [];\n\n // @ts-expect-error todo(flow->ts): this.container could be a NodePath\n this.container.splice(from, 0, ...nodes);\n for (let i = 0; i < nodes.length; i++) {\n const to = from + i;\n const path = this.getSibling(to) as NodePath<N>;\n paths.push(path);\n\n if (this.context && this.context.queue) {\n path.pushContext(this.context);\n }\n }\n\n const contexts = this._getQueueContexts();\n\n for (const path of paths) {\n path.setScope();\n path.debug(\"Inserted.\");\n\n for (const context of contexts) {\n context.maybeQueue(path, true);\n }\n }\n\n return paths;\n}\n\nexport function _containerInsertBefore<N extends t.Node>(\n this: NodePath,\n nodes: N[],\n) {\n return this._containerInsert(this.key as number, nodes);\n}\n\nexport function _containerInsertAfter<N extends t.Node>(\n this: NodePath,\n nodes: N[],\n) {\n return this._containerInsert((this.key as number) + 1, nodes);\n}\n\nconst last = <T>(arr: T[]) => arr[arr.length - 1];\n\nfunction isHiddenInSequenceExpression(path: NodePath): boolean {\n return (\n isSequenceExpression(path.parent) &&\n (last(path.parent.expressions) !== path.node ||\n isHiddenInSequenceExpression(path.parentPath))\n );\n}\n\nfunction isAlmostConstantAssignment(\n node: t.Node,\n scope: Scope,\n): node is t.AssignmentExpression & { left: t.Identifier } {\n if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {\n return false;\n }\n\n // Not every scope can contain variables. For example, we might be in\n // a ClassScope either in the ClassHeritage or in a computed key.\n const blockScope = scope.getBlockParent();\n\n // If the variable is defined in the current scope and only assigned here,\n // we can be sure that its value won't change.\n return (\n blockScope.hasOwnBinding(node.left.name) &&\n blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1\n );\n}\n\n/**\n * Insert the provided nodes after the current one. When inserting nodes after an\n * expression, ensure that the completion record is correct by pushing the current node.\n */\n\nexport function insertAfter(\n this: NodePath,\n nodes_: t.Node | t.Node[],\n): NodePath[] {\n this._assertUnremoved();\n\n if (this.isSequenceExpression()) {\n return last(this.get(\"expressions\")).insertAfter(nodes_);\n }\n\n const nodes = this._verifyNodeList(nodes_);\n\n const { parentPath } = this;\n if (\n parentPath.isExpressionStatement() ||\n parentPath.isLabeledStatement() ||\n parentPath.isExportNamedDeclaration() ||\n (parentPath.isExportDefaultDeclaration() && this.isDeclaration())\n ) {\n return parentPath.insertAfter(\n nodes.map(node => {\n // Usually after an expression we can safely insert another expression:\n // A.insertAfter(B)\n // foo = A; -> foo = (A, B);\n // If A is an expression statement, it isn't safe anymore so we need to\n // convert B to an expression statement\n // A; -> A; B // No semicolon! It could break if followed by [!\n return isExpression(node) ? expressionStatement(node) : node;\n }),\n );\n } else if (\n (this.isNodeType(\"Expression\") &&\n !this.isJSXElement() &&\n !parentPath.isJSXElement()) ||\n (parentPath.isForStatement() && this.key === \"init\")\n ) {\n if (this.node) {\n const node = this.node as t.Expression | t.VariableDeclaration;\n let { scope } = this;\n\n if (scope.path.isPattern()) {\n assertExpression(node);\n\n this.replaceWith(callExpression(arrowFunctionExpression([], node), []));\n (this.get(\"callee.body\") as NodePath<t.Expression>).insertAfter(nodes);\n return [this];\n }\n\n if (isHiddenInSequenceExpression(this)) {\n nodes.unshift(node);\n }\n // We need to preserve the value of this expression.\n else if (isCallExpression(node) && isSuper(node.callee)) {\n nodes.unshift(node);\n // `super(...)` always evaluates to `this`.\n nodes.push(thisExpression());\n } else if (isAlmostConstantAssignment(node, scope)) {\n nodes.unshift(node);\n nodes.push(cloneNode(node.left));\n } else if (scope.isPure(node, true)) {\n // Insert the nodes before rather than after; it's not observable.\n nodes.push(node);\n } else {\n // Inserting after the computed key of a method should insert the\n // temporary binding in the method's parent's scope.\n if (parentPath.isMethod({ computed: true, key: node })) {\n scope = scope.parent;\n }\n const temp = scope.generateDeclaredUidIdentifier();\n nodes.unshift(\n expressionStatement(\n // @ts-expect-error todo(flow->ts): This can be a variable\n // declaraion in the \"init\" of a for statement, but that's\n // invalid here.\n assignmentExpression(\"=\", cloneNode(temp), node),\n ),\n );\n nodes.push(expressionStatement(cloneNode(temp)));\n }\n }\n // @ts-expect-error todo(flow->ts): check that nodes is an array of statements\n return this.replaceExpressionWithStatements(nodes);\n } else if (Array.isArray(this.container)) {\n return this._containerInsertAfter(nodes);\n } else if (this.isStatementOrBlock()) {\n const node = this.node as t.Statement;\n const shouldInsertCurrentNode =\n node &&\n (!this.isExpressionStatement() ||\n (node as t.ExpressionStatement).expression != null);\n\n this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));\n // @ts-expect-error Fixme: refine nodes to t.BlockStatement[\"body\"] when this is a BlockStatement path\n return this.pushContainer(\"body\", nodes);\n } else {\n throw new Error(\n \"We don't know what to do with this node type. \" +\n \"We were previously a Statement but we can't fit in here?\",\n );\n }\n}\n\n/**\n * Update all sibling node paths after `fromIndex` by `incrementBy`.\n */\n\nexport function updateSiblingKeys(\n this: NodePath,\n fromIndex: number,\n incrementBy: number,\n) {\n if (!this.parent) return;\n\n const paths = pathCache.get(this.parent);\n for (const [, path] of paths) {\n if (path.key >= fromIndex) {\n path.key += incrementBy;\n }\n }\n}\n\nexport function _verifyNodeList<N extends t.Node>(\n this: NodePath,\n nodes: N | N[],\n): N[] {\n if (!nodes) {\n return [];\n }\n\n if (!Array.isArray(nodes)) {\n nodes = [nodes];\n }\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n let msg;\n\n if (!node) {\n msg = \"has falsy node\";\n } else if (typeof node !== \"object\") {\n msg = \"contains a non-object node\";\n } else if (!node.type) {\n msg = \"without a type\";\n } else if (node instanceof NodePath) {\n msg = \"has a NodePath when it expected a raw object\";\n }\n\n if (msg) {\n const type = Array.isArray(node) ? \"array\" : typeof node;\n throw new Error(\n `Node list ${msg} with the index of ${i} and type of ${type}`,\n );\n }\n }\n\n return nodes;\n}\n\nexport function unshiftContainer<N extends t.Node, K extends keyof N & string>(\n this: NodePath<N>,\n listKey: K,\n nodes: N[K] extends (infer E)[]\n ? E | E[]\n : // todo: refine to t.Node[]\n // ? E extends t.Node\n // ? E | E[]\n // : never\n never,\n) {\n // todo: NodePaths<Nodes>\n this._assertUnremoved();\n\n // @ts-expect-error fixme\n nodes = this._verifyNodeList(nodes);\n\n // get the first path and insert our nodes before it, if it doesn't exist then it\n // doesn't matter, our nodes will be inserted anyway\n const path = NodePath.get({\n parentPath: this,\n parent: this.node,\n container: this.node[listKey] as unknown as t.Node | t.Node[],\n listKey,\n key: 0,\n }).setContext(this.context);\n\n return path._containerInsertBefore(\n // @ts-expect-error typings needed to narrow down nodes as t.Node[]\n nodes,\n );\n}\n\nexport function pushContainer<N extends t.Node, K extends keyof N & string>(\n this: NodePath<N>,\n listKey: K,\n nodes: N[K] extends (infer E)[]\n ? E | E[]\n : // todo: refine to t.Node[]\n // ? E extends t.Node\n // ? E | E[]\n // : never\n never,\n) {\n this._assertUnremoved();\n\n const verifiedNodes = this._verifyNodeList(\n // @ts-expect-error refine typings\n nodes,\n );\n\n // get an invisible path that represents the last node + 1 and replace it with our\n // nodes, effectively inlining it\n\n const container = this.node[listKey];\n const path = NodePath.get({\n parentPath: this,\n parent: this.node,\n container: container as unknown as t.Node | t.Node[],\n listKey,\n // @ts-expect-error TS cannot infer that container is t.Node[]\n key: container.length,\n }).setContext(this.context);\n\n return path.replaceWithMultiple(verifiedNodes);\n}\n\n/**\n * Hoist the current node to the highest scope possible and return a UID\n * referencing it.\n */\nexport function hoist<T extends t.Node>(\n this: NodePath<T>,\n scope: Scope = this.scope,\n) {\n const hoister = new PathHoister<T>(this, scope);\n return hoister.run();\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAEA;;AACA;;AACA;;AACA;;;EACEA,uB;EACAC,gB;EACAC,oB;EACAC,c;EACAC,c;EACAC,S;EACAC,mB;EACAC,sB;EACAC,g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w this.buildCodeFrameError("NodePath has been removed so is read-only.");
72
72
  }
73
- }
73
+ }
74
+
75
+ //# sourceMappingURL=removal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["remove","_assertUnremoved","resync","opts","noScope","_removeFromScope","_callRemovalHooks","_markRemoved","shareCommentsWithSiblings","_remove","bindings","getBindingIdentifiers","Object","keys","forEach","name","scope","removeBinding","fn","hooks","parentPath","Array","isArray","container","splice","key","updateSiblingKeys","_replaceWith","_traverseFlags","SHOULD_SKIP","REMOVED","parent","pathCache","get","delete","node","removed","buildCodeFrameError"],"sources":["../../src/path/removal.ts"],"sourcesContent":["// This file contains methods responsible for removing a node.\n\nimport { hooks } from \"./lib/removal-hooks\";\nimport { path as pathCache } from \"../cache\";\nimport type NodePath from \"./index\";\nimport { REMOVED, SHOULD_SKIP } from \"./index\";\n\nexport function remove(this: NodePath) {\n this._assertUnremoved();\n\n this.resync();\n if (!this.opts?.noScope) {\n this._removeFromScope();\n }\n\n if (this._callRemovalHooks()) {\n this._markRemoved();\n return;\n }\n\n this.shareCommentsWithSiblings();\n this._remove();\n this._markRemoved();\n}\n\nexport function _removeFromScope(this: NodePath) {\n const bindings = this.getBindingIdentifiers();\n Object.keys(bindings).forEach(name => this.scope.removeBinding(name));\n}\n\nexport function _callRemovalHooks(this: NodePath) {\n for (const fn of hooks) {\n if (fn(this, this.parentPath)) return true;\n }\n}\n\nexport function _remove(this: NodePath) {\n if (Array.isArray(this.container)) {\n this.container.splice(this.key as number, 1);\n this.updateSiblingKeys(this.key as number, -1);\n } else {\n this._replaceWith(null);\n }\n}\n\nexport function _markRemoved(this: NodePath) {\n // this.shouldSkip = true; this.removed = true;\n this._traverseFlags |= SHOULD_SKIP | REMOVED;\n if (this.parent) pathCache.get(this.parent).delete(this.node);\n this.node = null;\n}\n\nexport function _assertUnremoved(this: NodePath) {\n if (this.removed) {\n throw this.buildCodeFrameError(\n \"NodePath has been removed so is read-only.\",\n );\n }\n}\n"],"mappings":";;;;;;;;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EAC/C,IAAI,KAAKmC,OAAT,EAAkB;IAChB,MAAM,KAAKC,mBAAL,CACJ,4CADI,CAAN;EAGD;AACF"}
@@ -256,4 +256,6 @@ function replaceInline(nodes) {
256
256
  } else {
257
257
  return this.replaceWith(nodes);
258
258
  }
259
- }
259
+ }
260
+
261
+ //# sourceMappingURL=replacement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FUNCTION_TYPES","arrowFunctionExpression","assignmentExpression","awaitExpression","blockStatement","callExpression","cloneNode","expressionStatement","identifier","inheritLeadingComments","inheritTrailingComments","inheritsComments","isExpression","isProgram","isStatement","removeComments","returnStatement","toSequenceExpression","validate","yieldExpression","replaceWithMultiple","nodes","resync","_verifyNodeList","node","length","pathCache","get","parent","delete","container","key","paths","insertAfter","requeue","remove","replaceWithSourceString","replacement","ast","parse","err","loc","message","codeFrameColumns","start","line","column","code","expressionAST","program","body","expression","traverse","removeProperties","replaceWith","replacementPath","removed","Error","NodePath","Array","isArray","nodePath","isNodeType","canHaveVariableDeclarationOrExpression","canSwapBetweenExpressionAndStatement","parentPath","isExportDefaultDeclaration","replaceExpressionWithStatements","oldNode","_replaceWith","type","setScope","ReferenceError","inList","debug","set","nodesAsSequenceExpression","scope","functionParent","getFunctionParent","isParentAsync","is","isParentGenerator","callee","hoistVariables","id","push","completionRecords","getCompletionRecords","path","isExpressionStatement","loop","findParent","isLoop","uid","getData","generateDeclaredUidIdentifier","pushContainer","setData","name","arrowFunctionToExpression","newCallee","needToAwaitFunction","hasType","needToYieldFunction","replaceInline","_containerInsertAfter"],"sources":["../../src/path/replacement.ts"],"sourcesContent":["// This file contains methods responsible for replacing a node with another.\n\nimport { codeFrameColumns } from \"@babel/code-frame\";\nimport traverse from \"../index\";\nimport NodePath from \"./index\";\nimport { path as pathCache } from \"../cache\";\nimport { parse } from \"@babel/parser\";\nimport {\n FUNCTION_TYPES,\n arrowFunctionExpression,\n assignmentExpression,\n awaitExpression,\n blockStatement,\n callExpression,\n cloneNode,\n expressionStatement,\n identifier,\n inheritLeadingComments,\n inheritTrailingComments,\n inheritsComments,\n isExpression,\n isProgram,\n isStatement,\n removeComments,\n returnStatement,\n toSequenceExpression,\n validate,\n yieldExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport hoistVariables from \"@babel/helper-hoist-variables\";\n\n/**\n * Replace a node with an array of multiple. This method performs the following steps:\n *\n * - Inherit the comments of first provided node with that of the current node.\n * - Insert the provided nodes after the current node.\n * - Remove the current node.\n */\n\nexport function replaceWithMultiple(\n this: NodePath,\n nodes: t.Node | t.Node[],\n): NodePath[] {\n this.resync();\n\n nodes = this._verifyNodeList(nodes);\n inheritLeadingComments(nodes[0], this.node);\n inheritTrailingComments(nodes[nodes.length - 1], this.node);\n pathCache.get(this.parent)?.delete(this.node);\n this.node =\n // @ts-expect-error this.key must present in this.container\n this.container[this.key] = null;\n const paths = this.insertAfter(nodes);\n\n if (this.node) {\n this.requeue();\n } else {\n this.remove();\n }\n return paths;\n}\n\n/**\n * Parse a string as an expression and replace the current node with the result.\n *\n * NOTE: This is typically not a good idea to use. Building source strings when\n * transforming ASTs is an antipattern and SHOULD NOT be encouraged. Even if it's\n * easier to use, your transforms will be extremely brittle.\n */\n\nexport function replaceWithSourceString(this: NodePath, replacement: string) {\n this.resync();\n let ast: t.File;\n\n try {\n replacement = `(${replacement})`;\n // @ts-expect-error todo: use babel-types ast typings in Babel parser\n ast = parse(replacement);\n } catch (err) {\n const loc = err.loc;\n if (loc) {\n err.message +=\n \" - make sure this is an expression.\\n\" +\n codeFrameColumns(replacement, {\n start: {\n line: loc.line,\n column: loc.column + 1,\n },\n });\n err.code = \"BABEL_REPLACE_SOURCE_ERROR\";\n }\n throw err;\n }\n\n const expressionAST = (ast.program.body[0] as t.ExpressionStatement)\n .expression;\n traverse.removeProperties(expressionAST);\n return this.replaceWith(expressionAST);\n}\n\n/**\n * Replace the current node with another.\n */\n\nexport function replaceWith<R extends t.Node>(\n this: NodePath,\n replacementPath: R | NodePath<R>,\n): [NodePath<R>] {\n this.resync();\n\n if (this.removed) {\n throw new Error(\"You can't replace this node, we've already removed it\");\n }\n\n let replacement: t.Node =\n replacementPath instanceof NodePath\n ? replacementPath.node\n : replacementPath;\n\n if (!replacement) {\n throw new Error(\n \"You passed `path.replaceWith()` a falsy node, use `path.remove()` instead\",\n );\n }\n\n if (this.node === replacement) {\n return [this as NodePath<R>];\n }\n\n if (this.isProgram() && !isProgram(replacement)) {\n throw new Error(\n \"You can only replace a Program root node with another Program node\",\n );\n }\n\n if (Array.isArray(replacement)) {\n throw new Error(\n \"Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`\",\n );\n }\n\n if (typeof replacement === \"string\") {\n throw new Error(\n \"Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`\",\n );\n }\n\n let nodePath = \"\";\n\n if (this.isNodeType(\"Statement\") && isExpression(replacement)) {\n if (\n !this.canHaveVariableDeclarationOrExpression() &&\n !this.canSwapBetweenExpressionAndStatement(replacement) &&\n !this.parentPath.isExportDefaultDeclaration()\n ) {\n // replacing a statement with an expression so wrap it in an expression statement\n replacement = expressionStatement(replacement);\n nodePath = \"expression\";\n }\n }\n\n if (this.isNodeType(\"Expression\") && isStatement(replacement)) {\n if (\n !this.canHaveVariableDeclarationOrExpression() &&\n !this.canSwapBetweenExpressionAndStatement(replacement)\n ) {\n // replacing an expression with a statement so let's explode it\n return this.replaceExpressionWithStatements([replacement]) as [\n NodePath<R>,\n ];\n }\n }\n\n const oldNode = this.node;\n if (oldNode) {\n inheritsComments(replacement, oldNode);\n removeComments(oldNode);\n }\n\n // replace the node\n this._replaceWith(replacement);\n this.type = replacement.type;\n\n // potentially create new scope\n this.setScope();\n\n // requeue for visiting\n this.requeue();\n\n return [\n nodePath ? (this.get(nodePath) as NodePath<R>) : (this as NodePath<R>),\n ];\n}\n\n/**\n * Description\n */\n\nexport function _replaceWith(this: NodePath, node: t.Node) {\n if (!this.container) {\n throw new ReferenceError(\"Container is falsy\");\n }\n\n if (this.inList) {\n // @ts-expect-error todo(flow->ts): check if validate accepts a numeric key\n validate(this.parent, this.key, [node]);\n } else {\n validate(this.parent, this.key as string, node);\n }\n\n this.debug(`Replace with ${node?.type}`);\n pathCache.get(this.parent)?.set(node, this).delete(this.node);\n\n this.node =\n // @ts-expect-error this.key must present in this.container\n this.container[this.key] = node;\n}\n\n/**\n * This method takes an array of statements nodes and then explodes it\n * into expressions. This method retains completion records which is\n * extremely important to retain original semantics.\n */\n\nexport function replaceExpressionWithStatements(\n this: NodePath,\n nodes: Array<t.Statement>,\n) {\n this.resync();\n\n const nodesAsSequenceExpression = toSequenceExpression(nodes, this.scope);\n\n if (nodesAsSequenceExpression) {\n return this.replaceWith(nodesAsSequenceExpression)[0].get(\"expressions\");\n }\n\n const functionParent = this.getFunctionParent();\n const isParentAsync = functionParent?.is(\"async\");\n const isParentGenerator = functionParent?.is(\"generator\");\n\n const container = arrowFunctionExpression([], blockStatement(nodes));\n\n this.replaceWith(callExpression(container, []));\n // replaceWith changes the type of \"this\", but it isn't trackable by TS\n type ThisType = NodePath<\n t.CallExpression & {\n callee: t.ArrowFunctionExpression & { body: t.BlockStatement };\n }\n >;\n\n // hoist variable declaration in do block\n // `(do { var x = 1; x;})` -> `var x; (() => { x = 1; return x; })()`\n const callee = (this as ThisType).get(\"callee\");\n hoistVariables(\n callee.get(\"body\"),\n (id: t.Identifier) => {\n this.scope.push({ id });\n },\n \"var\",\n );\n\n // add implicit returns to all ending expression statements\n const completionRecords: Array<NodePath> = (this as ThisType)\n .get(\"callee\")\n .getCompletionRecords();\n for (const path of completionRecords) {\n if (!path.isExpressionStatement()) continue;\n\n const loop = path.findParent(path => path.isLoop());\n if (loop) {\n let uid = loop.getData(\"expressionReplacementReturnUid\");\n\n if (!uid) {\n uid = callee.scope.generateDeclaredUidIdentifier(\"ret\");\n callee\n .get(\"body\")\n .pushContainer(\"body\", returnStatement(cloneNode(uid)));\n loop.setData(\"expressionReplacementReturnUid\", uid);\n } else {\n uid = identifier(uid.name);\n }\n\n path\n .get(\"expression\")\n .replaceWith(\n assignmentExpression(\"=\", cloneNode(uid), path.node.expression),\n );\n } else {\n path.replaceWith(returnStatement(path.node.expression));\n }\n }\n\n // This is an IIFE, so we don't need to worry about the noNewArrows assumption\n callee.arrowFunctionToExpression();\n // Fixme: we can not `assert this is NodePath<t.FunctionExpression>` in `arrowFunctionToExpression`\n // because it is not a class method known at compile time.\n const newCallee = callee as unknown as NodePath<t.FunctionExpression>;\n\n // (() => await xxx)() -> await (async () => await xxx)();\n const needToAwaitFunction =\n isParentAsync &&\n traverse.hasType(\n (this.get(\"callee.body\") as NodePath<t.BlockStatement>).node,\n \"AwaitExpression\",\n FUNCTION_TYPES,\n );\n const needToYieldFunction =\n isParentGenerator &&\n traverse.hasType(\n (this.get(\"callee.body\") as NodePath<t.BlockStatement>).node,\n \"YieldExpression\",\n FUNCTION_TYPES,\n );\n if (needToAwaitFunction) {\n newCallee.set(\"async\", true);\n // yield* will await the generator return result\n if (!needToYieldFunction) {\n this.replaceWith(awaitExpression((this as ThisType).node));\n }\n }\n if (needToYieldFunction) {\n newCallee.set(\"generator\", true);\n this.replaceWith(yieldExpression((this as ThisType).node, true));\n }\n\n return newCallee.get(\"body.body\");\n}\n\nexport function replaceInline(this: NodePath, nodes: t.Node | Array<t.Node>) {\n this.resync();\n\n if (Array.isArray(nodes)) {\n if (Array.isArray(this.container)) {\n nodes = this._verifyNodeList(nodes);\n const paths = this._containerInsertAfter(nodes);\n this.remove();\n return paths;\n } else {\n return this.replaceWithMultiple(nodes);\n }\n } else {\n return this.replaceWith(nodes);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuBA;;;EAtBEA,c;EACAC,uB;EACAC,oB;EACAC,e;EACAC,c;EACAC,c;EACAC,S;EACAC,mB;EACAC,U;EACAC,sB;EACAC,uB;EACAC,gB;EACAC,Y;EACAC,S;EACAC,W;EACAC,c;EAC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,EAA0B;MACxB,KAAKlD,WAAL,CAAiBnD,eAAe,CAAE,IAAD,CAAmBqB,IAApB,CAAhC;IACD;EACF;;EACD,IAAIgF,mBAAJ,EAAyB;IACvBH,SAAS,CAAC1B,GAAV,CAAc,WAAd,EAA2B,IAA3B;IACA,KAAKrB,WAAL,CAAiBnC,eAAe,CAAE,IAAD,CAAmBK,IAApB,EAA0B,IAA1B,CAAhC;EACD;;EAED,OAAO6E,SAAS,CAAC1E,GAAV,CAAc,WAAd,CAAP;AACD;;AAEM,SAAS8E,aAAT,CAAuCpF,KAAvC,EAAsE;EAC3E,KAAKC,MAAL;;EAEA,IAAIqC,KAAK,CAACC,OAAN,CAAcvC,KAAd,CAAJ,EAA0B;IACxB,IAAIsC,KAAK,CAACC,OAAN,CAAc,KAAK9B,SAAnB,CAAJ,EAAmC;MACjCT,KAAK,GAAG,KAAKE,eAAL,CAAqBF,KAArB,CAAR;;MACA,MAAMW,KAAK,GAAG,KAAK0E,qBAAL,CAA2BrF,KAA3B,CAAd;;MACA,KAAKc,MAAL;MACA,OAAOH,KAAP;IACD,CALD,MAKO;MACL,OAAO,KAAKZ,mBAAL,CAAyBC,KAAzB,CAAP;IACD;EACF,CATD,MASO;IACL,OAAO,KAAKiC,WAAL,CAAiBjC,KAAjB,CAAP;EACD;AACF"}
@@ -72,4 +72,6 @@ class Binding {
72
72
 
73
73
  }
74
74
 
75
- exports.default = Binding;
75
+ exports.default = Binding;
76
+
77
+ //# sourceMappingURL=binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Binding","constructor","identifier","scope","path","kind","constantViolations","constant","referencePaths","referenced","references","clearValue","deoptValue","hasDeoptedValue","setValue","value","hasValue","reassign","indexOf","push","reference","dereference"],"sources":["../../src/scope/binding.ts"],"sourcesContent":["import type NodePath from \"../path\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"./index\";\n\nexport type BindingKind =\n | \"var\" /* var declarator */\n | \"let\" /* let declarator, class declaration id, catch clause parameters */\n | \"const\" /* const declarator */\n | \"module\" /* import specifiers */\n | \"hoisted\" /* function declaration id */\n | \"param\" /* function declaration parameters */\n | \"local\" /* function expression id, class expression id */\n | \"unknown\"; /* export specifiers */\n/**\n * This class is responsible for a binding inside of a scope.\n *\n * It tracks the following:\n *\n * * Node path.\n * * Amount of times referenced by other nodes.\n * * Paths to nodes that reassign or modify this binding.\n * * The kind of binding. (Is it a parameter, declaration etc)\n */\n\nexport default class Binding {\n identifier: t.Identifier;\n scope: Scope;\n path: NodePath;\n kind: BindingKind;\n\n constructor({\n identifier,\n scope,\n path,\n kind,\n }: {\n identifier: t.Identifier;\n scope: Scope;\n path: NodePath;\n kind: BindingKind;\n }) {\n this.identifier = identifier;\n this.scope = scope;\n this.path = path;\n this.kind = kind;\n\n this.clearValue();\n }\n\n constantViolations: Array<NodePath> = [];\n constant: boolean = true;\n\n referencePaths: Array<NodePath> = [];\n referenced: boolean = false;\n references: number = 0;\n\n declare hasDeoptedValue: boolean;\n declare hasValue: boolean;\n declare value: any;\n\n deoptValue() {\n this.clearValue();\n this.hasDeoptedValue = true;\n }\n\n setValue(value: any) {\n if (this.hasDeoptedValue) return;\n this.hasValue = true;\n this.value = value;\n }\n\n clearValue() {\n this.hasDeoptedValue = false;\n this.hasValue = false;\n this.value = null;\n }\n\n /**\n * Register a constant violation with the provided `path`.\n */\n\n reassign(path: NodePath) {\n this.constant = false;\n if (this.constantViolations.indexOf(path) !== -1) {\n return;\n }\n this.constantViolations.push(path);\n }\n\n /**\n * Increment the amount of references to this binding.\n */\n\n reference(path: NodePath) {\n if (this.referencePaths.indexOf(path) !== -1) {\n return;\n }\n this.referenced = true;\n this.references++;\n this.referencePaths.push(path);\n }\n\n /**\n * Decrement the amount of references to this binding.\n */\n\n dereference() {\n this.references--;\n this.referenced = !!this.references;\n }\n}\n"],"mappings":";;;;;;;AAwBe,MAAMA,OAAN,CAAc;EAM3BC,WAAW,CAAC;IACVC,UADU;IAEVC,KAFU;IAGVC,IAHU;IAIVC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Z,KAAKX,UAAL;IACA,KAAKD,UAAL,GAAkB,CAAC,CAAC,KAAKC,UAAzB;EACD;;AArF0B"}
@@ -1064,4 +1064,6 @@ class Scope {
1064
1064
 
1065
1065
  exports.default = Scope;
1066
1066
  Scope.globals = Object.keys(_globals.builtin);
1067
- Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
1067
+ Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
1068
+
1069
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NOT_LOCAL_BINDING","callExpression","cloneNode","getBindingIdentifiers","identifier","isArrayExpression","isBinary","isClass","isClassBody","isClassDeclaration","isExportAllDeclaration","isExportDefaultDeclaration","isExportNamedDeclaration","isFunctionDeclaration","isIdentifier","isImportDeclaration","isLiteral","isMethod","isModuleDeclaration","isModuleSpecifier","isNullLiteral","isObjectExpression","isProperty","isPureish","isRegExpLiteral","isSuper","isTaggedTemplateExpression","isTemplateLiteral","isThisExpression","isUnaryExpression","isVariableDeclaration","matchesPattern","memberExpression","numericLiteral","toIdentifier","unaryExpression","variableDeclaration","variableDeclarator","isRecordExpression","isTupleExpression","isObjectProperty","isTopicReference","isMetaProperty","isPrivateName","gatherNodeParts","node","parts","type","source","specifiers","length","e","declaration","local","push","value","object","property","name","callee","properties","argument","key","left","id","expression","meta","openingElement","openingFragment","namespace","collectorVisitor","ForStatement","path","declar","get","isVar","scope","parentScope","getFunctionParent","getProgramParent","registerBinding","Declaration","isBlockScoped","isExportDeclaration","parent","registerDeclaration","ImportDeclaration","getBlockParent","ReferencedIdentifier","state","references","ForXStatement","isPattern","constantViolations","ExportDeclaration","exit","binding","getBinding","reference","decl","declarations","Object","keys","LabeledStatement","AssignmentExpression","assignments","UpdateExpression","UnaryExpression","operator","BlockScoped","bindings","CatchClause","Function","params","param","isFunctionExpression","has","ClassExpression","uid","Scope","constructor","block","labels","inited","globals","uids","data","crawling","cached","scopeCache","set","Map","shouldSkip","listKey","parentPath","isScope","parentBlock","hub","traverse","opts","generateDeclaredUidIdentifier","generateUidIdentifier","generateUid","replace","i","_generateUid","hasLabel","hasBinding","hasGlobal","hasReference","program","generateUidBasedOnNode","defaultName","join","slice","generateUidIdentifierBasedOnNode","isStatic","constant","maybeGenerateMemoised","dontPush","checkBlockScopedCollisions","kind","duplicate","buildError","TypeError","rename","oldName","newName","Renamer","_renameFromMap","map","dump","sep","repeat","console","log","violations","toArray","arrayLikeIsIterable","isGenericType","helperName","args","unshift","addHelper","getLabel","registerLabel","label","isLabeledStatement","declare","specifier","buildUndefinedNode","registerConstantViolation","ids","reassign","bindingPath","ReferenceError","declarators","getOuterBindingIdentifiers","getOwnBinding","Binding","addGlobal","hasUid","isPure","constantsOnly","superClass","decorators","body","method","right","elem","elements","prop","computed","static","tag","quasi","expressions","setData","val","getData","removeData","init","crawl","create","programParent","_exploded","visit","enter","typeVisitors","ref","getPatternParent","isBlockStatement","isProgram","isSwitchStatement","isLoop","isCatchClause","isFunction","ensureBlock","unique","blockHoist","_blockHoist","dataKey","declarPath","unshiftContainer","declarator","len","Error","isFunctionParent","isBlockParent","getAllBindings","getAllBindingsOfKind","kinds","bindingIdentifierEquals","getBindingIdentifier","previousPath","isArrowFunctionExpression","getOwnBindingIdentifier","hasOwnBinding","noGlobals","parentHasBinding","includes","contextVariables","moveBindingTo","info","removeOwnBinding","removeBinding","builtin"],"sources":["../../src/scope/index.ts"],"sourcesContent":["import Renamer from \"./lib/renamer\";\nimport type NodePath from \"../path\";\nimport traverse from \"../index\";\nimport type { TraverseOptions } from \"../index\";\nimport Binding from \"./binding\";\nimport type { BindingKind } from \"./binding\";\nimport globals from \"globals\";\nimport {\n NOT_LOCAL_BINDING,\n callExpression,\n cloneNode,\n getBindingIdentifiers,\n identifier,\n isArrayExpression,\n isBinary,\n isClass,\n isClassBody,\n isClassDeclaration,\n isExportAllDeclaration,\n isExportDefaultDeclaration,\n isExportNamedDeclaration,\n isFunctionDeclaration,\n isIdentifier,\n isImportDeclaration,\n isLiteral,\n isMethod,\n isModuleDeclaration,\n isModuleSpecifier,\n isNullLiteral,\n isObjectExpression,\n isProperty,\n isPureish,\n isRegExpLiteral,\n isSuper,\n isTaggedTemplateExpression,\n isTemplateLiteral,\n isThisExpression,\n isUnaryExpression,\n isVariableDeclaration,\n matchesPattern,\n memberExpression,\n numericLiteral,\n toIdentifier,\n unaryExpression,\n variableDeclaration,\n variableDeclarator,\n isRecordExpression,\n isTupleExpression,\n isObjectProperty,\n isTopicReference,\n isMetaProperty,\n isPrivateName,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport { scope as scopeCache } from \"../cache\";\nimport type { Visitor } from \"../types\";\n\ntype NodePart = string | number | boolean;\n// Recursively gathers the identifying names of a node.\nfunction gatherNodeParts(node: t.Node, parts: NodePart[]) {\n switch (node?.type) {\n default:\n if (isModuleDeclaration(node)) {\n if (\n (isExportAllDeclaration(node) ||\n isExportNamedDeclaration(node) ||\n isImportDeclaration(node)) &&\n node.source\n ) {\n gatherNodeParts(node.source, parts);\n } else if (\n (isExportNamedDeclaration(node) || isImportDeclaration(node)) &&\n node.specifiers &&\n node.specifiers.length\n ) {\n for (const e of node.specifiers) gatherNodeParts(e, parts);\n } else if (\n (isExportDefaultDeclaration(node) ||\n isExportNamedDeclaration(node)) &&\n node.declaration\n ) {\n gatherNodeParts(node.declaration, parts);\n }\n } else if (isModuleSpecifier(node)) {\n // todo(flow->ts): should condition instead be:\n // ```\n // t.isExportSpecifier(node) ||\n // t.isImportDefaultSpecifier(node) ||\n // t.isImportNamespaceSpecifier(node) ||\n // t.isImportSpecifier(node)\n // ```\n // allowing only nodes with `.local`?\n // @ts-expect-error todo(flow->ts)\n gatherNodeParts(node.local, parts);\n } else if (\n isLiteral(node) &&\n !isNullLiteral(node) &&\n !isRegExpLiteral(node) &&\n !isTemplateLiteral(node)\n ) {\n parts.push(node.value);\n }\n break;\n\n case \"MemberExpression\":\n case \"OptionalMemberExpression\":\n case \"JSXMemberExpression\":\n gatherNodeParts(node.object, parts);\n gatherNodeParts(node.property, parts);\n break;\n\n case \"Identifier\":\n case \"JSXIdentifier\":\n parts.push(node.name);\n break;\n\n case \"CallExpression\":\n case \"OptionalCallExpression\":\n case \"NewExpression\":\n gatherNodeParts(node.callee, parts);\n break;\n\n case \"ObjectExpression\":\n case \"ObjectPattern\":\n for (const e of node.properties) {\n gatherNodeParts(e, parts);\n }\n break;\n\n case \"SpreadElement\":\n case \"RestElement\":\n gatherNodeParts(node.argument, parts);\n break;\n\n case \"ObjectProperty\":\n case \"ObjectMethod\":\n case \"ClassProperty\":\n case \"ClassMethod\":\n case \"ClassPrivateProperty\":\n case \"ClassPrivateMethod\":\n gatherNodeParts(node.key, parts);\n break;\n\n case \"ThisExpression\":\n parts.push(\"this\");\n break;\n\n case \"Super\":\n parts.push(\"super\");\n break;\n\n case \"Import\":\n parts.push(\"import\");\n break;\n\n case \"DoExpression\":\n parts.push(\"do\");\n break;\n\n case \"YieldExpression\":\n parts.push(\"yield\");\n gatherNodeParts(node.argument, parts);\n break;\n\n case \"AwaitExpression\":\n parts.push(\"await\");\n gatherNodeParts(node.argument, parts);\n break;\n\n case \"AssignmentExpression\":\n gatherNodeParts(node.left, parts);\n break;\n\n case \"VariableDeclarator\":\n gatherNodeParts(node.id, parts);\n break;\n\n case \"FunctionExpression\":\n case \"FunctionDeclaration\":\n case \"ClassExpression\":\n case \"ClassDeclaration\":\n gatherNodeParts(node.id, parts);\n break;\n\n case \"PrivateName\":\n gatherNodeParts(node.id, parts);\n break;\n\n case \"ParenthesizedExpression\":\n gatherNodeParts(node.expression, parts);\n break;\n\n case \"UnaryExpression\":\n case \"UpdateExpression\":\n gatherNodeParts(node.argument, parts);\n break;\n\n case \"MetaProperty\":\n gatherNodeParts(node.meta, parts);\n gatherNodeParts(node.property, parts);\n break;\n\n case \"JSXElement\":\n gatherNodeParts(node.openingElement, parts);\n break;\n\n case \"JSXOpeningElement\":\n gatherNodeParts(node.name, parts);\n break;\n\n case \"JSXFragment\":\n gatherNodeParts(node.openingFragment, parts);\n break;\n\n case \"JSXOpeningFragment\":\n parts.push(\"Fragment\");\n break;\n\n case \"JSXNamespacedName\":\n gatherNodeParts(node.namespace, parts);\n gatherNodeParts(node.name, parts);\n break;\n }\n}\n\n//\ninterface CollectVisitorState {\n assignments: NodePath<t.AssignmentExpression>[];\n references: NodePath<t.Identifier | t.JSXIdentifier>[];\n constantViolations: NodePath[];\n}\n\nconst collectorVisitor: Visitor<CollectVisitorState> = {\n ForStatement(path) {\n const declar = path.get(\"init\");\n // delegate block scope handling to the `BlockScoped` method\n if (declar.isVar()) {\n const { scope } = path;\n const parentScope = scope.getFunctionParent() || scope.getProgramParent();\n parentScope.registerBinding(\"var\", declar);\n }\n },\n\n Declaration(path) {\n // delegate block scope handling to the `BlockScoped` method\n if (path.isBlockScoped()) return;\n\n // delegate import handing to the `ImportDeclaration` method\n if (path.isImportDeclaration()) return;\n\n // this will be hit again once we traverse into it after this iteration\n if (path.isExportDeclaration()) return;\n\n // we've ran into a declaration!\n const parent =\n path.scope.getFunctionParent() || path.scope.getProgramParent();\n parent.registerDeclaration(path);\n },\n\n ImportDeclaration(path) {\n // import may only appear in the top level or inside a module/namespace (for TS/flow)\n const parent = path.scope.getBlockParent();\n\n parent.registerDeclaration(path);\n },\n\n ReferencedIdentifier(path, state) {\n state.references.push(path);\n },\n\n ForXStatement(path, state) {\n const left = path.get(\"left\");\n if (left.isPattern() || left.isIdentifier()) {\n state.constantViolations.push(path);\n }\n // delegate block scope handling to the `BlockScoped` method\n else if (left.isVar()) {\n const { scope } = path;\n const parentScope = scope.getFunctionParent() || scope.getProgramParent();\n parentScope.registerBinding(\"var\", left);\n }\n },\n\n ExportDeclaration: {\n exit(path) {\n const { node, scope } = path;\n // ExportAllDeclaration does not have `declaration`\n if (isExportAllDeclaration(node)) return;\n const declar = node.declaration;\n if (isClassDeclaration(declar) || isFunctionDeclaration(declar)) {\n const id = declar.id;\n if (!id) return;\n\n const binding = scope.getBinding(id.name);\n binding?.reference(path);\n } else if (isVariableDeclaration(declar)) {\n for (const decl of declar.declarations) {\n for (const name of Object.keys(getBindingIdentifiers(decl))) {\n const binding = scope.getBinding(name);\n binding?.reference(path);\n }\n }\n }\n },\n },\n\n LabeledStatement(path) {\n path.scope.getBlockParent().registerDeclaration(path);\n },\n\n AssignmentExpression(path, state) {\n state.assignments.push(path);\n },\n\n UpdateExpression(path, state) {\n state.constantViolations.push(path);\n },\n\n UnaryExpression(path, state) {\n if (path.node.operator === \"delete\") {\n state.constantViolations.push(path);\n }\n },\n\n BlockScoped(path) {\n let scope = path.scope;\n if (scope.path === path) scope = scope.parent;\n\n const parent = scope.getBlockParent();\n parent.registerDeclaration(path);\n\n // Register class identifier in class' scope if this is a class declaration.\n if (path.isClassDeclaration() && path.node.id) {\n const id = path.node.id;\n const name = id.name;\n\n path.scope.bindings[name] = path.scope.parent.getBinding(name);\n }\n },\n\n CatchClause(path) {\n path.scope.registerBinding(\"let\", path);\n },\n\n Function(path) {\n const params: Array<NodePath> = path.get(\"params\");\n for (const param of params) {\n path.scope.registerBinding(\"param\", param);\n }\n\n // Register function expression id after params. When the id\n // collides with a function param, the id effectively can't be\n // referenced: here we registered it as a constantViolation\n if (\n path.isFunctionExpression() &&\n path.has(\"id\") &&\n // @ts-expect-error Fixme: document symbol ast properties\n !path.get(\"id\").node[NOT_LOCAL_BINDING]\n ) {\n path.scope.registerBinding(\"local\", path.get(\"id\"), path);\n }\n },\n\n ClassExpression(path) {\n if (\n path.has(\"id\") &&\n // @ts-expect-error Fixme: document symbol ast properties\n !path.get(\"id\").node[NOT_LOCAL_BINDING]\n ) {\n path.scope.registerBinding(\"local\", path);\n }\n },\n};\n\nlet uid = 0;\n\nexport type { Binding };\n\nexport default class Scope {\n uid;\n\n path: NodePath;\n block: t.Pattern | t.Scopable;\n\n labels;\n inited;\n\n bindings: { [name: string]: Binding };\n references: { [name: string]: true };\n globals: { [name: string]: t.Identifier | t.JSXIdentifier };\n uids: { [name: string]: boolean };\n data: { [key: string | symbol]: unknown };\n crawling: boolean;\n\n /**\n * This searches the current \"scope\" and collects all references/bindings\n * within.\n */\n constructor(path: NodePath<t.Pattern | t.Scopable>) {\n const { node } = path;\n const cached = scopeCache.get(node);\n // Sometimes, a scopable path is placed higher in the AST tree.\n // In these cases, have to create a new Scope.\n if (cached?.path === path) {\n return cached;\n }\n scopeCache.set(node, this);\n\n this.uid = uid++;\n\n this.block = node;\n this.path = path;\n\n this.labels = new Map();\n this.inited = false;\n }\n\n /**\n * Globals.\n */\n\n static globals = Object.keys(globals.builtin);\n\n /**\n * Variables available in current context.\n */\n\n static contextVariables = [\"arguments\", \"undefined\", \"Infinity\", \"NaN\"];\n\n get parent() {\n let parent,\n path = this.path;\n do {\n // Skip method scope if coming from inside computed key or decorator expression\n const shouldSkip = path.key === \"key\" || path.listKey === \"decorators\";\n path = path.parentPath;\n if (shouldSkip && path.isMethod()) path = path.parentPath;\n if (path && path.isScope()) parent = path;\n } while (path && !parent);\n\n return parent?.scope;\n }\n\n get parentBlock() {\n return this.path.parent;\n }\n\n get hub() {\n return this.path.hub;\n }\n\n traverse<S>(\n node: t.Node | t.Node[],\n opts: TraverseOptions<S>,\n state: S,\n ): void;\n traverse(node: t.Node | t.Node[], opts?: TraverseOptions, state?: any): void;\n /**\n * Traverse node with current scope and path.\n */\n traverse<S>(node: any, opts: any, state?: S) {\n traverse(node, opts, this, state, this.path);\n }\n\n /**\n * Generate a unique identifier and add it to the current scope.\n */\n\n generateDeclaredUidIdentifier(name?: string) {\n const id = this.generateUidIdentifier(name);\n this.push({ id });\n return cloneNode(id);\n }\n\n /**\n * Generate a unique identifier.\n */\n\n generateUidIdentifier(name?: string) {\n return identifier(this.generateUid(name));\n }\n\n /**\n * Generate a unique `_id1` binding.\n */\n\n generateUid(name: string = \"temp\"): string {\n name = toIdentifier(name)\n .replace(/^_+/, \"\")\n .replace(/[0-9]+$/g, \"\");\n\n let uid;\n let i = 1;\n do {\n uid = this._generateUid(name, i);\n i++;\n } while (\n this.hasLabel(uid) ||\n this.hasBinding(uid) ||\n this.hasGlobal(uid) ||\n this.hasReference(uid)\n );\n\n const program = this.getProgramParent();\n program.references[uid] = true;\n program.uids[uid] = true;\n\n return uid;\n }\n\n /**\n * Generate an `_id1`.\n */\n\n _generateUid(name: string, i: number) {\n let id = name;\n if (i > 1) id += i;\n return `_${id}`;\n }\n\n generateUidBasedOnNode(node: t.Node, defaultName?: string) {\n const parts: NodePart[] = [];\n gatherNodeParts(node, parts);\n\n let id = parts.join(\"$\");\n id = id.replace(/^_/, \"\") || defaultName || \"ref\";\n\n return this.generateUid(id.slice(0, 20));\n }\n\n /**\n * Generate a unique identifier based on a node.\n */\n\n generateUidIdentifierBasedOnNode(node: t.Node, defaultName?: string) {\n return identifier(this.generateUidBasedOnNode(node, defaultName));\n }\n\n /**\n * Determine whether evaluating the specific input `node` is a consequenceless reference. ie.\n * evaluating it wont result in potentially arbitrary code from being ran. The following are\n * allowed and determined not to cause side effects:\n *\n * - `this` expressions\n * - `super` expressions\n * - Bound identifiers\n */\n\n isStatic(node: t.Node): boolean {\n if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) {\n return true;\n }\n\n if (isIdentifier(node)) {\n const binding = this.getBinding(node.name);\n if (binding) {\n return binding.constant;\n } else {\n return this.hasBinding(node.name);\n }\n }\n\n return false;\n }\n\n /**\n * Possibly generate a memoised identifier if it is not static and has consequences.\n */\n\n maybeGenerateMemoised(node: t.Node, dontPush?: boolean) {\n if (this.isStatic(node)) {\n return null;\n } else {\n const id = this.generateUidIdentifierBasedOnNode(node);\n if (!dontPush) {\n this.push({ id });\n return cloneNode(id);\n }\n return id;\n }\n }\n\n checkBlockScopedCollisions(\n local: Binding,\n kind: BindingKind,\n name: string,\n id: any,\n ) {\n // ignore parameters\n if (kind === \"param\") return;\n\n // Ignore existing binding if it's the name of the current function or\n // class expression\n if (local.kind === \"local\") return;\n\n const duplicate =\n // don't allow duplicate bindings to exist alongside\n kind === \"let\" ||\n local.kind === \"let\" ||\n local.kind === \"const\" ||\n local.kind === \"module\" ||\n // don't allow a local of param with a kind of let\n (local.kind === \"param\" && kind === \"const\");\n\n if (duplicate) {\n throw this.hub.buildError(\n id,\n `Duplicate declaration \"${name}\"`,\n TypeError,\n );\n }\n }\n\n rename(oldName: string, newName?: string, block?: t.Pattern | t.Scopable) {\n const binding = this.getBinding(oldName);\n if (binding) {\n newName = newName || this.generateUidIdentifier(oldName).name;\n return new Renamer(binding, oldName, newName).rename(block);\n }\n }\n\n /** @deprecated Not used in our codebase */\n _renameFromMap(\n map: Record<string | symbol, unknown>,\n oldName: string | symbol,\n newName: string | symbol,\n value: unknown,\n ) {\n if (map[oldName]) {\n map[newName] = value;\n map[oldName] = null;\n }\n }\n\n dump() {\n const sep = \"-\".repeat(60);\n console.log(sep);\n let scope: Scope = this;\n do {\n console.log(\"#\", scope.block.type);\n for (const name of Object.keys(scope.bindings)) {\n const binding = scope.bindings[name];\n console.log(\" -\", name, {\n constant: binding.constant,\n references: binding.references,\n violations: binding.constantViolations.length,\n kind: binding.kind,\n });\n }\n } while ((scope = scope.parent));\n console.log(sep);\n }\n\n // TODO: (Babel 8) Split i in two parameters, and use an object of flags\n toArray(\n node: t.Node,\n i?: number | boolean,\n arrayLikeIsIterable?: boolean | void,\n ) {\n if (isIdentifier(node)) {\n const binding = this.getBinding(node.name);\n if (binding?.constant && binding.path.isGenericType(\"Array\")) {\n return node;\n }\n }\n\n if (isArrayExpression(node)) {\n return node;\n }\n\n if (isIdentifier(node, { name: \"arguments\" })) {\n return callExpression(\n memberExpression(\n memberExpression(\n memberExpression(identifier(\"Array\"), identifier(\"prototype\")),\n identifier(\"slice\"),\n ),\n identifier(\"call\"),\n ),\n [node],\n );\n }\n\n let helperName;\n const args = [node];\n if (i === true) {\n // Used in array-spread to create an array.\n helperName = \"toConsumableArray\";\n } else if (i) {\n args.push(numericLiteral(i));\n\n // Used in array-rest to create an array from a subset of an iterable.\n helperName = \"slicedToArray\";\n // TODO if (this.hub.isLoose(\"es6.forOf\")) helperName += \"-loose\";\n } else {\n // Used in array-rest to create an array\n helperName = \"toArray\";\n }\n\n if (arrayLikeIsIterable) {\n args.unshift(this.hub.addHelper(helperName));\n helperName = \"maybeArrayLike\";\n }\n\n // @ts-expect-error todo(flow->ts): t.Node is not valid to use in args, function argument typeneeds to be clarified\n return callExpression(this.hub.addHelper(helperName), args);\n }\n\n hasLabel(name: string) {\n return !!this.getLabel(name);\n }\n\n getLabel(name: string) {\n return this.labels.get(name);\n }\n\n registerLabel(path: NodePath<t.LabeledStatement>) {\n this.labels.set(path.node.label.name, path);\n }\n\n registerDeclaration(path: NodePath) {\n if (path.isLabeledStatement()) {\n this.registerLabel(path);\n } else if (path.isFunctionDeclaration()) {\n this.registerBinding(\"hoisted\", path.get(\"id\"), path);\n } else if (path.isVariableDeclaration()) {\n const declarations = path.get(\"declarations\");\n for (const declar of declarations) {\n this.registerBinding(path.node.kind, declar);\n }\n } else if (path.isClassDeclaration()) {\n if (path.node.declare) return;\n this.registerBinding(\"let\", path);\n } else if (path.isImportDeclaration()) {\n const specifiers = path.get(\"specifiers\");\n for (const specifier of specifiers) {\n this.registerBinding(\"module\", specifier);\n }\n } else if (path.isExportDeclaration()) {\n // todo: improve babel-types\n const declar = path.get(\"declaration\") as NodePath;\n if (\n declar.isClassDeclaration() ||\n declar.isFunctionDeclaration() ||\n declar.isVariableDeclaration()\n ) {\n this.registerDeclaration(declar);\n }\n } else {\n this.registerBinding(\"unknown\", path);\n }\n }\n\n buildUndefinedNode() {\n return unaryExpression(\"void\", numericLiteral(0), true);\n }\n\n registerConstantViolation(path: NodePath) {\n const ids = path.getBindingIdentifiers();\n for (const name of Object.keys(ids)) {\n const binding = this.getBinding(name);\n if (binding) binding.reassign(path);\n }\n }\n\n registerBinding(\n kind: Binding[\"kind\"],\n path: NodePath,\n bindingPath: NodePath = path,\n ) {\n if (!kind) throw new ReferenceError(\"no `kind`\");\n\n if (path.isVariableDeclaration()) {\n const declarators: Array<NodePath> = path.get(\"declarations\");\n for (const declar of declarators) {\n this.registerBinding(kind, declar);\n }\n return;\n }\n\n const parent = this.getProgramParent();\n const ids = path.getOuterBindingIdentifiers(true);\n\n for (const name of Object.keys(ids)) {\n parent.references[name] = true;\n\n for (const id of ids[name]) {\n const local = this.getOwnBinding(name);\n\n if (local) {\n // same identifier so continue safely as we're likely trying to register it\n // multiple times\n if (local.identifier === id) continue;\n\n this.checkBlockScopedCollisions(local, kind, name, id);\n }\n\n // A redeclaration of an existing variable is a modification\n if (local) {\n this.registerConstantViolation(bindingPath);\n } else {\n this.bindings[name] = new Binding({\n identifier: id,\n scope: this,\n path: bindingPath,\n kind: kind,\n });\n }\n }\n }\n }\n\n addGlobal(node: t.Identifier | t.JSXIdentifier) {\n this.globals[node.name] = node;\n }\n\n hasUid(name: string): boolean {\n let scope: Scope = this;\n\n do {\n if (scope.uids[name]) return true;\n } while ((scope = scope.parent));\n\n return false;\n }\n\n hasGlobal(name: string): boolean {\n let scope: Scope = this;\n\n do {\n if (scope.globals[name]) return true;\n } while ((scope = scope.parent));\n\n return false;\n }\n\n hasReference(name: string): boolean {\n return !!this.getProgramParent().references[name];\n }\n\n isPure(node: t.Node, constantsOnly?: boolean): boolean {\n if (isIdentifier(node)) {\n const binding = this.getBinding(node.name);\n if (!binding) return false;\n if (constantsOnly) return binding.constant;\n return true;\n } else if (\n isThisExpression(node) ||\n isMetaProperty(node) ||\n isTopicReference(node) ||\n isPrivateName(node)\n ) {\n return true;\n } else if (isClass(node)) {\n if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {\n return false;\n }\n if (node.decorators?.length > 0) {\n return false;\n }\n return this.isPure(node.body, constantsOnly);\n } else if (isClassBody(node)) {\n for (const method of node.body) {\n if (!this.isPure(method, constantsOnly)) return false;\n }\n return true;\n } else if (isBinary(node)) {\n return (\n this.isPure(node.left, constantsOnly) &&\n this.isPure(node.right, constantsOnly)\n );\n } else if (isArrayExpression(node) || isTupleExpression(node)) {\n for (const elem of node.elements) {\n if (elem !== null && !this.isPure(elem, constantsOnly)) return false;\n }\n return true;\n } else if (isObjectExpression(node) || isRecordExpression(node)) {\n for (const prop of node.properties) {\n if (!this.isPure(prop, constantsOnly)) return false;\n }\n return true;\n } else if (isMethod(node)) {\n if (node.computed && !this.isPure(node.key, constantsOnly)) return false;\n if (node.decorators?.length > 0) {\n return false;\n }\n return true;\n } else if (isProperty(node)) {\n // @ts-expect-error todo(flow->ts): computed in not present on private properties\n if (node.computed && !this.isPure(node.key, constantsOnly)) return false;\n if (node.decorators?.length > 0) {\n return false;\n }\n if (isObjectProperty(node) || node.static) {\n if (node.value !== null && !this.isPure(node.value, constantsOnly)) {\n return false;\n }\n }\n return true;\n } else if (isUnaryExpression(node)) {\n return this.isPure(node.argument, constantsOnly);\n } else if (isTaggedTemplateExpression(node)) {\n return (\n matchesPattern(node.tag, \"String.raw\") &&\n !this.hasBinding(\"String\", true) &&\n this.isPure(node.quasi, constantsOnly)\n );\n } else if (isTemplateLiteral(node)) {\n for (const expression of node.expressions) {\n if (!this.isPure(expression, constantsOnly)) return false;\n }\n return true;\n } else {\n return isPureish(node);\n }\n }\n\n /**\n * Set some arbitrary data on the current scope.\n */\n\n setData(key: string | symbol, val: any) {\n return (this.data[key] = val);\n }\n\n /**\n * Recursively walk up scope tree looking for the data `key`.\n */\n\n getData(key: string | symbol): any {\n let scope: Scope = this;\n do {\n const data = scope.data[key];\n if (data != null) return data;\n } while ((scope = scope.parent));\n }\n\n /**\n * Recursively walk up scope tree looking for the data `key` and if it exists,\n * remove it.\n */\n\n removeData(key: string) {\n let scope: Scope = this;\n do {\n const data = scope.data[key];\n if (data != null) scope.data[key] = null;\n } while ((scope = scope.parent));\n }\n\n init() {\n if (!this.inited) {\n this.inited = true;\n this.crawl();\n }\n }\n\n crawl() {\n const path = this.path;\n\n this.references = Object.create(null);\n this.bindings = Object.create(null);\n this.globals = Object.create(null);\n this.uids = Object.create(null);\n this.data = Object.create(null);\n\n const programParent = this.getProgramParent();\n if (programParent.crawling) return;\n\n const state: CollectVisitorState = {\n references: [],\n constantViolations: [],\n assignments: [],\n };\n\n this.crawling = true;\n // traverse does not visit the root node, here we explicitly collect\n // root node binding info when the root is not a Program.\n if (path.type !== \"Program\" && collectorVisitor._exploded) {\n // @ts-expect-error when collectorVisitor is exploded, `enter` always exists\n for (const visit of collectorVisitor.enter) {\n visit(path, state);\n }\n const typeVisitors = collectorVisitor[path.type];\n if (typeVisitors) {\n // @ts-expect-error when collectorVisitor is exploded, `enter` always exists\n for (const visit of typeVisitors.enter) {\n visit(path, state);\n }\n }\n }\n path.traverse(collectorVisitor, state);\n this.crawling = false;\n\n // register assignments\n for (const path of state.assignments) {\n // register undeclared bindings as globals\n const ids = path.getBindingIdentifiers();\n for (const name of Object.keys(ids)) {\n if (path.scope.getBinding(name)) continue;\n programParent.addGlobal(ids[name]);\n }\n\n // register as constant violation\n path.scope.registerConstantViolation(path);\n }\n\n // register references\n for (const ref of state.references) {\n const binding = ref.scope.getBinding(ref.node.name);\n if (binding) {\n binding.reference(ref);\n } else {\n programParent.addGlobal(ref.node);\n }\n }\n\n // register constant violations\n for (const path of state.constantViolations) {\n path.scope.registerConstantViolation(path);\n }\n }\n\n push(opts: {\n id: t.LVal;\n init?: t.Expression;\n unique?: boolean;\n _blockHoist?: number | undefined;\n kind?: \"var\" | \"let\" | \"const\";\n }) {\n let path = this.path;\n\n if (path.isPattern()) {\n path = this.getPatternParent().path;\n } else if (!path.isBlockStatement() && !path.isProgram()) {\n path = this.getBlockParent().path;\n }\n\n if (path.isSwitchStatement()) {\n path = (this.getFunctionParent() || this.getProgramParent()).path;\n }\n\n if (path.isLoop() || path.isCatchClause() || path.isFunction()) {\n // @ts-expect-error TS can not infer NodePath<Loop> | NodePath<CatchClause> as NodePath<Loop | CatchClause>\n path.ensureBlock();\n // @ts-expect-error todo(flow->ts): improve types\n path = path.get(\"body\");\n }\n\n const unique = opts.unique;\n const kind = opts.kind || \"var\";\n const blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist;\n\n const dataKey = `declaration:${kind}:${blockHoist}`;\n let declarPath = !unique && path.getData(dataKey);\n\n if (!declarPath) {\n const declar = variableDeclaration(kind, []);\n // @ts-expect-error todo(flow->ts): avoid modifying nodes\n declar._blockHoist = blockHoist;\n\n [declarPath] = (path as NodePath<t.BlockStatement>).unshiftContainer(\n \"body\",\n [declar],\n );\n if (!unique) path.setData(dataKey, declarPath);\n }\n\n const declarator = variableDeclarator(opts.id, opts.init);\n const len = declarPath.node.declarations.push(declarator);\n path.scope.registerBinding(kind, declarPath.get(\"declarations\")[len - 1]);\n }\n\n /**\n * Walk up to the top of the scope tree and get the `Program`.\n */\n\n getProgramParent() {\n let scope: Scope = this;\n do {\n if (scope.path.isProgram()) {\n return scope;\n }\n } while ((scope = scope.parent));\n throw new Error(\"Couldn't find a Program\");\n }\n\n /**\n * Walk up the scope tree until we hit either a Function or return null.\n */\n\n getFunctionParent(): Scope | null {\n let scope: Scope = this;\n do {\n if (scope.path.isFunctionParent()) {\n return scope;\n }\n } while ((scope = scope.parent));\n return null;\n }\n\n /**\n * Walk up the scope tree until we hit either a BlockStatement/Loop/Program/Function/Switch or reach the\n * very top and hit Program.\n */\n\n getBlockParent() {\n let scope: Scope = this;\n do {\n if (scope.path.isBlockParent()) {\n return scope;\n }\n } while ((scope = scope.parent));\n throw new Error(\n \"We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...\",\n );\n }\n\n /**\n * Walk up from a pattern scope (function param initializer) until we hit a non-pattern scope,\n * then returns its block parent\n * @returns An ancestry scope whose path is a block parent\n */\n getPatternParent() {\n let scope: Scope = this;\n do {\n if (!scope.path.isPattern()) {\n return scope.getBlockParent();\n }\n } while ((scope = scope.parent.parent));\n throw new Error(\n \"We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...\",\n );\n }\n\n /**\n * Walks the scope tree and gathers **all** bindings.\n */\n\n getAllBindings(): Record<string, Binding> {\n const ids = Object.create(null);\n\n let scope: Scope = this;\n do {\n for (const key of Object.keys(scope.bindings)) {\n if (key in ids === false) {\n ids[key] = scope.bindings[key];\n }\n }\n scope = scope.parent;\n } while (scope);\n\n return ids;\n }\n\n /**\n * Walks the scope tree and gathers all declarations of `kind`.\n */\n\n getAllBindingsOfKind(...kinds: string[]): Record<string, Binding> {\n const ids = Object.create(null);\n\n for (const kind of kinds) {\n let scope: Scope = this;\n do {\n for (const name of Object.keys(scope.bindings)) {\n const binding = scope.bindings[name];\n if (binding.kind === kind) ids[name] = binding;\n }\n scope = scope.parent;\n } while (scope);\n }\n\n return ids;\n }\n\n bindingIdentifierEquals(name: string, node: t.Node): boolean {\n return this.getBindingIdentifier(name) === node;\n }\n\n getBinding(name: string): Binding | undefined {\n let scope: Scope = this;\n let previousPath;\n\n do {\n const binding = scope.getOwnBinding(name);\n if (binding) {\n // Check if a pattern is a part of parameter expressions.\n // Note: for performance reason we skip checking previousPath.parentPath.isFunction()\n // because `scope.path` is validated as scope in packages/babel-types/src/validators/isScope.js\n // That is, if a scope path is pattern, its parent must be Function/CatchClause\n\n // Spec 9.2.10.28: The closure created by this expression should not have visibility of\n // declarations in the function body. If the binding is not a `param`-kind (as function parameters)\n // or `local`-kind (as id in function expression),\n // then it must be defined inside the function body, thus it should be skipped\n if (\n previousPath?.isPattern() &&\n binding.kind !== \"param\" &&\n binding.kind !== \"local\"\n ) {\n // do nothing\n } else {\n return binding;\n }\n } else if (\n !binding &&\n name === \"arguments\" &&\n scope.path.isFunction() &&\n !scope.path.isArrowFunctionExpression()\n ) {\n break;\n }\n previousPath = scope.path;\n } while ((scope = scope.parent));\n }\n\n getOwnBinding(name: string): Binding | undefined {\n return this.bindings[name];\n }\n\n // todo: return probably can be undefined…\n getBindingIdentifier(name: string): t.Identifier {\n return this.getBinding(name)?.identifier;\n }\n\n // todo: flow->ts return probably can be undefined\n getOwnBindingIdentifier(name: string): t.Identifier {\n const binding = this.bindings[name];\n return binding?.identifier;\n }\n\n hasOwnBinding(name: string) {\n return !!this.getOwnBinding(name);\n }\n\n hasBinding(name: string, noGlobals?: boolean) {\n if (!name) return false;\n if (this.hasOwnBinding(name)) return true;\n if (this.parentHasBinding(name, noGlobals)) return true;\n if (this.hasUid(name)) return true;\n if (!noGlobals && Scope.globals.includes(name)) return true;\n if (!noGlobals && Scope.contextVariables.includes(name)) return true;\n return false;\n }\n\n parentHasBinding(name: string, noGlobals?: boolean) {\n return this.parent?.hasBinding(name, noGlobals);\n }\n\n /**\n * Move a binding of `name` to another `scope`.\n */\n\n moveBindingTo(name: string, scope: Scope) {\n const info = this.getBinding(name);\n if (info) {\n info.scope.removeOwnBinding(name);\n info.scope = scope;\n scope.bindings[name] = info;\n }\n }\n\n removeOwnBinding(name: string) {\n delete this.bindings[name];\n }\n\n removeBinding(name: string) {\n // clear literal binding\n this.getBinding(name)?.scope.removeOwnBinding(name);\n\n // clear uids with this name - https://github.com/babel/babel/issues/2101\n let scope: Scope = this;\n do {\n if (scope.uids[name]) {\n scope.uids[name] = false;\n }\n } while ((scope = scope.parent));\n }\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA;;AACA;;AA+CA;;;EA9CEA,iB;EACAC,c;EACAC,S;EACAC,qB;EACAC,U;EACAC,iB;EACAC,Q;EACAC,O;EACAC,W;EACAC,kB;EACAC,sB;EACAC,0B;EACAC,wB;EACAC,qB;EACAC,Y;EACAC,mB;EACAC,S;EACAC,Q;EACAC,mB;EACAC,iB;EACAC,a;EACAC,kB;EACAC,U;EACAC,S;EACAC,e;EACAC,O;EACAC,0B;EACAC,iB;EACAC,gB;EACAC,iB;EACAC,qB;EACAC,c;EACAC,gB;EACAC,c;EACAC,Y;EACAC,e;EACAC,mB;EACAC,kB;EACAC,kB;EACAC,iB;EACAC,gB;EACAC,gB;EACAC,c;EACAC;;;AAQF,SAASC,eAAT,CAAyBC,IAAzB,EAAuCC,KAAvC,EAA0D;EACxD,QAAQD,IAAR,oBAAQA,IAAI,CAAEE,IAAd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B4L,gBAA7B,CAA8C9M,IAA9C;IAGA,IAAIkB,KAAY,GAAG,IAAnB;;IACA,GAAG;MACD,IAAIA,KAAK,CAACiD,IAAN,CAAWnE,IAAX,CAAJ,EAAsB;QACpBkB,KAAK,CAACiD,IAAN,CAAWnE,IAAX,IAAmB,KAAnB;MACD;IACF,CAJD,QAIUkB,KAAK,GAAGA,KAAK,CAACQ,MAJxB;EAKD;;AAp4BwB;;;AAANmC,K,CA2CZK,O,GAAUvB,MAAM,CAACC,IAAP,CAAYsB,QAAO,CAAC8I,OAApB,C;AA3CEnJ,K,CAiDZ8I,gB,GAAmB,CAAC,WAAD,EAAc,WAAd,EAA2B,UAA3B,EAAuC,KAAvC,C"}
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _binding = require("../binding");
9
-
10
8
  var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
11
9
 
12
10
  var t = require("@babel/types");
@@ -126,4 +124,6 @@ class Renamer {
126
124
 
127
125
  }
128
126
 
129
- exports.default = Renamer;
127
+ exports.default = Renamer;
128
+
129
+ //# sourceMappingURL=renamer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["renameVisitor","ReferencedIdentifier","node","state","name","oldName","newName","Scope","path","scope","bindingIdentifierEquals","binding","identifier","skip","isMethod","requeueComputedKeyAndDecorators","isVariableDeclaration","ids","getOuterBindingIdentifiers","Renamer","constructor","maybeConvertFromExportDeclaration","parentDeclar","maybeExportDeclar","parentPath","isExportDeclaration","isExportDefaultDeclaration","declaration","t","isDeclaration","id","isExportAllDeclaration","splitExportDeclaration","maybeConvertFromClassFunctionDeclaration","maybeConvertFromClassFunctionExpression","rename","block","find","isFunctionExpression","isClassExpression","bindingIds","blockToTraverse","type","cases","forEach","c","traverse","removeOwnBinding","bindings"],"sources":["../../../src/scope/lib/renamer.ts"],"sourcesContent":["import type Binding from \"../binding\";\nimport splitExportDeclaration from \"@babel/helper-split-export-declaration\";\nimport * as t from \"@babel/types\";\nimport type { NodePath, Visitor } from \"../..\";\nimport { requeueComputedKeyAndDecorators } from \"@babel/helper-environment-visitor\";\n\nconst renameVisitor: Visitor<Renamer> = {\n ReferencedIdentifier({ node }, state) {\n if (node.name === state.oldName) {\n node.name = state.newName;\n }\n },\n\n Scope(path, state) {\n if (\n !path.scope.bindingIdentifierEquals(\n state.oldName,\n state.binding.identifier,\n )\n ) {\n path.skip();\n if (path.isMethod()) {\n requeueComputedKeyAndDecorators(path);\n }\n }\n },\n\n \"AssignmentExpression|Declaration|VariableDeclarator\"(\n path: NodePath<t.AssignmentPattern | t.Declaration | t.VariableDeclarator>,\n state,\n ) {\n if (path.isVariableDeclaration()) return;\n const ids = path.getOuterBindingIdentifiers();\n\n for (const name in ids) {\n if (name === state.oldName) ids[name].name = state.newName;\n }\n },\n};\n\nexport default class Renamer {\n constructor(binding: Binding, oldName: string, newName: string) {\n this.newName = newName;\n this.oldName = oldName;\n this.binding = binding;\n }\n\n declare oldName: string;\n declare newName: string;\n declare binding: Binding;\n\n maybeConvertFromExportDeclaration(parentDeclar: NodePath) {\n const maybeExportDeclar = parentDeclar.parentPath;\n\n if (!maybeExportDeclar.isExportDeclaration()) {\n return;\n }\n\n if (maybeExportDeclar.isExportDefaultDeclaration()) {\n const { declaration } = maybeExportDeclar.node;\n if (t.isDeclaration(declaration) && !declaration.id) {\n return;\n }\n }\n\n if (maybeExportDeclar.isExportAllDeclaration()) {\n return;\n }\n\n splitExportDeclaration(\n maybeExportDeclar as NodePath<\n Exclude<t.ExportDeclaration, t.ExportAllDeclaration>\n >,\n );\n }\n\n maybeConvertFromClassFunctionDeclaration(path: NodePath) {\n return path; // TODO\n\n // // retain the `name` of a class/function declaration\n\n // if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;\n // if (this.binding.kind !== \"hoisted\") return;\n\n // path.node.id = identifier(this.oldName);\n // path.node._blockHoist = 3;\n\n // path.replaceWith(\n // variableDeclaration(\"let\", [\n // variableDeclarator(identifier(this.newName), toExpression(path.node)),\n // ]),\n // );\n }\n\n maybeConvertFromClassFunctionExpression(path: NodePath) {\n return path; // TODO\n\n // // retain the `name` of a class/function expression\n\n // if (!path.isFunctionExpression() && !path.isClassExpression()) return;\n // if (this.binding.kind !== \"local\") return;\n\n // path.node.id = identifier(this.oldName);\n\n // this.binding.scope.parent.push({\n // id: identifier(this.newName),\n // });\n\n // path.replaceWith(\n // assignmentExpression(\"=\", identifier(this.newName), path.node),\n // );\n }\n\n rename(block?: t.Pattern | t.Scopable) {\n const { binding, oldName, newName } = this;\n const { scope, path } = binding;\n\n const parentDeclar = path.find(\n path =>\n path.isDeclaration() ||\n path.isFunctionExpression() ||\n path.isClassExpression(),\n );\n if (parentDeclar) {\n const bindingIds = parentDeclar.getOuterBindingIdentifiers();\n if (bindingIds[oldName] === binding.identifier) {\n // When we are renaming an exported identifier, we need to ensure that\n // the exported binding keeps the old name.\n this.maybeConvertFromExportDeclaration(parentDeclar);\n }\n }\n\n const blockToTraverse = block || scope.block;\n if (blockToTraverse?.type === \"SwitchStatement\") {\n // discriminant is not part of current scope, should be skipped.\n blockToTraverse.cases.forEach(c => {\n scope.traverse(c, renameVisitor, this);\n });\n } else {\n scope.traverse(blockToTraverse, renameVisitor, this);\n }\n\n if (!block) {\n scope.removeOwnBinding(oldName);\n scope.bindings[newName] = binding;\n this.binding.identifier.name = newName;\n }\n\n if (parentDeclar) {\n this.maybeConvertFromClassFunctionDeclaration(path);\n this.maybeConvertFromClassFunctionExpression(path);\n }\n }\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AAEA;;AAEA,MAAMA,aAA+B,GAAG;EACtCC,oBAAoB,CAAC;IAAEC;EAAF,CAAD,EAAWC,KAAX,EAAkB;IACpC,IAAID,IAAI,CAACE,IAAL,KAAcD,KAAK,CAACE,OAAxB,EAAiC;MAC/BH,IAAI,CAACE,IAAL,GAAYD,KAAK,CAACG,OAAlB;IACD;EACF,CALqC;;EAOtCC,K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L,CAAaC,UAAb,CAAwBR,IAAxB,GAA+BE,OAA/B;IACD;;IAED,IAAIgB,YAAJ,EAAkB;MAChB,KAAKW,wCAAL,CAA8CzB,IAA9C;MACA,KAAK0B,uCAAL,CAA6C1B,IAA7C;IACD;EACF;;AAhH0B"}
@@ -27,4 +27,6 @@ function traverseNode(node, opts, scope, state, path, skipKeys) {
27
27
  }
28
28
 
29
29
  return false;
30
- }
30
+ }
31
+
32
+ //# sourceMappingURL=traverse-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VISITOR_KEYS","traverseNode","node","opts","scope","state","path","skipKeys","keys","type","context","TraversalContext","key","visit"],"sources":["../src/traverse-node.ts"],"sourcesContent":["import TraversalContext from \"./context\";\nimport type { TraverseOptions } from \"./index\";\nimport type NodePath from \"./path\";\nimport type Scope from \"./scope\";\nimport type * as t from \"@babel/types\";\nimport { VISITOR_KEYS } from \"@babel/types\";\n\n/**\n * Traverse the children of given node\n * @param {Node} node\n * @param {TraverseOptions} opts The traverse options used to create a new traversal context\n * @param {scope} scope A traversal scope used to create a new traversal context. When opts.noScope is true, scope should not be provided\n * @param {any} state A user data storage provided as the second callback argument for traversal visitors\n * @param {NodePath} path A NodePath of given node\n * @param {Record<string, boolean>} skipKeys A map from key names to whether that should be skipped during traversal. The skipKeys are applied to every descendants\n * @returns {boolean} Whether the traversal stops early\n\n * @note This function does not visit the given `node`.\n */\nexport function traverseNode(\n node: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n path?: NodePath,\n skipKeys?: Record<string, boolean>,\n): boolean {\n const keys = VISITOR_KEYS[node.type];\n if (!keys) return false;\n\n const context = new TraversalContext(scope, opts, state, path);\n for (const key of keys) {\n if (skipKeys && skipKeys[key]) continue;\n if (context.visit(node, key)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;;;AAAA;;AAKA;;;EAASA;;;AAcF,SAASC,YAAT,CACLC,IADK,EAELC,IAFK,EAGLC,KAHK,EAILC,KAJK,EAKLC,IALK,EAMLC,QANK,EAOI;EACT,MAAMC,IAAI,GAAGR,YAAY,CAACE,IAAI,CAACO,IAAN,CAAzB;EACA,IAAI,CAACD,IAAL,EAAW,OAAO,KAAP;EAEX,MAAME,OAAO,GAAG,IAAIC,gBAAJ,CAAqBP,KAArB,EAA4BD,IAA5B,EAAkCE,KAAlC,EAAyCC,IAAzC,CAAhB;;EACA,KAAK,MAAMM,GAAX,IAAkBJ,IAAlB,EAAwB;IACtB,IAAID,QAAQ,IAAIA,QAAQ,CAACK,GAAD,CAAxB,EAA+B;;IAC/B,IAAIF,OAAO,CAACG,KAAR,CAAcX,IAAd,EAAoBU,GAApB,CAAJ,EAA8B;MAC5B,OAAO,IAAP;IACD;EACF;;EAED,OAAO,KAAP;AACD"}
package/lib/types.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
1
 
3
- var _index = require("./index");
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../src/types.ts"],"sourcesContent":["import type * as t from \"@babel/types\";\nimport type { NodePath } from \"./index\";\nimport type { VirtualTypeAliases } from \"./path/lib/virtual-types\";\n\nexport type Visitor<S = {}> = VisitNodeObject<S, t.Node> & {\n [Type in t.Node[\"type\"]]?: VisitNode<S, Extract<t.Node, { type: Type }>>;\n} & {\n [K in keyof t.Aliases]?: VisitNode<S, t.Aliases[K]>;\n} & {\n [K in keyof VirtualTypeAliases]?: VisitNode<S, VirtualTypeAliases[K]>;\n} & {\n [K in keyof InternalVisitorFlags]?: InternalVisitorFlags[K];\n} & {\n // Babel supports `NodeTypesWithoutComment | NodeTypesWithoutComment | ... ` but it is\n // too complex for TS. So we type it as a general visitor only if the key contains `|`\n // this is good enough for non-visitor traverse options e.g. `noScope`\n [k: `${string}|${string}`]: VisitNode<S, t.Node>;\n};\n\n/** @internal */\ntype InternalVisitorFlags = {\n _exploded?: boolean;\n _verified?: boolean;\n};\n\nexport type VisitNode<S, P extends t.Node> =\n | VisitNodeFunction<S, P>\n | VisitNodeObject<S, P>;\n\nexport type VisitNodeFunction<S, P extends t.Node> = (\n this: S,\n path: NodePath<P>,\n state: S,\n) => void;\n\nexport interface VisitNodeObject<S, P extends t.Node> {\n enter?: VisitNodeFunction<S, P>;\n exit?: VisitNodeFunction<S, P>;\n}\n"],"mappings":""}
package/lib/visitors.js CHANGED
@@ -243,4 +243,6 @@ function mergePair(dest, src) {
243
243
  for (const key of Object.keys(src)) {
244
244
  dest[key] = [].concat(dest[key] || [], src[key]);
245
245
  }
246
- }
246
+ }
247
+
248
+ //# sourceMappingURL=visitors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEPRECATED_KEYS","FLIPPED_ALIAS_KEYS","TYPES","isVirtualType","type","virtualTypes","explode","visitor","_exploded","nodeType","Object","keys","shouldIgnoreKey","parts","split","length","fns","part","verify","__esModule","ensureEntranceObjects","ensureCallbackArrays","wrapCheck","types","mergePair","aliases","deprecatedKey","console","trace","alias","existing","_verified","Error","validateVisitorMethods","indexOf","visitors","visitorKey","path","val","concat","fn","TypeError","merge","states","wrapper","rootVisitor","i","state","visitorType","wrapWithStateOrWrapper","nodeVisitor","oldVisitor","newVisitor","key","Array","isArray","map","newFn","call","toString","obj","enter","exit","apply","arguments","dest","src"],"sources":["../src/visitors.ts"],"sourcesContent":["import * as virtualTypes from \"./path/lib/virtual-types\";\nimport { DEPRECATED_KEYS, FLIPPED_ALIAS_KEYS, TYPES } from \"@babel/types\";\nimport type { NodePath, Visitor } from \"./index\";\n\ntype VIRTUAL_TYPES = keyof typeof virtualTypes;\nfunction isVirtualType(type: string): type is VIRTUAL_TYPES {\n return type in virtualTypes;\n}\n\n/**\n * explode() will take a visitor object with all of the various shorthands\n * that we support, and validates & normalizes it into a common format, ready\n * to be used in traversal\n *\n * The various shorthands are:\n * * `Identifier() { ... }` -> `Identifier: { enter() { ... } }`\n * * `\"Identifier|NumericLiteral\": { ... }` -> `Identifier: { ... }, NumericLiteral: { ... }`\n * * Aliases in `@babel/types`: e.g. `Property: { ... }` -> `ObjectProperty: { ... }, ClassProperty: { ... }`\n *\n * Other normalizations are:\n * * Visitors of virtual types are wrapped, so that they are only visited when\n * their dynamic check passes\n * * `enter` and `exit` functions are wrapped in arrays, to ease merging of\n * visitors\n */\nexport function explode(visitor: Visitor) {\n if (visitor._exploded) return visitor;\n visitor._exploded = true;\n\n // normalise pipes\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n const parts: Array<string> = nodeType.split(\"|\");\n if (parts.length === 1) continue;\n\n const fns = visitor[nodeType];\n delete visitor[nodeType];\n\n for (const part of parts) {\n // @ts-expect-error part will be verified by `verify` later\n visitor[part] = fns;\n }\n }\n\n // verify data structure\n verify(visitor);\n\n // make sure there's no __esModule type since this is because we're using loose mode\n // and it sets __esModule to be enumerable on all modules :(\n // @ts-expect-error ESModule interop\n delete visitor.__esModule;\n\n // ensure visitors are objects\n ensureEntranceObjects(visitor);\n\n // ensure enter/exit callbacks are arrays\n ensureCallbackArrays(visitor);\n\n // add type wrappers\n for (const nodeType of Object.keys(visitor)) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n if (!isVirtualType(nodeType)) continue;\n\n // wrap all the functions\n const fns = visitor[nodeType];\n for (const type of Object.keys(fns)) {\n // @ts-expect-error manipulating visitors\n fns[type] = wrapCheck(nodeType, fns[type]);\n }\n\n // clear it from the visitor\n delete visitor[nodeType];\n\n const types = virtualTypes[nodeType];\n if (types !== null) {\n for (const type of types) {\n // merge the visitor if necessary or just put it back in\n if (visitor[type]) {\n mergePair(visitor[type], fns);\n } else {\n // @ts-expect-error Expression produces too complex union\n visitor[type] = fns;\n }\n }\n } else {\n mergePair(visitor, fns);\n }\n }\n\n // add aliases\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n const fns = visitor[nodeType];\n\n let aliases = FLIPPED_ALIAS_KEYS[nodeType];\n\n const deprecatedKey = DEPRECATED_KEYS[nodeType];\n if (deprecatedKey) {\n console.trace(\n `Visitor defined for ${nodeType} but it has been renamed to ${deprecatedKey}`,\n );\n aliases = [deprecatedKey];\n }\n\n if (!aliases) continue;\n\n // clear it from the visitor\n delete visitor[nodeType];\n\n for (const alias of aliases) {\n const existing = visitor[alias];\n if (existing) {\n mergePair(existing, fns);\n } else {\n // @ts-expect-error Expression produces a union type that is too complex to represent.\n visitor[alias] = { ...fns };\n }\n }\n }\n\n for (const nodeType of Object.keys(visitor)) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n ensureCallbackArrays(\n // @ts-expect-error nodeType must present in visitor after previous validations\n visitor[nodeType],\n );\n }\n\n return visitor;\n}\n\nexport function verify(visitor: Visitor) {\n if (visitor._verified) return;\n\n if (typeof visitor === \"function\") {\n throw new Error(\n \"You passed `traverse()` a function when it expected a visitor object, \" +\n \"are you sure you didn't mean `{ enter: Function }`?\",\n );\n }\n\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (nodeType === \"enter\" || nodeType === \"exit\") {\n validateVisitorMethods(nodeType, visitor[nodeType]);\n }\n\n if (shouldIgnoreKey(nodeType)) continue;\n\n if (TYPES.indexOf(nodeType) < 0) {\n throw new Error(\n `You gave us a visitor for the node type ${nodeType} but it's not a valid type`,\n );\n }\n\n const visitors = visitor[nodeType];\n if (typeof visitors === \"object\") {\n for (const visitorKey of Object.keys(visitors)) {\n if (visitorKey === \"enter\" || visitorKey === \"exit\") {\n // verify that it just contains functions\n validateVisitorMethods(\n `${nodeType}.${visitorKey}`,\n visitors[visitorKey],\n );\n } else {\n throw new Error(\n \"You passed `traverse()` a visitor object with the property \" +\n `${nodeType} that has the invalid property ${visitorKey}`,\n );\n }\n }\n }\n }\n\n visitor._verified = true;\n}\n\nfunction validateVisitorMethods(\n path: string,\n val: any,\n): asserts val is Function | Function[] {\n const fns = [].concat(val);\n for (const fn of fns) {\n if (typeof fn !== \"function\") {\n throw new TypeError(\n `Non-function found defined in ${path} with type ${typeof fn}`,\n );\n }\n }\n}\n\nexport function merge<State>(visitors: Visitor<State>[]): Visitor<State>;\nexport function merge(\n visitors: Visitor<unknown>[],\n states?: any[],\n wrapper?: Function | null,\n): Visitor<unknown>;\nexport function merge(\n visitors: any[],\n states: any[] = [],\n wrapper?: Function | null,\n) {\n const rootVisitor: Visitor = {};\n\n for (let i = 0; i < visitors.length; i++) {\n const visitor = visitors[i];\n const state = states[i];\n\n explode(visitor);\n\n for (const type of Object.keys(visitor) as (keyof Visitor)[]) {\n let visitorType = visitor[type];\n\n // if we have state or wrapper then overload the callbacks to take it\n if (state || wrapper) {\n visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);\n }\n\n // @ts-expect-error: Expression produces a union type that is too complex to represent.\n const nodeVisitor = (rootVisitor[type] ||= {});\n mergePair(nodeVisitor, visitorType);\n }\n }\n\n return rootVisitor;\n}\n\nfunction wrapWithStateOrWrapper<State>(\n oldVisitor: Visitor<State>,\n state: State,\n wrapper?: Function | null,\n) {\n const newVisitor: Visitor = {};\n\n for (const key of Object.keys(oldVisitor) as (keyof Visitor<State>)[]) {\n let fns = oldVisitor[key];\n\n // not an enter/exit array of callbacks\n if (!Array.isArray(fns)) continue;\n\n // @ts-expect-error manipulating visitors\n fns = fns.map(function (fn) {\n let newFn = fn;\n\n if (state) {\n newFn = function (path: NodePath) {\n return fn.call(state, path, state);\n };\n }\n\n if (wrapper) {\n // @ts-expect-error Fixme: document state.key\n newFn = wrapper(state.key, key, newFn);\n }\n\n // Override toString in case this function is printed, we want to print the wrapped function, same as we do in `wrapCheck`\n if (newFn !== fn) {\n newFn.toString = () => fn.toString();\n }\n\n return newFn;\n });\n\n // @ts-expect-error: Expression produces a union type that is too complex to represent.\n newVisitor[key] = fns;\n }\n\n return newVisitor;\n}\n\nfunction ensureEntranceObjects(obj: Visitor) {\n for (const key of Object.keys(obj) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(key)) continue;\n\n const fns = obj[key];\n if (typeof fns === \"function\") {\n // @ts-expect-error: Expression produces a union type that is too complex to represent.\n obj[key] = { enter: fns };\n }\n }\n}\n\nfunction ensureCallbackArrays(obj: Visitor) {\n // @ts-expect-error normalizing enter property\n if (obj.enter && !Array.isArray(obj.enter)) obj.enter = [obj.enter];\n // @ts-expect-error normalizing exit property\n if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];\n}\n\nfunction wrapCheck(nodeType: VIRTUAL_TYPES, fn: Function) {\n const newFn = function (this: unknown, path: NodePath) {\n if (path[`is${nodeType}`]()) {\n return fn.apply(this, arguments);\n }\n };\n newFn.toString = () => fn.toString();\n return newFn;\n}\n\nfunction shouldIgnoreKey(\n key: string,\n): key is\n | \"enter\"\n | \"exit\"\n | \"shouldSkip\"\n | \"denylist\"\n | \"noScope\"\n | \"skipKeys\"\n | \"blacklist\" {\n // internal/hidden key\n if (key[0] === \"_\") return true;\n\n // ignore function keys\n if (key === \"enter\" || key === \"exit\" || key === \"shouldSkip\") return true;\n\n // ignore other options\n if (\n key === \"denylist\" ||\n key === \"noScope\" ||\n key === \"skipKeys\" ||\n // TODO: Remove in Babel 8\n key === \"blacklist\"\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction mergePair(dest: any, src: any) {\n for (const key of Object.keys(src)) {\n dest[key] = [].concat(dest[key] || [], src[key]);\n }\n}\n"],"mappings":";;;;;;;;;AAAA;;AACA;;;EAASA,e;EAAiBC,kB;EAAoBC;;;AAI9C,SAASC,aAAT,CAAuBC,IAAvB,EAA4D;EAC1D,OAAOA,IAAI,IAAIC,YAAf;AACD;;AAkBM,SAASC,OAAT,CAAiBC,OAAjB,EAAmC;EACxC,IAAIA,OAAO,CAACC,SAAZ,EAAuB,OAAOD,OAAP;EACvBA,OAAO,CAACC,SAAR,GAAoB,IAApB;;EAGA,KAAK,MAAMC,QAAX,IAAuBC,MAAM,CAACC,IAAP,CAAYJ,OAAZ,CAAvB,EAAkE;IAChE,IAAIK,eAAe,CAAC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AL,CAAX;AAC3C;;AAED,SAASxC,SAAT,CAAmBb,QAAnB,EAA4C+B,EAA5C,EAA0D;EACxD,MAAMiB,KAAK,GAAG,UAAyBpB,IAAzB,EAAyC;IACrD,IAAIA,IAAI,CAAE,KAAI5B,QAAS,EAAf,CAAJ,EAAJ,EAA6B;MAC3B,OAAO+B,EAAE,CAACuB,KAAH,CAAS,IAAT,EAAeC,SAAf,CAAP;IACD;EACF,CAJD;;EAKAP,KAAK,CAACE,QAAN,GAAiB,MAAMnB,EAAE,CAACmB,QAAH,EAAvB;;EACA,OAAOF,KAAP;AACD;;AAED,SAAS7C,eAAT,CACEyC,GADF,EASgB;EAEd,IAAIA,GAAG,CAAC,CAAD,CAAH,KAAW,GAAf,EAAoB,OAAO,IAAP;EAGpB,IAAIA,GAAG,KAAK,OAAR,IAAmBA,GAAG,KAAK,MAA3B,IAAqCA,GAAG,KAAK,YAAjD,EAA+D,OAAO,IAAP;;EAG/D,IACEA,GAAG,KAAK,UAAR,IACAA,GAAG,KAAK,SADR,IAEAA,GAAG,KAAK,UAFR,IAIAA,GAAG,KAAK,WALV,EAME;IACA,OAAO,IAAP;EACD;;EAED,OAAO,KAAP;AACD;;AAED,SAAS7B,SAAT,CAAmByC,IAAnB,EAA8BC,GAA9B,EAAwC;EACtC,KAAK,MAAMb,GAAX,IAAkB3C,MAAM,CAACC,IAAP,CAAYuD,GAAZ,CAAlB,EAAoC;IAClCD,IAAI,CAACZ,GAAD,CAAJ,GAAY,GAAGd,MAAH,CAAU0B,IAAI,CAACZ,GAAD,CAAJ,IAAa,EAAvB,EAA2Ba,GAAG,CAACb,GAAD,CAA9B,CAAZ;EACD;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.18.13",
3
+ "version": "7.19.0",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "The Babel Team (https://babel.dev/team)",
6
6
  "homepage": "https://babel.dev/docs/en/next/babel-traverse",
@@ -17,13 +17,13 @@
17
17
  "main": "./lib/index.js",
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.18.6",
20
- "@babel/generator": "^7.18.13",
20
+ "@babel/generator": "^7.19.0",
21
21
  "@babel/helper-environment-visitor": "^7.18.9",
22
- "@babel/helper-function-name": "^7.18.9",
22
+ "@babel/helper-function-name": "^7.19.0",
23
23
  "@babel/helper-hoist-variables": "^7.18.6",
24
24
  "@babel/helper-split-export-declaration": "^7.18.6",
25
- "@babel/parser": "^7.18.13",
26
- "@babel/types": "^7.18.13",
25
+ "@babel/parser": "^7.19.0",
26
+ "@babel/types": "^7.19.0",
27
27
  "debug": "^4.1.0",
28
28
  "globals": "^11.1.0"
29
29
  },
@@ -5,8 +5,8 @@ export default function generateAsserts() {
5
5
  * This file is auto-generated! Do not modify it directly.
6
6
  * To re-generate run 'make build'
7
7
  */
8
- import * as t from "@babel/types";
9
- import NodePath from "../index";
8
+ import type * as t from "@babel/types";
9
+ import type NodePath from "../index";
10
10
 
11
11
 
12
12
  export interface NodePathAssetions {`;