@babel/traverse 7.28.5 → 7.28.6

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.
Files changed (40) hide show
  1. package/lib/cache.js +0 -1
  2. package/lib/cache.js.map +1 -1
  3. package/lib/context.js +0 -2
  4. package/lib/context.js.map +1 -1
  5. package/lib/index.js.map +1 -1
  6. package/lib/path/ancestry.js.map +1 -1
  7. package/lib/path/context.js +18 -6
  8. package/lib/path/context.js.map +1 -1
  9. package/lib/path/conversion.js +6 -12
  10. package/lib/path/conversion.js.map +1 -1
  11. package/lib/path/evaluation.js +9 -4
  12. package/lib/path/evaluation.js.map +1 -1
  13. package/lib/path/family.js.map +1 -1
  14. package/lib/path/index.js +42 -46
  15. package/lib/path/index.js.map +1 -1
  16. package/lib/path/inference/index.js.map +1 -1
  17. package/lib/path/inference/util.js +8 -10
  18. package/lib/path/inference/util.js.map +1 -1
  19. package/lib/path/introspection.js +17 -21
  20. package/lib/path/introspection.js.map +1 -1
  21. package/lib/path/lib/hoister.js.map +1 -1
  22. package/lib/path/lib/virtual-types-validator.js +6 -8
  23. package/lib/path/lib/virtual-types-validator.js.map +1 -1
  24. package/lib/path/modification.js +4 -6
  25. package/lib/path/modification.js.map +1 -1
  26. package/lib/path/replacement.js +2 -2
  27. package/lib/path/replacement.js.map +1 -1
  28. package/lib/scope/binding.js.map +1 -1
  29. package/lib/scope/index.js +107 -132
  30. package/lib/scope/index.js.map +1 -1
  31. package/lib/scope/lib/renamer.js +2 -4
  32. package/lib/scope/lib/renamer.js.map +1 -1
  33. package/lib/scope/traverseForScope.js +9 -11
  34. package/lib/scope/traverseForScope.js.map +1 -1
  35. package/lib/traverse-node.js +0 -1
  36. package/lib/traverse-node.js.map +1 -1
  37. package/lib/types.js.map +1 -1
  38. package/lib/visitors.js +10 -14
  39. package/lib/visitors.js.map +1 -1
  40. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"names":["_codeFrame","require","_index","_index2","_cache","_modification","_parser","_t","_context","FUNCTION_TYPES","arrowFunctionExpression","assignmentExpression","awaitExpression","blockStatement","buildUndefinedNode","callExpression","cloneNode","conditionalExpression","expressionStatement","getBindingIdentifiers","identifier","inheritLeadingComments","inheritTrailingComments","inheritsComments","isBlockStatement","isEmptyStatement","isExpression","isExpressionStatement","isIfStatement","isProgram","isStatement","isVariableDeclaration","removeComments","returnStatement","sequenceExpression","validate","yieldExpression","replaceWithMultiple","nodes","_getCachedPaths","resync","call","verifiedNodes","_verifyNodeList","node","length","getCachedPaths","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","get","_getCachedPaths2","ReferenceError","inList","parent","debug","set","declars","nodesAsSingleExpression","gatherSequenceExpressions","id","scope","push","functionParent","getFunctionParent","isParentAsync","async","isParentGenerator","generator","callee","hoistVariables","completionRecords","getCompletionRecords","path","loop","findParent","isLoop","uid","getData","generateDeclaredUidIdentifier","pushContainer","setData","name","arrowFunctionToExpression","newCallee","needToAwaitFunction","hasType","needToYieldFunction","exprs","ensureLastUndefined","kind","declar","declarations","bindings","Object","keys","init","consequent","alternate","test","indexOf","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.ts\";\nimport NodePath from \"./index.ts\";\nimport { getCachedPaths } from \"../cache.ts\";\nimport { _verifyNodeList, _containerInsertAfter } from \"./modification.ts\";\nimport { parse } from \"@babel/parser\";\nimport {\n FUNCTION_TYPES,\n arrowFunctionExpression,\n assignmentExpression,\n awaitExpression,\n blockStatement,\n buildUndefinedNode,\n callExpression,\n cloneNode,\n conditionalExpression,\n expressionStatement,\n getBindingIdentifiers,\n identifier,\n inheritLeadingComments,\n inheritTrailingComments,\n inheritsComments,\n isBlockStatement,\n isEmptyStatement,\n isExpression,\n isExpressionStatement,\n isIfStatement,\n isProgram,\n isStatement,\n isVariableDeclaration,\n removeComments,\n returnStatement,\n sequenceExpression,\n validate,\n yieldExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport { resync, setScope } from \"./context.ts\";\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\nimport type { NodeOrNodeList, NodePaths } from \"./index.ts\";\n\nexport function replaceWithMultiple<Nodes extends NodeOrNodeList<t.Node>>(\n this: NodePath,\n nodes: Nodes,\n): NodePaths<Nodes> {\n resync.call(this);\n\n const verifiedNodes = _verifyNodeList.call(this, nodes);\n inheritLeadingComments(verifiedNodes[0], this.node);\n inheritTrailingComments(verifiedNodes[verifiedNodes.length - 1], this.node);\n getCachedPaths(this)?.delete(this.node);\n // @ts-expect-error TODO: better types\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 resync.call(this);\n let ast: t.File;\n\n try {\n replacement = `(${replacement})`;\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 */\nexport function replaceWith<R extends t.Node>(\n this: NodePath,\n replacementPath: R,\n): [NodePath<R>];\nexport function replaceWith<R extends NodePath>(\n this: NodePath,\n replacementPath: R,\n): [R];\nexport function replaceWith(\n this: NodePath,\n replacementPath: t.Node | NodePath,\n): [NodePath] {\n resync.call(this);\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];\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 [NodePath];\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 _replaceWith.call(this, replacement);\n this.type = replacement.type;\n\n // potentially create new scope\n setScope.call(this);\n\n // requeue for visiting\n this.requeue();\n\n return [nodePath ? this.get(nodePath) : this];\n}\n\nexport function _replaceWith(this: NodePath, node: t.Node | null) {\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 // @ts-expect-error TODO: better types\n getCachedPaths(this)?.set(node, this).delete(this.node);\n\n // @ts-expect-error TODO: better types\n this.node = 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 resync.call(this);\n\n const declars: t.Identifier[] = [];\n const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);\n if (nodesAsSingleExpression) {\n for (const id of declars) this.scope.push({ id });\n return this.replaceWith(nodesAsSingleExpression)[0].get(\"expressions\");\n }\n\n const functionParent = this.getFunctionParent();\n const isParentAsync = functionParent?.node.async;\n const isParentGenerator = functionParent?.node.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 callee.get(\"body\").scope.hoistVariables(id => this.scope.push({ id }));\n\n // add implicit returns to all ending expression statements\n const completionRecords: Array<NodePath> = callee.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\nfunction gatherSequenceExpressions(\n nodes: ReadonlyArray<t.Node>,\n declars: Array<t.Identifier>,\n) {\n const exprs: t.Expression[] = [];\n let ensureLastUndefined = true;\n\n for (const node of nodes) {\n // if we encounter emptyStatement before a non-emptyStatement\n // we want to disregard that\n if (!isEmptyStatement(node)) {\n ensureLastUndefined = false;\n }\n\n if (isExpression(node)) {\n exprs.push(node);\n } else if (isExpressionStatement(node)) {\n exprs.push(node.expression);\n } else if (isVariableDeclaration(node)) {\n if (node.kind !== \"var\") return; // bailed\n\n for (const declar of node.declarations) {\n const bindings = getBindingIdentifiers(declar);\n for (const key of Object.keys(bindings)) {\n declars.push(cloneNode(bindings[key]));\n }\n\n if (declar.init) {\n exprs.push(\n assignmentExpression(\n \"=\",\n // var declarator must not be a void pattern\n declar.id as Exclude<t.VariableDeclarator[\"id\"], t.VoidPattern>,\n declar.init,\n ),\n );\n }\n }\n\n ensureLastUndefined = true;\n } else if (isIfStatement(node)) {\n const consequent = node.consequent\n ? gatherSequenceExpressions([node.consequent], declars)\n : buildUndefinedNode();\n const alternate = node.alternate\n ? gatherSequenceExpressions([node.alternate], declars)\n : buildUndefinedNode();\n if (!consequent || !alternate) return; // bailed\n\n exprs.push(conditionalExpression(node.test, consequent, alternate));\n } else if (isBlockStatement(node)) {\n const body = gatherSequenceExpressions(node.body, declars);\n if (!body) return; // bailed\n\n exprs.push(body);\n } else if (isEmptyStatement(node)) {\n // empty statement so ensure the last item is undefined if we're last\n // checks if emptyStatement is first\n if (nodes.indexOf(node) === 0) {\n ensureLastUndefined = true;\n }\n } else {\n // bailed, we can't turn this statement into an expression\n return;\n }\n }\n\n if (ensureLastUndefined) exprs.push(buildUndefinedNode());\n\n if (exprs.length === 1) {\n return exprs[0];\n } else {\n return sequenceExpression(exprs);\n }\n}\n\nexport function replaceInline(this: NodePath, nodes: t.Node | Array<t.Node>) {\n resync.call(this);\n\n if (Array.isArray(nodes)) {\n if (Array.isArray(this.container)) {\n nodes = _verifyNodeList.call(this, nodes);\n const paths = _containerInsertAfter.call(this, 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,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MA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,CAAC;EAEzD,IAAIkH,KAAK,CAACnF,MAAM,KAAK,CAAC,EAAE;IACtB,OAAOmF,KAAK,CAAC,CAAC,CAAC;EACjB,CAAC,MAAM;IACL,OAAO9F,kBAAkB,CAAC8F,KAAK,CAAC;EAClC;AACF;AAEO,SAASa,aAAaA,CAAiBvG,KAA6B,EAAE;EAC3EE,eAAM,CAACC,IAAI,CAAC,IAAI,CAAC;EAEjB,IAAIoC,KAAK,CAACC,OAAO,CAACxC,KAAK,CAAC,EAAE;IACxB,IAAIuC,KAAK,CAACC,OAAO,CAAC,IAAI,CAAC9B,SAAS,CAAC,EAAE;MACjCV,KAAK,GAAGK,6BAAe,CAACF,IAAI,CAAC,IAAI,EAAEH,KAAK,CAAC;MACzC,MAAMY,KAAK,GAAG4F,mCAAqB,CAACrG,IAAI,CAAC,IAAI,EAAEH,KAAK,CAAC;MACrD,IAAI,CAACe,MAAM,CAAC,CAAC;MACb,OAAOH,KAAK;IACd,CAAC,MAAM;MACL,OAAO,IAAI,CAACb,mBAAmB,CAACC,KAAK,CAAC;IACxC;EACF,CAAC,MAAM;IACL,OAAO,IAAI,CAACkC,WAAW,CAAClC,KAAK,CAAC;EAChC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_codeFrame","require","_index","_index2","_cache","_modification","_parser","_t","_context","FUNCTION_TYPES","arrowFunctionExpression","assignmentExpression","awaitExpression","blockStatement","buildUndefinedNode","callExpression","cloneNode","conditionalExpression","expressionStatement","getBindingIdentifiers","identifier","inheritLeadingComments","inheritTrailingComments","inheritsComments","isBlockStatement","isEmptyStatement","isExpression","isExpressionStatement","isIfStatement","isProgram","isStatement","isVariableDeclaration","removeComments","returnStatement","sequenceExpression","validate","yieldExpression","replaceWithMultiple","nodes","_getCachedPaths","resync","call","verifiedNodes","_verifyNodeList","node","length","getCachedPaths","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","get","_getCachedPaths2","ReferenceError","inList","parent","debug","set","declars","nodesAsSingleExpression","gatherSequenceExpressions","id","scope","push","functionParent","getFunctionParent","isParentAsync","async","isParentGenerator","generator","callee","hoistVariables","completionRecords","getCompletionRecords","path","loop","findParent","isLoop","uid","getData","generateDeclaredUidIdentifier","pushContainer","setData","name","arrowFunctionToExpression","newCallee","needToAwaitFunction","hasType","needToYieldFunction","exprs","ensureLastUndefined","kind","declar","declarations","bindings","Object","keys","init","consequent","alternate","test","indexOf","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.ts\";\nimport NodePath from \"./index.ts\";\nimport { getCachedPaths } from \"../cache.ts\";\nimport { _verifyNodeList, _containerInsertAfter } from \"./modification.ts\";\nimport { parse } from \"@babel/parser\";\nimport {\n FUNCTION_TYPES,\n arrowFunctionExpression,\n assignmentExpression,\n awaitExpression,\n blockStatement,\n buildUndefinedNode,\n callExpression,\n cloneNode,\n conditionalExpression,\n expressionStatement,\n getBindingIdentifiers,\n identifier,\n inheritLeadingComments,\n inheritTrailingComments,\n inheritsComments,\n isBlockStatement,\n isEmptyStatement,\n isExpression,\n isExpressionStatement,\n isIfStatement,\n isProgram,\n isStatement,\n isVariableDeclaration,\n removeComments,\n returnStatement,\n sequenceExpression,\n validate,\n yieldExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport { resync, setScope } from \"./context.ts\";\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\nimport type { NodeOrNodeList, NodePaths } from \"./index.ts\";\n\nexport function replaceWithMultiple<Nodes extends NodeOrNodeList<t.Node>>(\n this: NodePath,\n nodes: Nodes,\n): NodePaths<Nodes> {\n resync.call(this);\n\n const verifiedNodes = _verifyNodeList.call(this, nodes);\n inheritLeadingComments(verifiedNodes[0], this.node);\n inheritTrailingComments(verifiedNodes[verifiedNodes.length - 1], this.node);\n getCachedPaths(this)?.delete(this.node);\n // @ts-expect-error TODO: better types\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 resync.call(this);\n let ast: t.File;\n\n try {\n replacement = `(${replacement})`;\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 */\nexport function replaceWith<R extends t.Node>(\n this: NodePath,\n replacementPath: R,\n): [NodePath<R>];\nexport function replaceWith<R extends NodePath>(\n this: NodePath,\n replacementPath: R,\n): [R];\nexport function replaceWith(\n this: NodePath,\n replacementPath: t.Node | NodePath,\n): [NodePath] {\n resync.call(this);\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];\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 [NodePath];\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 _replaceWith.call(this, replacement);\n this.type = replacement.type;\n\n // potentially create new scope\n setScope.call(this);\n\n // requeue for visiting\n this.requeue();\n\n return [nodePath ? this.get(nodePath) : this];\n}\n\nexport function _replaceWith(this: NodePath, node: t.Node | null) {\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 // @ts-expect-error TODO: better types\n getCachedPaths(this)?.set(node, this).delete(this.node);\n\n // @ts-expect-error TODO: better types\n this.node = 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: t.Statement[],\n) {\n resync.call(this);\n\n const declars: t.Identifier[] = [];\n const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);\n if (nodesAsSingleExpression) {\n for (const id of declars) this.scope.push({ id });\n return this.replaceWith(nodesAsSingleExpression)[0].get(\"expressions\");\n }\n\n const functionParent = this.getFunctionParent();\n const isParentAsync = functionParent?.node.async;\n const isParentGenerator = functionParent?.node.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 callee.get(\"body\").scope.hoistVariables(id => this.scope.push({ id }));\n\n // add implicit returns to all ending expression statements\n const completionRecords: NodePath[] = callee.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 // (() => await xxx)() -> await (async () => await xxx)();\n const needToAwaitFunction =\n isParentAsync &&\n traverse.hasType(newCallee.node.body, \"AwaitExpression\", FUNCTION_TYPES);\n const needToYieldFunction =\n isParentGenerator &&\n traverse.hasType(newCallee.node.body, \"YieldExpression\", FUNCTION_TYPES);\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\nfunction gatherSequenceExpressions(\n nodes: readonly t.Node[],\n declars: t.Identifier[],\n) {\n const exprs: t.Expression[] = [];\n let ensureLastUndefined = true;\n\n for (const node of nodes) {\n // if we encounter emptyStatement before a non-emptyStatement\n // we want to disregard that\n if (!isEmptyStatement(node)) {\n ensureLastUndefined = false;\n }\n\n if (isExpression(node)) {\n exprs.push(node);\n } else if (isExpressionStatement(node)) {\n exprs.push(node.expression);\n } else if (isVariableDeclaration(node)) {\n if (node.kind !== \"var\") return; // bailed\n\n for (const declar of node.declarations) {\n const bindings = getBindingIdentifiers(declar);\n for (const key of Object.keys(bindings)) {\n declars.push(cloneNode(bindings[key]));\n }\n\n if (declar.init) {\n exprs.push(\n assignmentExpression(\n \"=\",\n // var declarator must not be a void pattern\n declar.id as Exclude<t.VariableDeclarator[\"id\"], t.VoidPattern>,\n declar.init,\n ),\n );\n }\n }\n\n ensureLastUndefined = true;\n } else if (isIfStatement(node)) {\n const consequent = node.consequent\n ? gatherSequenceExpressions([node.consequent], declars)\n : buildUndefinedNode();\n const alternate = node.alternate\n ? gatherSequenceExpressions([node.alternate], declars)\n : buildUndefinedNode();\n if (!consequent || !alternate) return; // bailed\n\n exprs.push(conditionalExpression(node.test, consequent, alternate));\n } else if (isBlockStatement(node)) {\n const body = gatherSequenceExpressions(node.body, declars);\n if (!body) return; // bailed\n\n exprs.push(body);\n } else if (isEmptyStatement(node)) {\n // empty statement so ensure the last item is undefined if we're last\n // checks if emptyStatement is first\n if (nodes.indexOf(node) === 0) {\n ensureLastUndefined = true;\n }\n } else {\n // bailed, we can't turn this statement into an expression\n return;\n }\n }\n\n if (ensureLastUndefined) exprs.push(buildUndefinedNode());\n\n if (exprs.length === 1) {\n return exprs[0];\n } else {\n return sequenceExpression(exprs);\n }\n}\n\nexport function replaceInline(this: NodePath, nodes: t.Node | t.Node[]) {\n resync.call(this);\n\n if (Array.isArray(nodes)) {\n if (Array.isArray(this.container)) {\n nodes = _verifyNodeList.call(this, nodes);\n const paths = _containerInsertAfter.call(this, 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,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,EAAA,GAAAN,OAAA;AA+BA,IAAAO,QAAA,GAAAP,OAAA;AAAgD;EA9B9CQ,cAAc;EACdC,uBAAuB;EACvBC,oBAAoB;EACpBC,eAAe;EACfC,cAAc;EACdC,kBAAkB;EAClBC,cAAc;EACdC,SAAS;EACTC,qBAAqB;EACrBC,mBAAmB;EACnBC,qBAAqB;EACrBC,UAAU;EACVC,sBAAsB;EACtBC,uBAAuB;EACvBC,gBAAgB;EAChBC,gBAAgB;EAChBC,gBAAgB;EAChBC,YAAY;EACZC,qBAAqB;EACrBC,aAAa;EACbC,SAAS;EACTC,WAAW;EACXC,qBA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b,OAAOH,KAAK;IACd,CAAC,MAAM;MACL,OAAO,IAAI,CAACb,mBAAmB,CAACC,KAAK,CAAC;IACxC;EACF,CAAC,MAAM;IACL,OAAO,IAAI,CAACkC,WAAW,CAAClC,KAAK,CAAC;EAChC;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["Binding","constructor","identifier","scope","path","kind","constantViolations","constant","referencePaths","referenced","references","isInitInLoop","reassign","clearValue","deoptValue","hasDeoptedValue","setValue","value","hasValue","includes","push","reference","dereference","exports","default","isFunctionDeclarationOrHasInit","isVariableDeclarator","node","init","parentPath","key","isFunctionParent","isForXStatement","isLoop"],"sources":["../../src/scope/binding.ts"],"sourcesContent":["import type NodePath from \"../path/index.ts\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"./index.ts\";\n\nexport type BindingKind =\n | \"var\" /* var declarator */\n | \"let\" /* let declarator, class declaration id, catch clause parameters */\n | \"const\" /* const/using/await using 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 if ((kind === \"var\" || kind === \"hoisted\") && isInitInLoop(path)) {\n this.reassign(path);\n }\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.includes(path)) {\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.includes(path)) {\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\nfunction isInitInLoop(path: NodePath) {\n const isFunctionDeclarationOrHasInit =\n !path.isVariableDeclarator() || path.node.init;\n for (\n let { parentPath, key } = path;\n parentPath;\n { parentPath, key } = parentPath\n ) {\n if (parentPath.isFunctionParent()) return false;\n if (\n (key === \"left\" && parentPath.isForXStatement()) ||\n (isFunctionDeclarationOrHasInit && key === \"body\" && parentPath.isLoop())\n ) {\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;;AAwBe,MAAMA,OAAO,CAAC;EAM3BC,WAAWA,CAAC;IACVC,UAAU;IACVC,KAAK;IACLC,IAAI;IACJC;EAMF,CAAC,EAAE;IAAA,KAfHH,UAAU;IAAA,KACVC,KAAK;IAAA,KACLC,IAAI;IAAA,KACJC,IAAI;IAAA,KAyBJC,kBAAkB,GAAoB,EAAE;IAAA,KACxCC,QAAQ,GAAY,IAAI;IAAA,KAExBC,cAAc,GAAoB,EAAE;IAAA,KACpCC,UAAU,GAAY,KAAK;IAAA,KAC3BC,UAAU,GAAW,CAAC;IAjBpB,IAAI,CAACR,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACC,KAAK,GAAGA,KAAK;IACl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;EACrC;AACF;AAACa,OAAA,CAAAC,OAAA,GAAAxB,OAAA;AAED,SAASW,YAAYA,CAACP,IAAc,EAAE;EACpC,MAAMqB,8BAA8B,GAClC,CAACrB,IAAI,CAACsB,oBAAoB,CAAC,CAAC,IAAItB,IAAI,CAACuB,IAAI,CAACC,IAAI;EAChD,KACE,IAAI;IAAEC,UAAU;IAAEC;EAAI,CAAC,GAAG1B,IAAI,EAC9ByB,UAAU,EACV;IAAEA,UAAU;IAAEC;EAAI,CAAC,GAAGD,UAAU,EAChC;IACA,IAAIA,UAAU,CAACE,gBAAgB,CAAC,CAAC,EAAE,OAAO,KAAK;IAC/C,IACGD,GAAG,KAAK,MAAM,IAAID,UAAU,CAACG,eAAe,CAAC,CAAC,IAC9CP,8BAA8B,IAAIK,GAAG,KAAK,MAAM,IAAID,UAAU,CAACI,MAAM,CAAC,CAAE,EACzE;MACA,OAAO,IAAI;IACb;EACF;EACA,OAAO,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["Binding","constructor","identifier","scope","path","kind","constantViolations","constant","referencePaths","referenced","references","isInitInLoop","reassign","clearValue","deoptValue","hasDeoptedValue","setValue","value","hasValue","includes","push","reference","dereference","exports","default","isFunctionDeclarationOrHasInit","isVariableDeclarator","node","init","parentPath","key","isFunctionParent","isForXStatement","isLoop"],"sources":["../../src/scope/binding.ts"],"sourcesContent":["import type NodePath from \"../path/index.ts\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"./index.ts\";\n\nexport type BindingKind =\n | \"var\" /* var declarator */\n | \"let\" /* let declarator, class declaration id, catch clause parameters */\n | \"const\" /* const/using/await using 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 if ((kind === \"var\" || kind === \"hoisted\") && isInitInLoop(path)) {\n this.reassign(path);\n }\n\n this.clearValue();\n }\n\n constantViolations: NodePath[] = [];\n constant: boolean = true;\n\n referencePaths: 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.includes(path)) {\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.includes(path)) {\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\nfunction isInitInLoop(path: NodePath) {\n const isFunctionDeclarationOrHasInit =\n !path.isVariableDeclarator() || path.node.init;\n for (\n let { parentPath, key } = path;\n parentPath;\n { parentPath, key } = parentPath\n ) {\n if (parentPath.isFunctionParent()) return false;\n if (\n (key === \"left\" && parentPath.isForXStatement()) ||\n (isFunctionDeclarationOrHasInit && key === \"body\" && parentPath.isLoop())\n ) {\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;;AAwBe,MAAMA,OA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I,CAACE,kBAAkB,CAACc,IAAI,CAAChB,IAAI,CAAC;EACpC;EAMAiB,SAASA,CAACjB,IAAc,EAAE;IACxB,IAAI,IAAI,CAACI,cAAc,CAACW,QAAQ,CAACf,IAAI,CAAC,EAAE;MACtC;IACF;IACA,IAAI,CAACK,UAAU,GAAG,IAAI;IACtB,IAAI,CAACC,UAAU,EAAE;IACjB,IAAI,CAACF,cAAc,CAACY,IAAI,CAAChB,IAAI,CAAC;EAChC;EAMAkB,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACZ,UAAU,EAAE;IACjB,IAAI,CAACD,UAAU,GAAG,CAAC,CAAC,IAAI,CAACC,UAAU;EACrC;AACF;AAACa,OAAA,CAAAC,OAAA,GAAAxB,OAAA;AAED,SAASW,YAAYA,CAACP,IAAc,EAAE;EACpC,MAAMqB,8BAA8B,GAClC,CAACrB,IAAI,CAACsB,oBAAoB,CAAC,CAAC,IAAItB,IAAI,CAACuB,IAAI,CAACC,IAAI;EAChD,KACE,IAAI;IAAEC,UAAU;IAAEC;EAAI,CAAC,GAAG1B,IAAI,EAC9ByB,UAAU,EACV;IAAEA,UAAU;IAAEC;EAAI,CAAC,GAAGD,UAAU,EAChC;IACA,IAAIA,UAAU,CAACE,gBAAgB,CAAC,CAAC,EAAE,OAAO,KAAK;IAC/C,IACGD,GAAG,KAAK,MAAM,IAAID,UAAU,CAACG,eAAe,CAAC,CAAC,IAC9CP,8BAA8B,IAAIK,GAAG,KAAK,MAAM,IAAID,UAAU,CAACI,MAAM,CAAC,CAAE,EACzE;MACA,OAAO,IAAI;IACb;EACF;EACA,OAAO,KAAK;AACd","ignoreList":[]}
@@ -53,8 +53,6 @@ const {
53
53
  toIdentifier,
54
54
  variableDeclaration,
55
55
  variableDeclarator,
56
- isRecordExpression,
57
- isTupleExpression,
58
56
  isObjectProperty,
59
57
  isTopicReference,
60
58
  isMetaProperty,
@@ -180,19 +178,15 @@ function gatherNodeParts(node, parts) {
180
178
  }
181
179
  }
182
180
  function resetScope(scope) {
183
- {
184
- scope.references = Object.create(null);
185
- scope.uids = Object.create(null);
186
- }
181
+ scope.references = Object.create(null);
182
+ scope.uids = Object.create(null);
187
183
  scope.bindings = Object.create(null);
188
184
  scope.globals = Object.create(null);
189
185
  }
190
186
  function isAnonymousFunctionExpression(path) {
191
187
  return path.isFunctionExpression() && !path.node.id || path.isArrowFunctionExpression();
192
188
  }
193
- {
194
- var NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding");
195
- }
189
+ var NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding");
196
190
  const collectorVisitor = {
197
191
  ForStatement(path) {
198
192
  const declar = path.get("init");
@@ -335,22 +329,20 @@ class Scope {
335
329
  this.path = path;
336
330
  this.labels = new Map();
337
331
  this.inited = false;
338
- {
339
- Object.defineProperties(this, {
340
- references: {
341
- enumerable: true,
342
- configurable: true,
343
- writable: true,
344
- value: Object.create(null)
345
- },
346
- uids: {
347
- enumerable: true,
348
- configurable: true,
349
- writable: true,
350
- value: Object.create(null)
351
- }
352
- });
353
- }
332
+ Object.defineProperties(this, {
333
+ references: {
334
+ enumerable: true,
335
+ configurable: true,
336
+ writable: true,
337
+ value: Object.create(null)
338
+ },
339
+ uids: {
340
+ enumerable: true,
341
+ configurable: true,
342
+ writable: true,
343
+ value: Object.create(null)
344
+ }
345
+ });
354
346
  }
355
347
  get parent() {
356
348
  var _parent;
@@ -391,10 +383,8 @@ class Scope {
391
383
  i++;
392
384
  } while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
393
385
  const program = this.getProgramParent();
394
- {
395
- program.references[uid] = true;
396
- program.uids[uid] = true;
397
- }
386
+ program.references[uid] = true;
387
+ program.uids[uid] = true;
398
388
  return uid;
399
389
  }
400
390
  generateUidBasedOnNode(node, defaultName) {
@@ -448,9 +438,7 @@ class Scope {
448
438
  if (binding) {
449
439
  newName || (newName = this.generateUidIdentifier(oldName).name);
450
440
  const renamer = new _renamer.default(binding, oldName, newName);
451
- {
452
- renamer.rename(arguments[2]);
453
- }
441
+ renamer.rename(arguments[2]);
454
442
  }
455
443
  }
456
444
  dump() {
@@ -534,9 +522,7 @@ class Scope {
534
522
  const parent = this.getProgramParent();
535
523
  const ids = path.getOuterBindingIdentifiers(true);
536
524
  for (const name of Object.keys(ids)) {
537
- {
538
- parent.references[name] = true;
539
- }
525
+ parent.references[name] = true;
540
526
  for (const id of ids[name]) {
541
527
  const local = this.getOwnBinding(name);
542
528
  if (local) {
@@ -560,13 +546,11 @@ class Scope {
560
546
  this.globals[node.name] = node;
561
547
  }
562
548
  hasUid(name) {
563
- {
564
- let scope = this;
565
- do {
566
- if (scope.uids[name]) return true;
567
- } while (scope = scope.parent);
568
- return false;
569
- }
549
+ let scope = this;
550
+ do {
551
+ if (scope.uids[name]) return true;
552
+ } while (scope = scope.parent);
553
+ return false;
570
554
  }
571
555
  hasGlobal(name) {
572
556
  let scope = this;
@@ -576,9 +560,7 @@ class Scope {
576
560
  return false;
577
561
  }
578
562
  hasReference(name) {
579
- {
580
- return !!this.getProgramParent().references[name];
581
- }
563
+ return !!this.getProgramParent().references[name];
582
564
  }
583
565
  isPure(node, constantsOnly) {
584
566
  if (isIdentifier(node)) {
@@ -604,12 +586,12 @@ class Scope {
604
586
  return true;
605
587
  } else if (isBinary(node)) {
606
588
  return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
607
- } else if (isArrayExpression(node) || isTupleExpression(node)) {
589
+ } else if (isArrayExpression(node) || (node == null ? void 0 : node.type) === "TupleExpression") {
608
590
  for (const elem of node.elements) {
609
591
  if (elem !== null && !this.isPure(elem, constantsOnly)) return false;
610
592
  }
611
593
  return true;
612
- } else if (isObjectExpression(node) || isRecordExpression(node)) {
594
+ } else if (isObjectExpression(node) || (node == null ? void 0 : node.type) === "RecordExpression") {
613
595
  for (const prop of node.properties) {
614
596
  if (!this.isPure(prop, constantsOnly)) return false;
615
597
  }
@@ -681,7 +663,6 @@ class Scope {
681
663
  }
682
664
  crawl() {
683
665
  const path = this.path;
684
- ;
685
666
  resetScope(this);
686
667
  this.data = Object.create(null);
687
668
  let scope = this;
@@ -711,9 +692,7 @@ class Scope {
711
692
  }
712
693
  }
713
694
  }
714
- {
715
- path.traverse(scopeVisitor, state);
716
- }
695
+ path.traverse(scopeVisitor, state);
717
696
  this.crawling = false;
718
697
  for (const path of state.assignments) {
719
698
  const ids = path.getAssignmentIdentifiers();
@@ -901,14 +880,12 @@ class Scope {
901
880
  removeBinding(name) {
902
881
  var _this$getBinding3;
903
882
  (_this$getBinding3 = this.getBinding(name)) == null || _this$getBinding3.scope.removeOwnBinding(name);
904
- {
905
- let scope = this;
906
- do {
907
- if (scope.uids[name]) {
908
- scope.uids[name] = false;
909
- }
910
- } while (scope = scope.parent);
911
- }
883
+ let scope = this;
884
+ do {
885
+ if (scope.uids[name]) {
886
+ scope.uids[name] = false;
887
+ }
888
+ } while (scope = scope.parent);
912
889
  }
913
890
  hoistVariables(emit = id => this.push({
914
891
  id
@@ -962,82 +939,80 @@ class Scope {
962
939
  exports.default = Scope;
963
940
  Scope.globals = [...globalsBuiltinLower, ...globalsBuiltinUpper];
964
941
  Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
965
- {
966
- Scope.prototype._renameFromMap = function _renameFromMap(map, oldName, newName, value) {
967
- if (map[oldName]) {
968
- map[newName] = value;
969
- map[oldName] = null;
970
- }
971
- };
972
- Scope.prototype.traverse = function (node, opts, state) {
973
- (0, _index.default)(node, opts, this, state, this.path);
974
- };
975
- Scope.prototype._generateUid = function _generateUid(name, i) {
976
- let id = name;
977
- if (i > 1) id += i;
978
- return `_${id}`;
979
- };
980
- Scope.prototype.toArray = function toArray(node, i, arrayLikeIsIterable) {
981
- if (isIdentifier(node)) {
982
- const binding = this.getBinding(node.name);
983
- if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
984
- return node;
985
- }
986
- }
987
- if (isArrayExpression(node)) {
942
+ Scope.prototype._renameFromMap = function _renameFromMap(map, oldName, newName, value) {
943
+ if (map[oldName]) {
944
+ map[newName] = value;
945
+ map[oldName] = null;
946
+ }
947
+ };
948
+ Scope.prototype.traverse = function (node, opts, state) {
949
+ (0, _index.default)(node, opts, this, state, this.path);
950
+ };
951
+ Scope.prototype._generateUid = function _generateUid(name, i) {
952
+ let id = name;
953
+ if (i > 1) id += i;
954
+ return `_${id}`;
955
+ };
956
+ Scope.prototype.toArray = function toArray(node, i, arrayLikeIsIterable) {
957
+ if (isIdentifier(node)) {
958
+ const binding = this.getBinding(node.name);
959
+ if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
988
960
  return node;
989
961
  }
990
- if (isIdentifier(node, {
991
- name: "arguments"
992
- })) {
993
- return callExpression(memberExpression(memberExpression(memberExpression(identifier("Array"), identifier("prototype")), identifier("slice")), identifier("call")), [node]);
994
- }
995
- let helperName;
996
- const args = [node];
997
- if (i === true) {
998
- helperName = "toConsumableArray";
999
- } else if (typeof i === "number") {
1000
- args.push(numericLiteral(i));
1001
- helperName = "slicedToArray";
1002
- } else {
1003
- helperName = "toArray";
1004
- }
1005
- if (arrayLikeIsIterable) {
1006
- args.unshift(this.path.hub.addHelper(helperName));
1007
- helperName = "maybeArrayLike";
1008
- }
1009
- return callExpression(this.path.hub.addHelper(helperName), args);
1010
- };
1011
- Scope.prototype.getAllBindingsOfKind = function getAllBindingsOfKind(...kinds) {
1012
- const ids = Object.create(null);
1013
- for (const kind of kinds) {
1014
- let scope = this;
1015
- do {
1016
- for (const name of Object.keys(scope.bindings)) {
1017
- const binding = scope.bindings[name];
1018
- if (binding.kind === kind) ids[name] = binding;
1019
- }
1020
- scope = scope.parent;
1021
- } while (scope);
1022
- }
1023
- return ids;
1024
- };
1025
- Object.defineProperties(Scope.prototype, {
1026
- parentBlock: {
1027
- configurable: true,
1028
- enumerable: true,
1029
- get() {
1030
- return this.path.parent;
1031
- }
1032
- },
1033
- hub: {
1034
- configurable: true,
1035
- enumerable: true,
1036
- get() {
1037
- return this.path.hub;
962
+ }
963
+ if (isArrayExpression(node)) {
964
+ return node;
965
+ }
966
+ if (isIdentifier(node, {
967
+ name: "arguments"
968
+ })) {
969
+ return callExpression(memberExpression(memberExpression(memberExpression(identifier("Array"), identifier("prototype")), identifier("slice")), identifier("call")), [node]);
970
+ }
971
+ let helperName;
972
+ const args = [node];
973
+ if (i === true) {
974
+ helperName = "toConsumableArray";
975
+ } else if (typeof i === "number") {
976
+ args.push(numericLiteral(i));
977
+ helperName = "slicedToArray";
978
+ } else {
979
+ helperName = "toArray";
980
+ }
981
+ if (arrayLikeIsIterable) {
982
+ args.unshift(this.path.hub.addHelper(helperName));
983
+ helperName = "maybeArrayLike";
984
+ }
985
+ return callExpression(this.path.hub.addHelper(helperName), args);
986
+ };
987
+ Scope.prototype.getAllBindingsOfKind = function getAllBindingsOfKind(...kinds) {
988
+ const ids = Object.create(null);
989
+ for (const kind of kinds) {
990
+ let scope = this;
991
+ do {
992
+ for (const name of Object.keys(scope.bindings)) {
993
+ const binding = scope.bindings[name];
994
+ if (binding.kind === kind) ids[name] = binding;
1038
995
  }
996
+ scope = scope.parent;
997
+ } while (scope);
998
+ }
999
+ return ids;
1000
+ };
1001
+ Object.defineProperties(Scope.prototype, {
1002
+ parentBlock: {
1003
+ configurable: true,
1004
+ enumerable: true,
1005
+ get() {
1006
+ return this.path.parent;
1039
1007
  }
1040
- });
1041
- }
1008
+ },
1009
+ hub: {
1010
+ configurable: true,
1011
+ enumerable: true,
1012
+ get() {
1013
+ return this.path.hub;
1014
+ }
1015
+ }
1016
+ });
1042
1017
 
1043
1018
  //# sourceMappingURL=index.js.map