@babel/traverse 7.20.10 → 7.20.12

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 (49) hide show
  1. package/lib/context.js +2 -14
  2. package/lib/context.js.map +1 -1
  3. package/lib/index.js +1 -4
  4. package/lib/index.js.map +1 -1
  5. package/lib/path/ancestry.js +0 -19
  6. package/lib/path/ancestry.js.map +1 -1
  7. package/lib/path/comments.js +0 -2
  8. package/lib/path/comments.js.map +1 -1
  9. package/lib/path/context.js +5 -21
  10. package/lib/path/context.js.map +1 -1
  11. package/lib/path/conversion.js +6 -30
  12. package/lib/path/conversion.js.map +1 -1
  13. package/lib/path/evaluation.js +14 -20
  14. package/lib/path/evaluation.js.map +1 -1
  15. package/lib/path/family.js +3 -9
  16. package/lib/path/family.js.map +1 -1
  17. package/lib/path/index.js +1 -6
  18. package/lib/path/index.js.map +1 -1
  19. package/lib/path/inference/index.js +1 -9
  20. package/lib/path/inference/index.js.map +1 -1
  21. package/lib/path/inference/inferer-reference.js +1 -13
  22. package/lib/path/inference/inferer-reference.js.map +1 -1
  23. package/lib/path/inference/inferers.js +2 -5
  24. package/lib/path/inference/inferers.js.map +1 -1
  25. package/lib/path/introspection.js +1 -45
  26. package/lib/path/introspection.js.map +1 -1
  27. package/lib/path/lib/hoister.js +1 -22
  28. package/lib/path/lib/hoister.js.map +1 -1
  29. package/lib/path/lib/removal-hooks.js +1 -7
  30. package/lib/path/lib/removal-hooks.js.map +1 -1
  31. package/lib/path/lib/virtual-types-validator.js +0 -2
  32. package/lib/path/lib/virtual-types-validator.js.map +1 -1
  33. package/lib/path/lib/virtual-types.js +0 -1
  34. package/lib/path/lib/virtual-types.js.map +1 -1
  35. package/lib/path/modification.js +7 -24
  36. package/lib/path/modification.js.map +1 -1
  37. package/lib/path/removal.js +0 -1
  38. package/lib/path/removal.js.map +1 -1
  39. package/lib/path/replacement.js +2 -16
  40. package/lib/path/replacement.js.map +1 -1
  41. package/lib/scope/binding.js +1 -6
  42. package/lib/scope/binding.js.map +1 -1
  43. package/lib/scope/index.js +5 -50
  44. package/lib/scope/index.js.map +1 -1
  45. package/lib/scope/lib/renamer.js +1 -6
  46. package/lib/scope/lib/renamer.js.map +1 -1
  47. package/lib/visitors.js +2 -23
  48. package/lib/visitors.js.map +1 -1
  49. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["VALID_CALLEES","INVALID_METHODS","isValidCallee","val","includes","isInvalidMethod","evaluateTruthy","res","evaluate","confident","value","deopt","path","state","deoptPath","evaluateCached","node","seen","has","existing","get","resolved","item","set","_evaluate","isSequenceExpression","exprs","length","isStringLiteral","isNumericLiteral","isBooleanLiteral","isNullLiteral","isTemplateLiteral","evaluateQuasis","quasis","isTaggedTemplateExpression","isMemberExpression","object","name","property","isIdentifier","scope","getBinding","quasi","isConditionalExpression","testResult","isExpressionWrapper","parentPath","isCallExpression","callee","isLiteral","type","isReferencedIdentifier","binding","constantViolations","start","end","hasValue","undefined","Infinity","NaN","resolve","isUnaryExpression","prefix","operator","argument","isFunction","isClass","arg","isArrayExpression","arr","elems","elem","elemValue","push","isObjectExpression","obj","props","prop","isObjectMethod","isSpreadElement","keyPath","key","computed","valuePath","isLogicalExpression","wasConfident","left","leftConfident","right","rightConfident","isBinaryExpression","context","func","global","args","map","apply","raw","str","i","cooked","expr","String","Map"],"sources":["../../src/path/evaluation.ts"],"sourcesContent":["import type NodePath from \"./index\";\nimport type * as t from \"@babel/types\";\n\n// This file contains Babels metainterpreter that can evaluate static code.\n\nconst VALID_CALLEES = [\"String\", \"Number\", \"Math\"] as const;\nconst INVALID_METHODS = [\"random\"] as const;\n\nfunction isValidCallee(val: string): val is typeof VALID_CALLEES[number] {\n return VALID_CALLEES.includes(\n // @ts-expect-error val is a string\n val,\n );\n}\n\nfunction isInvalidMethod(val: string): val is typeof INVALID_METHODS[number] {\n return INVALID_METHODS.includes(\n // @ts-expect-error val is a string\n val,\n );\n}\n\n/**\n * Walk the input `node` and statically evaluate if it's truthy.\n *\n * Returning `true` when we're sure that the expression will evaluate to a\n * truthy value, `false` if we're sure that it will evaluate to a falsy\n * value and `undefined` if we aren't sure. Because of this please do not\n * rely on coercion when using this method and check with === if it's false.\n *\n * For example do:\n *\n * if (t.evaluateTruthy(node) === false) falsyLogic();\n *\n * **AND NOT**\n *\n * if (!t.evaluateTruthy(node)) falsyLogic();\n *\n */\n\nexport function evaluateTruthy(this: NodePath): boolean {\n const res = this.evaluate();\n if (res.confident) return !!res.value;\n}\n\ntype State = {\n confident: boolean;\n deoptPath: NodePath | null;\n seen: Map<t.Node, Result>;\n};\n\ntype Result = {\n resolved: boolean;\n value?: any;\n};\n/**\n * Deopts the evaluation\n */\nfunction deopt(path: NodePath, state: State) {\n if (!state.confident) return;\n state.deoptPath = path;\n state.confident = false;\n}\n\n/**\n * We wrap the _evaluate method so we can track `seen` nodes, we push an item\n * to the map before we actually evaluate it so we can deopt on self recursive\n * nodes such as:\n *\n * var g = a ? 1 : 2,\n * a = g * this.foo\n */\nfunction evaluateCached(path: NodePath, state: State): any {\n const { node } = path;\n const { seen } = state;\n\n if (seen.has(node)) {\n const existing = seen.get(node);\n if (existing.resolved) {\n return existing.value;\n } else {\n deopt(path, state);\n return;\n }\n } else {\n const item: Result = { resolved: false };\n seen.set(node, item);\n\n const val = _evaluate(path, state);\n if (state.confident) {\n item.resolved = true;\n item.value = val;\n }\n return val;\n }\n}\n\nfunction _evaluate(path: NodePath, state: State): any {\n if (!state.confident) return;\n\n if (path.isSequenceExpression()) {\n const exprs = path.get(\"expressions\");\n return evaluateCached(exprs[exprs.length - 1], state);\n }\n\n if (\n path.isStringLiteral() ||\n path.isNumericLiteral() ||\n path.isBooleanLiteral()\n ) {\n return path.node.value;\n }\n\n if (path.isNullLiteral()) {\n return null;\n }\n\n if (path.isTemplateLiteral()) {\n return evaluateQuasis(path, path.node.quasis, state);\n }\n\n if (\n path.isTaggedTemplateExpression() &&\n path.get(\"tag\").isMemberExpression()\n ) {\n const object = path.get(\"tag.object\") as NodePath;\n const {\n // @ts-expect-error todo(flow->ts): possible bug, object is can be any expression and so name might be undefined\n node: { name },\n } = object;\n const property = path.get(\"tag.property\") as NodePath;\n\n if (\n object.isIdentifier() &&\n name === \"String\" &&\n // todo(flow->ts): was changed from getBinding(name, true)\n // should this be hasBinding(name, true) as the binding is never used later?\n !path.scope.getBinding(name) &&\n property.isIdentifier() &&\n property.node.name === \"raw\"\n ) {\n return evaluateQuasis(path, path.node.quasi.quasis, state, true);\n }\n }\n\n if (path.isConditionalExpression()) {\n const testResult = evaluateCached(path.get(\"test\"), state);\n if (!state.confident) return;\n if (testResult) {\n return evaluateCached(path.get(\"consequent\"), state);\n } else {\n return evaluateCached(path.get(\"alternate\"), state);\n }\n }\n\n if (path.isExpressionWrapper()) {\n // TypeCastExpression, ExpressionStatement etc\n return evaluateCached(path.get(\"expression\"), state);\n }\n\n // \"foo\".length\n if (\n path.isMemberExpression() &&\n !path.parentPath.isCallExpression({ callee: path.node })\n ) {\n const property = path.get(\"property\");\n const object = path.get(\"object\");\n\n if (object.isLiteral() && property.isIdentifier()) {\n // @ts-expect-error todo(flow->ts): instead of typeof - would it be better to check type of ast node?\n const value = object.node.value;\n const type = typeof value;\n if (type === \"number\" || type === \"string\") {\n return value[property.node.name];\n }\n }\n }\n\n if (path.isReferencedIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding && binding.constantViolations.length > 0) {\n return deopt(binding.path, state);\n }\n\n if (binding && path.node.start < binding.path.node.end) {\n return deopt(binding.path, state);\n }\n\n if (binding?.hasValue) {\n return binding.value;\n } else {\n if (path.node.name === \"undefined\") {\n return binding ? deopt(binding.path, state) : undefined;\n } else if (path.node.name === \"Infinity\") {\n return binding ? deopt(binding.path, state) : Infinity;\n } else if (path.node.name === \"NaN\") {\n return binding ? deopt(binding.path, state) : NaN;\n }\n\n const resolved = path.resolve();\n if (resolved === path) {\n return deopt(path, state);\n } else {\n return evaluateCached(resolved, state);\n }\n }\n }\n\n if (path.isUnaryExpression({ prefix: true })) {\n if (path.node.operator === \"void\") {\n // we don't need to evaluate the argument to know what this will return\n return undefined;\n }\n\n const argument = path.get(\"argument\");\n if (\n path.node.operator === \"typeof\" &&\n (argument.isFunction() || argument.isClass())\n ) {\n return \"function\";\n }\n\n const arg = evaluateCached(argument, state);\n if (!state.confident) return;\n switch (path.node.operator) {\n case \"!\":\n return !arg;\n case \"+\":\n return +arg;\n case \"-\":\n return -arg;\n case \"~\":\n return ~arg;\n case \"typeof\":\n return typeof arg;\n }\n }\n\n if (path.isArrayExpression()) {\n const arr = [];\n const elems: Array<NodePath> = path.get(\"elements\");\n for (const elem of elems) {\n const elemValue = elem.evaluate();\n\n if (elemValue.confident) {\n arr.push(elemValue.value);\n } else {\n return deopt(elemValue.deopt, state);\n }\n }\n return arr;\n }\n\n if (path.isObjectExpression()) {\n const obj = {};\n const props = path.get(\"properties\");\n for (const prop of props) {\n if (prop.isObjectMethod() || prop.isSpreadElement()) {\n return deopt(prop, state);\n }\n const keyPath = (prop as NodePath<t.ObjectProperty>).get(\"key\");\n let key;\n // @ts-expect-error todo(flow->ts): type refinement issues ObjectMethod and SpreadElement somehow not excluded\n if (prop.node.computed) {\n key = keyPath.evaluate();\n if (!key.confident) {\n return deopt(key.deopt, state);\n }\n key = key.value;\n } else if (keyPath.isIdentifier()) {\n key = keyPath.node.name;\n } else {\n key = (\n keyPath.node as t.StringLiteral | t.NumericLiteral | t.BigIntLiteral\n ).value;\n }\n const valuePath = (prop as NodePath<t.ObjectProperty>).get(\"value\");\n let value = valuePath.evaluate();\n if (!value.confident) {\n return deopt(value.deopt, state);\n }\n value = value.value;\n // @ts-expect-error key is any type\n obj[key] = value;\n }\n return obj;\n }\n\n if (path.isLogicalExpression()) {\n // If we are confident that the left side of an && is false, or the left\n // side of an || is true, we can be confident about the entire expression\n const wasConfident = state.confident;\n const left = evaluateCached(path.get(\"left\"), state);\n const leftConfident = state.confident;\n state.confident = wasConfident;\n const right = evaluateCached(path.get(\"right\"), state);\n const rightConfident = state.confident;\n\n switch (path.node.operator) {\n case \"||\":\n // TODO consider having a \"truthy type\" that doesn't bail on\n // left uncertainty but can still evaluate to truthy.\n state.confident = leftConfident && (!!left || rightConfident);\n if (!state.confident) return;\n\n return left || right;\n case \"&&\":\n state.confident = leftConfident && (!left || rightConfident);\n if (!state.confident) return;\n\n return left && right;\n case \"??\":\n state.confident = leftConfident && (left != null || rightConfident);\n if (!state.confident) return;\n\n return left ?? right;\n }\n }\n\n if (path.isBinaryExpression()) {\n const left = evaluateCached(path.get(\"left\"), state);\n if (!state.confident) return;\n const right = evaluateCached(path.get(\"right\"), state);\n if (!state.confident) return;\n\n switch (path.node.operator) {\n case \"-\":\n return left - right;\n case \"+\":\n return left + right;\n case \"/\":\n return left / right;\n case \"*\":\n return left * right;\n case \"%\":\n return left % right;\n case \"**\":\n return left ** right;\n case \"<\":\n return left < right;\n case \">\":\n return left > right;\n case \"<=\":\n return left <= right;\n case \">=\":\n return left >= right;\n case \"==\":\n return left == right; // eslint-disable-line eqeqeq\n case \"!=\":\n return left != right;\n case \"===\":\n return left === right;\n case \"!==\":\n return left !== right;\n case \"|\":\n return left | right;\n case \"&\":\n return left & right;\n case \"^\":\n return left ^ right;\n case \"<<\":\n return left << right;\n case \">>\":\n return left >> right;\n case \">>>\":\n return left >>> right;\n }\n }\n\n if (path.isCallExpression()) {\n const callee = path.get(\"callee\");\n let context;\n let func;\n\n // Number(1);\n if (\n callee.isIdentifier() &&\n !path.scope.getBinding(callee.node.name) &&\n isValidCallee(callee.node.name)\n ) {\n func = global[callee.node.name];\n }\n\n if (callee.isMemberExpression()) {\n const object = callee.get(\"object\");\n const property = callee.get(\"property\");\n\n // Math.min(1, 2)\n if (\n object.isIdentifier() &&\n property.isIdentifier() &&\n isValidCallee(object.node.name) &&\n !isInvalidMethod(property.node.name)\n ) {\n context = global[object.node.name];\n // @ts-expect-error property may not exist in context object\n func = context[property.node.name];\n }\n\n // \"abc\".charCodeAt(4)\n if (object.isLiteral() && property.isIdentifier()) {\n // @ts-expect-error todo(flow->ts): consider checking ast node type instead of value type (StringLiteral and NumberLiteral)\n const type = typeof object.node.value;\n if (type === \"string\" || type === \"number\") {\n // @ts-expect-error todo(flow->ts): consider checking ast node type instead of value type\n context = object.node.value;\n func = context[property.node.name];\n }\n }\n }\n\n if (func) {\n const args = path.get(\"arguments\").map(arg => evaluateCached(arg, state));\n if (!state.confident) return;\n\n return func.apply(context, args);\n }\n }\n\n deopt(path, state);\n}\n\nfunction evaluateQuasis(\n path: NodePath<t.TaggedTemplateExpression | t.TemplateLiteral>,\n quasis: Array<any>,\n state: State,\n raw = false,\n) {\n let str = \"\";\n\n let i = 0;\n const exprs = path.get(\"expressions\");\n\n for (const elem of quasis) {\n // not confident, evaluated an expression we don't like\n if (!state.confident) break;\n\n // add on element\n str += raw ? elem.value.raw : elem.value.cooked;\n\n // add on interpolated expression if it's present\n const expr = exprs[i++];\n if (expr) str += String(evaluateCached(expr, state));\n }\n\n if (!state.confident) return;\n return str;\n}\n\n/**\n * Walk the input `node` and statically evaluate it.\n *\n * Returns an object in the form `{ confident, value, deopt }`. `confident`\n * indicates whether or not we had to drop out of evaluating the expression\n * because of hitting an unknown node that we couldn't confidently find the\n * value of, in which case `deopt` is the path of said node.\n *\n * Example:\n *\n * t.evaluate(parse(\"5 + 5\")) // { confident: true, value: 10 }\n * t.evaluate(parse(\"!true\")) // { confident: true, value: false }\n * t.evaluate(parse(\"foo + foo\")) // { confident: false, value: undefined, deopt: NodePath }\n *\n */\n\nexport function evaluate(this: NodePath): {\n confident: boolean;\n value: any;\n deopt?: NodePath;\n} {\n const state: State = {\n confident: true,\n deoptPath: null,\n seen: new Map(),\n };\n let value = evaluateCached(this, state);\n if (!state.confident) value = undefined;\n\n return {\n confident: state.confident,\n deopt: state.deoptPath,\n value: value,\n };\n}\n"],"mappings":";;;;;;;;AAKA,MAAMA,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uF,IAAI,EAAEzF,KAAK,CAAC,CAAC;EACtD;EAEA,IAAI,CAACA,KAAK,CAACJ,SAAS,EAAE;EACtB,OAAO0F,GAAG;AACZ;;AAkBO,SAAS3F,QAAQ,GAItB;EACA,MAAMK,KAAY,GAAG;IACnBJ,SAAS,EAAE,IAAI;IACfK,SAAS,EAAE,IAAI;IACfG,IAAI,EAAE,IAAIuF,GAAG;EACf,CAAC;EACD,IAAI9F,KAAK,GAAGK,cAAc,CAAC,IAAI,EAAEF,KAAK,CAAC;EACvC,IAAI,CAACA,KAAK,CAACJ,SAAS,EAAEC,KAAK,GAAGgD,SAAS;EAEvC,OAAO;IACLjD,SAAS,EAAEI,KAAK,CAACJ,SAAS;IAC1BE,KAAK,EAAEE,KAAK,CAACC,SAAS;IACtBJ,KAAK,EAAEA;EACT,CAAC;AACH"}
1
+ {"version":3,"names":["VALID_CALLEES","INVALID_METHODS","isValidCallee","val","includes","isInvalidMethod","evaluateTruthy","res","evaluate","confident","value","deopt","path","state","deoptPath","evaluateCached","node","seen","has","existing","get","resolved","item","set","_evaluate","isSequenceExpression","exprs","length","isStringLiteral","isNumericLiteral","isBooleanLiteral","isNullLiteral","isTemplateLiteral","evaluateQuasis","quasis","isTaggedTemplateExpression","isMemberExpression","object","name","property","isIdentifier","scope","getBinding","quasi","isConditionalExpression","testResult","isExpressionWrapper","parentPath","isCallExpression","callee","isLiteral","type","key","computed","isReferencedIdentifier","binding","constantViolations","start","end","hasValue","undefined","Infinity","NaN","resolve","isUnaryExpression","prefix","operator","argument","isFunction","isClass","arg","isArrayExpression","arr","elems","elem","elemValue","push","isObjectExpression","obj","props","prop","isObjectMethod","isSpreadElement","keyPath","valuePath","isLogicalExpression","wasConfident","left","leftConfident","right","rightConfident","isBinaryExpression","context","func","global","args","map","apply","raw","str","i","cooked","expr","String","Map"],"sources":["../../src/path/evaluation.ts"],"sourcesContent":["import type NodePath from \"./index\";\nimport type * as t from \"@babel/types\";\n\n// This file contains Babels metainterpreter that can evaluate static code.\n\nconst VALID_CALLEES = [\"String\", \"Number\", \"Math\"] as const;\nconst INVALID_METHODS = [\"random\"] as const;\n\nfunction isValidCallee(val: string): val is typeof VALID_CALLEES[number] {\n return VALID_CALLEES.includes(\n // @ts-expect-error val is a string\n val,\n );\n}\n\nfunction isInvalidMethod(val: string): val is typeof INVALID_METHODS[number] {\n return INVALID_METHODS.includes(\n // @ts-expect-error val is a string\n val,\n );\n}\n\n/**\n * Walk the input `node` and statically evaluate if it's truthy.\n *\n * Returning `true` when we're sure that the expression will evaluate to a\n * truthy value, `false` if we're sure that it will evaluate to a falsy\n * value and `undefined` if we aren't sure. Because of this please do not\n * rely on coercion when using this method and check with === if it's false.\n *\n * For example do:\n *\n * if (t.evaluateTruthy(node) === false) falsyLogic();\n *\n * **AND NOT**\n *\n * if (!t.evaluateTruthy(node)) falsyLogic();\n *\n */\n\nexport function evaluateTruthy(this: NodePath): boolean {\n const res = this.evaluate();\n if (res.confident) return !!res.value;\n}\n\ntype State = {\n confident: boolean;\n deoptPath: NodePath | null;\n seen: Map<t.Node, Result>;\n};\n\ntype Result = {\n resolved: boolean;\n value?: any;\n};\n/**\n * Deopts the evaluation\n */\nfunction deopt(path: NodePath, state: State) {\n if (!state.confident) return;\n state.deoptPath = path;\n state.confident = false;\n}\n\n/**\n * We wrap the _evaluate method so we can track `seen` nodes, we push an item\n * to the map before we actually evaluate it so we can deopt on self recursive\n * nodes such as:\n *\n * var g = a ? 1 : 2,\n * a = g * this.foo\n */\nfunction evaluateCached(path: NodePath, state: State): any {\n const { node } = path;\n const { seen } = state;\n\n if (seen.has(node)) {\n const existing = seen.get(node);\n if (existing.resolved) {\n return existing.value;\n } else {\n deopt(path, state);\n return;\n }\n } else {\n const item: Result = { resolved: false };\n seen.set(node, item);\n\n const val = _evaluate(path, state);\n if (state.confident) {\n item.resolved = true;\n item.value = val;\n }\n return val;\n }\n}\n\nfunction _evaluate(path: NodePath, state: State): any {\n if (!state.confident) return;\n\n if (path.isSequenceExpression()) {\n const exprs = path.get(\"expressions\");\n return evaluateCached(exprs[exprs.length - 1], state);\n }\n\n if (\n path.isStringLiteral() ||\n path.isNumericLiteral() ||\n path.isBooleanLiteral()\n ) {\n return path.node.value;\n }\n\n if (path.isNullLiteral()) {\n return null;\n }\n\n if (path.isTemplateLiteral()) {\n return evaluateQuasis(path, path.node.quasis, state);\n }\n\n if (\n path.isTaggedTemplateExpression() &&\n path.get(\"tag\").isMemberExpression()\n ) {\n const object = path.get(\"tag.object\") as NodePath;\n const {\n // @ts-expect-error todo(flow->ts): possible bug, object is can be any expression and so name might be undefined\n node: { name },\n } = object;\n const property = path.get(\"tag.property\") as NodePath;\n\n if (\n object.isIdentifier() &&\n name === \"String\" &&\n // todo(flow->ts): was changed from getBinding(name, true)\n // should this be hasBinding(name, true) as the binding is never used later?\n !path.scope.getBinding(name) &&\n property.isIdentifier() &&\n property.node.name === \"raw\"\n ) {\n return evaluateQuasis(path, path.node.quasi.quasis, state, true);\n }\n }\n\n if (path.isConditionalExpression()) {\n const testResult = evaluateCached(path.get(\"test\"), state);\n if (!state.confident) return;\n if (testResult) {\n return evaluateCached(path.get(\"consequent\"), state);\n } else {\n return evaluateCached(path.get(\"alternate\"), state);\n }\n }\n\n if (path.isExpressionWrapper()) {\n // TypeCastExpression, ExpressionStatement etc\n return evaluateCached(path.get(\"expression\"), state);\n }\n\n // \"foo\".length, \"foo\"[0]\n if (\n path.isMemberExpression() &&\n !path.parentPath.isCallExpression({ callee: path.node })\n ) {\n const property = path.get(\"property\");\n const object = path.get(\"object\");\n\n if (object.isLiteral()) {\n // @ts-expect-error todo(flow->ts): instead of typeof - would it be better to check type of ast node?\n const value = object.node.value;\n const type = typeof value;\n\n let key = null;\n if (path.node.computed) {\n key = evaluateCached(property, state);\n if (!state.confident) return;\n } else if (property.isIdentifier()) {\n key = property.node.name;\n }\n if (\n (type === \"number\" || type === \"string\") &&\n key != null &&\n (typeof key === \"number\" || typeof key === \"string\")\n ) {\n return value[key];\n }\n }\n }\n\n if (path.isReferencedIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding && binding.constantViolations.length > 0) {\n return deopt(binding.path, state);\n }\n\n if (binding && path.node.start < binding.path.node.end) {\n return deopt(binding.path, state);\n }\n\n if (binding?.hasValue) {\n return binding.value;\n } else {\n if (path.node.name === \"undefined\") {\n return binding ? deopt(binding.path, state) : undefined;\n } else if (path.node.name === \"Infinity\") {\n return binding ? deopt(binding.path, state) : Infinity;\n } else if (path.node.name === \"NaN\") {\n return binding ? deopt(binding.path, state) : NaN;\n }\n\n const resolved = path.resolve();\n if (resolved === path) {\n return deopt(path, state);\n } else {\n return evaluateCached(resolved, state);\n }\n }\n }\n\n if (path.isUnaryExpression({ prefix: true })) {\n if (path.node.operator === \"void\") {\n // we don't need to evaluate the argument to know what this will return\n return undefined;\n }\n\n const argument = path.get(\"argument\");\n if (\n path.node.operator === \"typeof\" &&\n (argument.isFunction() || argument.isClass())\n ) {\n return \"function\";\n }\n\n const arg = evaluateCached(argument, state);\n if (!state.confident) return;\n switch (path.node.operator) {\n case \"!\":\n return !arg;\n case \"+\":\n return +arg;\n case \"-\":\n return -arg;\n case \"~\":\n return ~arg;\n case \"typeof\":\n return typeof arg;\n }\n }\n\n if (path.isArrayExpression()) {\n const arr = [];\n const elems: Array<NodePath> = path.get(\"elements\");\n for (const elem of elems) {\n const elemValue = elem.evaluate();\n\n if (elemValue.confident) {\n arr.push(elemValue.value);\n } else {\n return deopt(elemValue.deopt, state);\n }\n }\n return arr;\n }\n\n if (path.isObjectExpression()) {\n const obj = {};\n const props = path.get(\"properties\");\n for (const prop of props) {\n if (prop.isObjectMethod() || prop.isSpreadElement()) {\n return deopt(prop, state);\n }\n const keyPath = (prop as NodePath<t.ObjectProperty>).get(\"key\");\n let key;\n // @ts-expect-error todo(flow->ts): type refinement issues ObjectMethod and SpreadElement somehow not excluded\n if (prop.node.computed) {\n key = keyPath.evaluate();\n if (!key.confident) {\n return deopt(key.deopt, state);\n }\n key = key.value;\n } else if (keyPath.isIdentifier()) {\n key = keyPath.node.name;\n } else {\n key = (\n keyPath.node as t.StringLiteral | t.NumericLiteral | t.BigIntLiteral\n ).value;\n }\n const valuePath = (prop as NodePath<t.ObjectProperty>).get(\"value\");\n let value = valuePath.evaluate();\n if (!value.confident) {\n return deopt(value.deopt, state);\n }\n value = value.value;\n // @ts-expect-error key is any type\n obj[key] = value;\n }\n return obj;\n }\n\n if (path.isLogicalExpression()) {\n // If we are confident that the left side of an && is false, or the left\n // side of an || is true, we can be confident about the entire expression\n const wasConfident = state.confident;\n const left = evaluateCached(path.get(\"left\"), state);\n const leftConfident = state.confident;\n state.confident = wasConfident;\n const right = evaluateCached(path.get(\"right\"), state);\n const rightConfident = state.confident;\n\n switch (path.node.operator) {\n case \"||\":\n // TODO consider having a \"truthy type\" that doesn't bail on\n // left uncertainty but can still evaluate to truthy.\n state.confident = leftConfident && (!!left || rightConfident);\n if (!state.confident) return;\n\n return left || right;\n case \"&&\":\n state.confident = leftConfident && (!left || rightConfident);\n if (!state.confident) return;\n\n return left && right;\n case \"??\":\n state.confident = leftConfident && (left != null || rightConfident);\n if (!state.confident) return;\n\n return left ?? right;\n }\n }\n\n if (path.isBinaryExpression()) {\n const left = evaluateCached(path.get(\"left\"), state);\n if (!state.confident) return;\n const right = evaluateCached(path.get(\"right\"), state);\n if (!state.confident) return;\n\n switch (path.node.operator) {\n case \"-\":\n return left - right;\n case \"+\":\n return left + right;\n case \"/\":\n return left / right;\n case \"*\":\n return left * right;\n case \"%\":\n return left % right;\n case \"**\":\n return left ** right;\n case \"<\":\n return left < right;\n case \">\":\n return left > right;\n case \"<=\":\n return left <= right;\n case \">=\":\n return left >= right;\n case \"==\":\n return left == right; // eslint-disable-line eqeqeq\n case \"!=\":\n return left != right;\n case \"===\":\n return left === right;\n case \"!==\":\n return left !== right;\n case \"|\":\n return left | right;\n case \"&\":\n return left & right;\n case \"^\":\n return left ^ right;\n case \"<<\":\n return left << right;\n case \">>\":\n return left >> right;\n case \">>>\":\n return left >>> right;\n }\n }\n\n if (path.isCallExpression()) {\n const callee = path.get(\"callee\");\n let context;\n let func;\n\n // Number(1);\n if (\n callee.isIdentifier() &&\n !path.scope.getBinding(callee.node.name) &&\n isValidCallee(callee.node.name)\n ) {\n func = global[callee.node.name];\n }\n\n if (callee.isMemberExpression()) {\n const object = callee.get(\"object\");\n const property = callee.get(\"property\");\n\n // Math.min(1, 2)\n if (\n object.isIdentifier() &&\n property.isIdentifier() &&\n isValidCallee(object.node.name) &&\n !isInvalidMethod(property.node.name)\n ) {\n context = global[object.node.name];\n // @ts-expect-error property may not exist in context object\n func = context[property.node.name];\n }\n\n // \"abc\".charCodeAt(4)\n if (object.isLiteral() && property.isIdentifier()) {\n // @ts-expect-error todo(flow->ts): consider checking ast node type instead of value type (StringLiteral and NumberLiteral)\n const type = typeof object.node.value;\n if (type === \"string\" || type === \"number\") {\n // @ts-expect-error todo(flow->ts): consider checking ast node type instead of value type\n context = object.node.value;\n func = context[property.node.name];\n }\n }\n }\n\n if (func) {\n const args = path.get(\"arguments\").map(arg => evaluateCached(arg, state));\n if (!state.confident) return;\n\n return func.apply(context, args);\n }\n }\n\n deopt(path, state);\n}\n\nfunction evaluateQuasis(\n path: NodePath<t.TaggedTemplateExpression | t.TemplateLiteral>,\n quasis: Array<any>,\n state: State,\n raw = false,\n) {\n let str = \"\";\n\n let i = 0;\n const exprs: Array<NodePath<t.Node>> = path.isTemplateLiteral()\n ? path.get(\"expressions\")\n : path.get(\"quasi.expressions\");\n\n for (const elem of quasis) {\n // not confident, evaluated an expression we don't like\n if (!state.confident) break;\n\n // add on element\n str += raw ? elem.value.raw : elem.value.cooked;\n\n // add on interpolated expression if it's present\n const expr = exprs[i++];\n if (expr) str += String(evaluateCached(expr, state));\n }\n\n if (!state.confident) return;\n return str;\n}\n\n/**\n * Walk the input `node` and statically evaluate it.\n *\n * Returns an object in the form `{ confident, value, deopt }`. `confident`\n * indicates whether or not we had to drop out of evaluating the expression\n * because of hitting an unknown node that we couldn't confidently find the\n * value of, in which case `deopt` is the path of said node.\n *\n * Example:\n *\n * t.evaluate(parse(\"5 + 5\")) // { confident: true, value: 10 }\n * t.evaluate(parse(\"!true\")) // { confident: true, value: false }\n * t.evaluate(parse(\"foo + foo\")) // { confident: false, value: undefined, deopt: NodePath }\n *\n */\n\nexport function evaluate(this: NodePath): {\n confident: boolean;\n value: any;\n deopt?: NodePath;\n} {\n const state: State = {\n confident: true,\n deoptPath: null,\n seen: new Map(),\n };\n let value = evaluateCached(this, state);\n if (!state.confident) value = undefined;\n\n return {\n confident: state.confident,\n deopt: state.deoptPath,\n value: value,\n };\n}\n"],"mappings":";;;;;;;AAKA,MAAMA,aAAa,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAU;AAC3D,MAAMC,eAAe,GAAG,CAAC,QAAQ,CAAU;AAE3C,SAASC,aAAa,CAACC,GAAW,EAAuC;EACvE,OAAOH,aAAa,CAACI,QAAQ,CAE3BD,GAAG,CACJ;AACH;AAEA,SAASE,eAAe,CAACF,GAAW,EAAyC;EAC3E,OAAOF,eAAe,CAACG,QAAQ,CAE7BD,GAAG,CACJ;AACH;AAoBO,SAASG,cAAc,GAA0B;EACtD,MAAMC,GAAG,GAAG,IAAI,CAACC,QAAQ,EAAE;EAC3B,IAAID,GAAG,CAACE,SAAS,EAAE,OAAO,CAAC,CAACF,GAAG,CAACG,KAAK;AACvC;AAeA,SAASC,KAAK,CAACC,IAAc,EAAEC,KAAY,EAAE;EAC3C,IAAI,CAACA,KAAK,CAACJ,SAAS,EAAE;EACtBI,KAAK,CAACC,SAAS,GAAGF,IAAI;EACtBC,KAAK,CAACJ,SAAS,GAAG,KAAK;AACzB;AAUA,SAASM,cAAc,CAACH,IAAc,EAAEC,KAAY,EAAO;EACzD,MAAM;IAAEG;EAAK,CAAC,GAAGJ,IAAI;EACrB,MAAM;IAAEK;EAAK,CAAC,GAAGJ,KAAK;EAEtB,IAAII,IAAI,CAAC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,SAAS,EAAEC,KAAK,GAAGkD,SAAS;EAEvC,OAAO;IACLnD,SAAS,EAAEI,KAAK,CAACJ,SAAS;IAC1BE,KAAK,EAAEE,KAAK,CAACC,SAAS;IACtBJ,KAAK,EAAEA;EACT,CAAC;AACH"}
@@ -82,7 +82,6 @@ function normalCompletionToBreak(completions) {
82
82
  c.type = BREAK_COMPLETION;
83
83
  });
84
84
  }
85
-
86
85
  function replaceBreakStatementInBreakCompletion(completions, reachable) {
87
86
  completions.forEach(c => {
88
87
  if (c.path.isBreakStatement({
@@ -105,15 +104,13 @@ function getStatementListCompletion(paths, context) {
105
104
  const newContext = Object.assign({}, context, {
106
105
  inCaseClause: false
107
106
  });
108
- if (path.isBlockStatement() && (context.inCaseClause ||
109
- context.shouldPopulateBreak)) {
107
+ if (path.isBlockStatement() && (context.inCaseClause || context.shouldPopulateBreak)) {
110
108
  newContext.shouldPopulateBreak = true;
111
109
  } else {
112
110
  newContext.shouldPopulateBreak = false;
113
111
  }
114
112
  const statementCompletions = _getCompletionRecords(path, newContext);
115
- if (statementCompletions.length > 0 &&
116
- statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
113
+ if (statementCompletions.length > 0 && statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
117
114
  if (lastNormalCompletions.length > 0 && statementCompletions.every(c => c.path.isBreakStatement({
118
115
  label: null
119
116
  }))) {
@@ -189,7 +186,6 @@ function _getCompletionRecords(path, context) {
189
186
  }
190
187
  return records;
191
188
  }
192
-
193
189
  function getCompletionRecords() {
194
190
  const records = _getCompletionRecords(this, {
195
191
  canHaveBreak: false,
@@ -233,7 +229,6 @@ function getAllPrevSiblings() {
233
229
  }
234
230
  return siblings;
235
231
  }
236
-
237
232
  function get(key, context = true) {
238
233
  if (context === true) context = this.context;
239
234
  const parts = key.split(".");
@@ -294,8 +289,7 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
294
289
  const id = search.shift();
295
290
  if (!id) continue;
296
291
  if (!id.node) continue;
297
- const keys =
298
- _getBindingIdentifiers.keys[id.node.type];
292
+ const keys = _getBindingIdentifiers.keys[id.node.type];
299
293
  if (id.isIdentifier()) {
300
294
  if (duplicates) {
301
295
  const _ids = ids[id.node.name] = ids[id.node.name] || [];
@@ -1 +1 @@
1
- {"version":3,"names":["getBindingIdentifiers","_getBindingIdentifiers","getOuterBindingIdentifiers","_getOuterBindingIdentifiers","isDeclaration","numericLiteral","unaryExpression","NORMAL_COMPLETION","BREAK_COMPLETION","NormalCompletion","path","type","BreakCompletion","getOpposite","key","getSibling","addCompletionRecords","records","context","push","_getCompletionRecords","completionRecordForSwitch","cases","lastNormalCompletions","i","length","casePath","caseCompletions","normalCompletions","breakCompletions","c","normalCompletionToBreak","completions","forEach","replaceBreakStatementInBreakCompletion","reachable","isBreakStatement","label","replaceWith","remove","getStatementListCompletion","paths","canHaveBreak","newContext","inCaseClause","isBlockStatement","shouldPopulateBreak","statementCompletions","every","some","pathCompletions","isVariableDeclaration","isIfStatement","get","isDoExpression","isFor","isWhile","isLabeledStatement","isProgram","isFunction","isTryStatement","isCatchClause","isSwitchStatement","isSwitchCase","getCompletionRecords","map","r","NodePath","parentPath","parent","container","listKey","setContext","getPrevSibling","getNextSibling","getAllNextSiblings","_key","sibling","siblings","node","getAllPrevSiblings","parts","split","_getKey","_getPattern","Array","isArray","_","part","duplicates","getBindingIdentifierPaths","outerOnly","search","ids","Object","create","id","shift","keys","isIdentifier","_ids","name","isExportDeclaration","declaration","isFunctionDeclaration","isFunctionExpression","child","getOuterBindingIdentifierPaths"],"sources":["../../src/path/family.ts"],"sourcesContent":["// This file contains methods responsible for dealing with/retrieving children or siblings.\n\nimport type TraversalContext from \"../context\";\nimport NodePath from \"./index\";\nimport {\n getBindingIdentifiers as _getBindingIdentifiers,\n getOuterBindingIdentifiers as _getOuterBindingIdentifiers,\n isDeclaration,\n numericLiteral,\n unaryExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nconst NORMAL_COMPLETION = 0 as const;\nconst BREAK_COMPLETION = 1 as const;\n\ntype Completion = {\n path: NodePath;\n type: 0 | 1;\n};\n\ntype CompletionContext = {\n // whether the current context allows `break` statement. When it allows, we have\n // to search all the statements for potential `break`\n canHaveBreak: boolean;\n // whether the statement is an immediate descendant of a switch case clause\n inCaseClause: boolean;\n // whether the `break` statement record should be populated to upper level\n // when a `break` statement is an immediate descendant of a block statement, e.g.\n // `{ break }`, it can influence the control flow in the upper levels.\n shouldPopulateBreak: boolean;\n};\n\nfunction NormalCompletion(path: NodePath) {\n return { type: NORMAL_COMPLETION, path };\n}\n\nfunction BreakCompletion(path: NodePath) {\n return { type: BREAK_COMPLETION, path };\n}\n\nexport function getOpposite(this: NodePath): NodePath | null {\n if (this.key === \"left\") {\n return this.getSibling(\"right\");\n } else if (this.key === \"right\") {\n return this.getSibling(\"left\");\n }\n return null;\n}\n\nfunction addCompletionRecords(\n path: NodePath | null | undefined,\n records: Completion[],\n context: CompletionContext,\n): Completion[] {\n if (path) {\n records.push(..._getCompletionRecords(path, context));\n }\n return records;\n}\n\nfunction completionRecordForSwitch(\n cases: NodePath<t.SwitchCase>[],\n records: Completion[],\n context: CompletionContext,\n): Completion[] {\n // https://tc39.es/ecma262/#sec-runtime-semantics-caseblockevaluation\n let lastNormalCompletions: Completion[] = [];\n for (let i = 0; i < cases.length; i++) {\n const casePath = cases[i];\n const caseCompletions = _getCompletionRecords(casePath, context);\n const normalCompletions = [];\n const breakCompletions = [];\n for (const c of caseCompletions) {\n if (c.type === NORMAL_COMPLETION) {\n normalCompletions.push(c);\n }\n if (c.type === BREAK_COMPLETION) {\n breakCompletions.push(c);\n }\n }\n if (normalCompletions.length) {\n lastNormalCompletions = normalCompletions;\n }\n records.push(...breakCompletions);\n }\n records.push(...lastNormalCompletions);\n return records;\n}\n\nfunction normalCompletionToBreak(completions: Completion[]) {\n completions.forEach(c => {\n c.type = BREAK_COMPLETION;\n });\n}\n\n/**\n * Determine how we should handle the break statement for break completions\n *\n * @param {Completion[]} completions\n * @param {boolean} reachable Whether the break statement is reachable after\n we mark the normal completions _before_ the given break completions as the final\n completions. For example,\n `{ 0 }; break;` is transformed to `{ return 0 }; break;`, the `break` here is unreachable\n and thus can be removed without consequences. We may in the future reserve them instead since\n we do not consistently remove unreachable statements _after_ break\n `{ var x = 0 }; break;` is transformed to `{ var x = 0 }; return void 0;`, the `break` is reachable\n because we can not wrap variable declaration under a return statement\n */\nfunction replaceBreakStatementInBreakCompletion(\n completions: Completion[],\n reachable: boolean,\n) {\n completions.forEach(c => {\n if (c.path.isBreakStatement({ label: null })) {\n if (reachable) {\n c.path.replaceWith(unaryExpression(\"void\", numericLiteral(0)));\n } else {\n c.path.remove();\n }\n }\n });\n}\n\nfunction getStatementListCompletion(\n paths: NodePath[],\n context: CompletionContext,\n): Completion[] {\n const completions = [];\n if (context.canHaveBreak) {\n let lastNormalCompletions = [];\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i];\n const newContext = { ...context, inCaseClause: false };\n if (\n path.isBlockStatement() &&\n (context.inCaseClause || // case test: { break }\n context.shouldPopulateBreak) // case test: { { break } }\n ) {\n newContext.shouldPopulateBreak = true;\n } else {\n newContext.shouldPopulateBreak = false;\n }\n const statementCompletions = _getCompletionRecords(path, newContext);\n if (\n statementCompletions.length > 0 &&\n // we can stop search `paths` when we have seen a `path` that is\n // effectively a `break` statement. Examples are\n // - `break`\n // - `if (true) { 1; break } else { 2; break }`\n // - `{ break }```\n // In other words, the paths after this `path` are unreachable\n statementCompletions.every(c => c.type === BREAK_COMPLETION)\n ) {\n if (\n lastNormalCompletions.length > 0 &&\n statementCompletions.every(c =>\n c.path.isBreakStatement({ label: null }),\n )\n ) {\n // when a break completion has a path as BreakStatement, it must be `{ break }`\n // whose completion value we can not determine, otherwise it would have been\n // replaced by `replaceBreakStatementInBreakCompletion`\n // When we have seen normal completions from the last statement\n // it is safe to stop populating break and mark normal completions as break\n normalCompletionToBreak(lastNormalCompletions);\n completions.push(...lastNormalCompletions);\n // Declarations have empty completion record, however they can not be nested\n // directly in return statement, i.e. `return (var a = 1)` is invalid.\n if (lastNormalCompletions.some(c => c.path.isDeclaration())) {\n completions.push(...statementCompletions);\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ true,\n );\n }\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ false,\n );\n } else {\n completions.push(...statementCompletions);\n if (!context.shouldPopulateBreak) {\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ true,\n );\n }\n }\n break;\n }\n if (i === paths.length - 1) {\n completions.push(...statementCompletions);\n } else {\n lastNormalCompletions = [];\n for (let i = 0; i < statementCompletions.length; i++) {\n const c = statementCompletions[i];\n if (c.type === BREAK_COMPLETION) {\n completions.push(c);\n }\n if (c.type === NORMAL_COMPLETION) {\n lastNormalCompletions.push(c);\n }\n }\n }\n }\n } else if (paths.length) {\n // When we are in a context where `break` must not exist, we can skip linear\n // search on statement lists and assume that the last\n // non-variable-declaration statement determines the completion.\n for (let i = paths.length - 1; i >= 0; i--) {\n const pathCompletions = _getCompletionRecords(paths[i], context);\n if (\n pathCompletions.length > 1 ||\n (pathCompletions.length === 1 &&\n !pathCompletions[0].path.isVariableDeclaration())\n ) {\n completions.push(...pathCompletions);\n break;\n }\n }\n }\n return completions;\n}\n\nfunction _getCompletionRecords(\n path: NodePath,\n context: CompletionContext,\n): Completion[] {\n let records: Completion[] = [];\n if (path.isIfStatement()) {\n records = addCompletionRecords(path.get(\"consequent\"), records, context);\n records = addCompletionRecords(path.get(\"alternate\"), records, context);\n } else if (\n path.isDoExpression() ||\n path.isFor() ||\n path.isWhile() ||\n path.isLabeledStatement()\n ) {\n // @ts-expect-error(flow->ts): todo\n return addCompletionRecords(path.get(\"body\"), records, context);\n } else if (path.isProgram() || path.isBlockStatement()) {\n // @ts-expect-error(flow->ts): todo\n return getStatementListCompletion(path.get(\"body\"), context);\n } else if (path.isFunction()) {\n return _getCompletionRecords(path.get(\"body\"), context);\n } else if (path.isTryStatement()) {\n records = addCompletionRecords(path.get(\"block\"), records, context);\n records = addCompletionRecords(path.get(\"handler\"), records, context);\n } else if (path.isCatchClause()) {\n return addCompletionRecords(path.get(\"body\"), records, context);\n } else if (path.isSwitchStatement()) {\n return completionRecordForSwitch(path.get(\"cases\"), records, context);\n } else if (path.isSwitchCase()) {\n return getStatementListCompletion(path.get(\"consequent\"), {\n canHaveBreak: true,\n shouldPopulateBreak: false,\n inCaseClause: true,\n });\n } else if (path.isBreakStatement()) {\n records.push(BreakCompletion(path));\n } else {\n records.push(NormalCompletion(path));\n }\n\n return records;\n}\n\n/**\n * Retrieve the completion records of a given path.\n * Note: to ensure proper support on `break` statement, this method\n * will manipulate the AST around the break statement. Do not call the method\n * twice for the same path.\n *\n * @export\n * @param {NodePath} this\n * @returns {NodePath[]} Completion records\n */\nexport function getCompletionRecords(this: NodePath): NodePath[] {\n const records = _getCompletionRecords(this, {\n canHaveBreak: false,\n shouldPopulateBreak: false,\n inCaseClause: false,\n });\n return records.map(r => r.path);\n}\n\nexport function getSibling(this: NodePath, key: string | number): NodePath {\n return NodePath.get({\n parentPath: this.parentPath,\n parent: this.parent,\n container: this.container,\n listKey: this.listKey,\n key: key,\n }).setContext(this.context);\n}\n\nexport function getPrevSibling(this: NodePath): NodePath {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n return this.getSibling(this.key - 1);\n}\n\nexport function getNextSibling(this: NodePath): NodePath {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n return this.getSibling(this.key + 1);\n}\n\nexport function getAllNextSiblings(this: NodePath): NodePath[] {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n let _key: number = this.key;\n let sibling = this.getSibling(++_key);\n const siblings = [];\n while (sibling.node) {\n siblings.push(sibling);\n sibling = this.getSibling(++_key);\n }\n return siblings;\n}\n\nexport function getAllPrevSiblings(this: NodePath): NodePath[] {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n let _key: number = this.key;\n let sibling = this.getSibling(--_key);\n const siblings = [];\n while (sibling.node) {\n siblings.push(sibling);\n sibling = this.getSibling(--_key);\n }\n return siblings;\n}\n\n// convert \"1\" to 1 (string index to number index)\ntype MaybeToIndex<T extends string> = T extends `${bigint}` ? number : T;\n\ntype Pattern<Obj extends string, Prop extends string> = `${Obj}.${Prop}`;\n\n// split \"body.body.1\" to [\"body\", \"body\", 1]\ntype Split<P extends string> = P extends Pattern<infer O, infer U>\n ? [MaybeToIndex<O>, ...Split<U>]\n : [MaybeToIndex<P>];\n\n// get all K with Node[K] is t.Node | t.Node[]\ntype NodeKeyOf<Node extends t.Node | t.Node[]> = keyof Pick<\n Node,\n {\n [Key in keyof Node]-?: Node[Key] extends t.Node | t.Node[] ? Key : never;\n }[keyof Node]\n>;\n\n// traverse the Node with tuple path [\"body\", \"body\", 1]\n// Path should be created with Split\ntype Trav<\n Node extends t.Node | t.Node[],\n Path extends unknown[],\n> = Path extends [infer K, ...infer R]\n ? K extends NodeKeyOf<Node>\n ? R extends []\n ? Node[K]\n : // @ts-expect-error ignore since TS is not smart enough\n Trav<Node[K], R>\n : never\n : never;\n\ntype ToNodePath<T> = T extends Array<t.Node | null | undefined>\n ? Array<NodePath<T[number]>>\n : T extends t.Node | null | undefined\n ? NodePath<T>\n : never;\n\nfunction get<T extends t.Node, K extends keyof T>(\n this: NodePath<T>,\n key: K,\n context?: boolean | TraversalContext,\n): T[K] extends Array<t.Node | null | undefined>\n ? Array<NodePath<T[K][number]>>\n : T[K] extends t.Node | null | undefined\n ? NodePath<T[K]>\n : never;\n\nfunction get<T extends t.Node, K extends string>(\n this: NodePath<T>,\n key: K,\n context?: boolean | TraversalContext,\n): ToNodePath<Trav<T, Split<K>>>;\n\nfunction get<T extends t.Node>(\n this: NodePath<T>,\n key: string,\n context?: true | TraversalContext,\n): NodePath | NodePath[];\n\nfunction get<T extends t.Node>(\n this: NodePath<T>,\n key: string,\n context: true | TraversalContext = true,\n): NodePath | NodePath[] {\n if (context === true) context = this.context;\n const parts = key.split(\".\");\n if (parts.length === 1) {\n // \"foo\"\n // @ts-expect-error key may not index T\n return this._getKey(key, context);\n } else {\n // \"foo.bar\"\n return this._getPattern(parts, context);\n }\n}\n\nexport { get };\n\nexport function _getKey<T extends t.Node>(\n this: NodePath<T>,\n key: keyof T & string,\n context?: TraversalContext,\n): NodePath | NodePath[] {\n const node = this.node;\n const container = node[key];\n\n if (Array.isArray(container)) {\n // requested a container so give them all the paths\n return container.map((_, i) => {\n return NodePath.get({\n listKey: key,\n parentPath: this,\n parent: node,\n container: container,\n key: i,\n }).setContext(context);\n });\n } else {\n return NodePath.get({\n parentPath: this,\n parent: node,\n container: node,\n key: key,\n }).setContext(context);\n }\n}\n\nexport function _getPattern(\n this: NodePath,\n parts: string[],\n context?: TraversalContext,\n): NodePath | NodePath[] {\n let path: NodePath | NodePath[] = this;\n for (const part of parts) {\n if (part === \".\") {\n // @ts-expect-error todo(flow-ts): Can path be an array here?\n path = path.parentPath;\n } else {\n if (Array.isArray(path)) {\n // @ts-expect-error part may not index path\n path = path[part];\n } else {\n path = path.get(part, context);\n }\n }\n }\n return path;\n}\n\nfunction getBindingIdentifiers(\n duplicates: true,\n): Record<string, t.Identifier[]>;\nfunction getBindingIdentifiers(\n duplicates?: false,\n): Record<string, t.Identifier>;\nfunction getBindingIdentifiers(\n duplicates: boolean,\n): Record<string, t.Identifier[] | t.Identifier>;\n\nfunction getBindingIdentifiers(\n this: NodePath,\n duplicates?: boolean,\n): Record<string, t.Identifier[] | t.Identifier> {\n return _getBindingIdentifiers(this.node, duplicates);\n}\n\nexport { getBindingIdentifiers };\n\nfunction getOuterBindingIdentifiers(\n duplicates: true,\n): Record<string, t.Identifier[]>;\nfunction getOuterBindingIdentifiers(\n duplicates?: false,\n): Record<string, t.Identifier>;\nfunction getOuterBindingIdentifiers(\n duplicates: boolean,\n): Record<string, t.Identifier[] | t.Identifier>;\n\nfunction getOuterBindingIdentifiers(\n this: NodePath,\n duplicates?: boolean,\n): Record<string, t.Identifier[] | t.Identifier> {\n return _getOuterBindingIdentifiers(this.node, duplicates);\n}\n\nexport { getOuterBindingIdentifiers };\n\nfunction getBindingIdentifierPaths(\n duplicates: true,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier>[]>;\nfunction getBindingIdentifierPaths(\n duplicates: false,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier>>;\nfunction getBindingIdentifierPaths(\n duplicates?: boolean,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;\n\n// original source - https://github.com/babel/babel/blob/main/packages/babel-types/src/retrievers/getBindingIdentifiers.js\n// path.getBindingIdentifiers returns nodes where the following re-implementation returns paths\nfunction getBindingIdentifierPaths(\n this: NodePath,\n duplicates: boolean = false,\n outerOnly: boolean = false,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]> {\n const path = this;\n const search = [path];\n const ids = Object.create(null);\n\n while (search.length) {\n const id = search.shift();\n if (!id) continue;\n if (!id.node) continue;\n\n const keys =\n // @ts-expect-error _getBindingIdentifiers.keys do not cover all node types\n _getBindingIdentifiers.keys[id.node.type];\n\n if (id.isIdentifier()) {\n if (duplicates) {\n const _ids = (ids[id.node.name] = ids[id.node.name] || []);\n _ids.push(id);\n } else {\n ids[id.node.name] = id;\n }\n continue;\n }\n\n if (id.isExportDeclaration()) {\n const declaration = id.get(\"declaration\");\n if (isDeclaration(declaration)) {\n search.push(declaration);\n }\n continue;\n }\n\n if (outerOnly) {\n if (id.isFunctionDeclaration()) {\n search.push(id.get(\"id\"));\n continue;\n }\n if (id.isFunctionExpression()) {\n continue;\n }\n }\n\n if (keys) {\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const child = id.get(key);\n if (Array.isArray(child)) {\n search.push(...child);\n } else if (child.node) {\n search.push(child);\n }\n }\n }\n }\n\n return ids;\n}\n\nexport { getBindingIdentifierPaths };\n\nfunction getOuterBindingIdentifierPaths(\n duplicates: true,\n): Record<string, NodePath<t.Identifier>[]>;\nfunction getOuterBindingIdentifierPaths(\n duplicates?: false,\n): Record<string, NodePath<t.Identifier>>;\nfunction getOuterBindingIdentifierPaths(\n duplicates?: boolean,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;\n\nfunction getOuterBindingIdentifierPaths(\n this: NodePath,\n duplicates: boolean = false,\n) {\n return this.getBindingIdentifierPaths(duplicates, true);\n}\n\nexport { getOuterBindingIdentifierPaths };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;AACA;AAMsB;EALpBA,qBAAqB,EAAIC,sBAAsB;EAC/CC,0BAA0B,EAAIC,2BAA2B;EACzDC,aAAa;EACbC,cAAc;EACdC;AAAe;AAIjB,MAAMC,iBAAiB,GAAG,CAAU;AACpC,MAAMC,gBAAgB,GAAG,CAAU;AAmBnC,SAASC,gBAAgB,CAACC,IAAc,EAAE;EACxC,OAAO;IAAEC,IAAI,EAAEJ,iBAAiB;IAAEG;EAAK,CAAC;AAC1C;AAEA,SAASE,eAAe,CAACF,IAAc,EAAE;EACvC,OAAO;IAAEC,IAAI,EAAEH,gBAAgB;IAAEE;EAAK,CAAC;AACzC;AAEO,SAASG,WAAW,GAAkC;EAC3D,IAAI,IAAI,CAACC,GAAG,KAAK,MAAM,EAAE;IACvB,OAAO,IAAI,CAACC,UAAU,CAAC,OAAO,CAAC;EACjC,CAAC,MAAM,IAAI,IAAI,CAACD,GAAG,KAAK,OAAO,EAAE;IAC/B,OAAO,IAAI,CAACC,UAAU,CAAC,MAAM,CAAC;EAChC;EACA,OAAO,IAAI;AACb;AAEA,SAASC,oBAAoB,CAC3BN,IAAiC,EACjCO,OAAqB,EACrBC,OAA0B,EACZ;EACd,IAAIR,IAAI,EAAE;IACRO,OAAO,CAACE,IAAI,CAAC,GAAGC,qBAAqB,CAACV,IAAI,EAAEQ,OAAO,CAAC,CAAC;EACvD;EACA,OAAOD,OAAO;AAChB;AAEA,SAASI,yBAAyB,CAChCC,KAA+B,EAC/BL,OAAqB,EACrBC,OAA0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IAAI,EAAE;UACrBa,MAAM,CAACzE,IAAI,CAACuF,KAAK,CAAC;QACpB;MACF;IACF;EACF;EAEA,OAAOb,GAAG;AACZ;AAcA,SAASc,8BAA8B,CAErClB,UAAmB,GAAG,KAAK,EAC3B;EACA,OAAO,IAAI,CAACC,yBAAyB,CAACD,UAAU,EAAE,IAAI,CAAC;AACzD"}
1
+ {"version":3,"names":["getBindingIdentifiers","_getBindingIdentifiers","getOuterBindingIdentifiers","_getOuterBindingIdentifiers","isDeclaration","numericLiteral","unaryExpression","NORMAL_COMPLETION","BREAK_COMPLETION","NormalCompletion","path","type","BreakCompletion","getOpposite","key","getSibling","addCompletionRecords","records","context","push","_getCompletionRecords","completionRecordForSwitch","cases","lastNormalCompletions","i","length","casePath","caseCompletions","normalCompletions","breakCompletions","c","normalCompletionToBreak","completions","forEach","replaceBreakStatementInBreakCompletion","reachable","isBreakStatement","label","replaceWith","remove","getStatementListCompletion","paths","canHaveBreak","newContext","inCaseClause","isBlockStatement","shouldPopulateBreak","statementCompletions","every","some","pathCompletions","isVariableDeclaration","isIfStatement","get","isDoExpression","isFor","isWhile","isLabeledStatement","isProgram","isFunction","isTryStatement","isCatchClause","isSwitchStatement","isSwitchCase","getCompletionRecords","map","r","NodePath","parentPath","parent","container","listKey","setContext","getPrevSibling","getNextSibling","getAllNextSiblings","_key","sibling","siblings","node","getAllPrevSiblings","parts","split","_getKey","_getPattern","Array","isArray","_","part","duplicates","getBindingIdentifierPaths","outerOnly","search","ids","Object","create","id","shift","keys","isIdentifier","_ids","name","isExportDeclaration","declaration","isFunctionDeclaration","isFunctionExpression","child","getOuterBindingIdentifierPaths"],"sources":["../../src/path/family.ts"],"sourcesContent":["// This file contains methods responsible for dealing with/retrieving children or siblings.\n\nimport type TraversalContext from \"../context\";\nimport NodePath from \"./index\";\nimport {\n getBindingIdentifiers as _getBindingIdentifiers,\n getOuterBindingIdentifiers as _getOuterBindingIdentifiers,\n isDeclaration,\n numericLiteral,\n unaryExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nconst NORMAL_COMPLETION = 0 as const;\nconst BREAK_COMPLETION = 1 as const;\n\ntype Completion = {\n path: NodePath;\n type: 0 | 1;\n};\n\ntype CompletionContext = {\n // whether the current context allows `break` statement. When it allows, we have\n // to search all the statements for potential `break`\n canHaveBreak: boolean;\n // whether the statement is an immediate descendant of a switch case clause\n inCaseClause: boolean;\n // whether the `break` statement record should be populated to upper level\n // when a `break` statement is an immediate descendant of a block statement, e.g.\n // `{ break }`, it can influence the control flow in the upper levels.\n shouldPopulateBreak: boolean;\n};\n\nfunction NormalCompletion(path: NodePath) {\n return { type: NORMAL_COMPLETION, path };\n}\n\nfunction BreakCompletion(path: NodePath) {\n return { type: BREAK_COMPLETION, path };\n}\n\nexport function getOpposite(this: NodePath): NodePath | null {\n if (this.key === \"left\") {\n return this.getSibling(\"right\");\n } else if (this.key === \"right\") {\n return this.getSibling(\"left\");\n }\n return null;\n}\n\nfunction addCompletionRecords(\n path: NodePath | null | undefined,\n records: Completion[],\n context: CompletionContext,\n): Completion[] {\n if (path) {\n records.push(..._getCompletionRecords(path, context));\n }\n return records;\n}\n\nfunction completionRecordForSwitch(\n cases: NodePath<t.SwitchCase>[],\n records: Completion[],\n context: CompletionContext,\n): Completion[] {\n // https://tc39.es/ecma262/#sec-runtime-semantics-caseblockevaluation\n let lastNormalCompletions: Completion[] = [];\n for (let i = 0; i < cases.length; i++) {\n const casePath = cases[i];\n const caseCompletions = _getCompletionRecords(casePath, context);\n const normalCompletions = [];\n const breakCompletions = [];\n for (const c of caseCompletions) {\n if (c.type === NORMAL_COMPLETION) {\n normalCompletions.push(c);\n }\n if (c.type === BREAK_COMPLETION) {\n breakCompletions.push(c);\n }\n }\n if (normalCompletions.length) {\n lastNormalCompletions = normalCompletions;\n }\n records.push(...breakCompletions);\n }\n records.push(...lastNormalCompletions);\n return records;\n}\n\nfunction normalCompletionToBreak(completions: Completion[]) {\n completions.forEach(c => {\n c.type = BREAK_COMPLETION;\n });\n}\n\n/**\n * Determine how we should handle the break statement for break completions\n *\n * @param {Completion[]} completions\n * @param {boolean} reachable Whether the break statement is reachable after\n we mark the normal completions _before_ the given break completions as the final\n completions. For example,\n `{ 0 }; break;` is transformed to `{ return 0 }; break;`, the `break` here is unreachable\n and thus can be removed without consequences. We may in the future reserve them instead since\n we do not consistently remove unreachable statements _after_ break\n `{ var x = 0 }; break;` is transformed to `{ var x = 0 }; return void 0;`, the `break` is reachable\n because we can not wrap variable declaration under a return statement\n */\nfunction replaceBreakStatementInBreakCompletion(\n completions: Completion[],\n reachable: boolean,\n) {\n completions.forEach(c => {\n if (c.path.isBreakStatement({ label: null })) {\n if (reachable) {\n c.path.replaceWith(unaryExpression(\"void\", numericLiteral(0)));\n } else {\n c.path.remove();\n }\n }\n });\n}\n\nfunction getStatementListCompletion(\n paths: NodePath[],\n context: CompletionContext,\n): Completion[] {\n const completions = [];\n if (context.canHaveBreak) {\n let lastNormalCompletions = [];\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i];\n const newContext = { ...context, inCaseClause: false };\n if (\n path.isBlockStatement() &&\n (context.inCaseClause || // case test: { break }\n context.shouldPopulateBreak) // case test: { { break } }\n ) {\n newContext.shouldPopulateBreak = true;\n } else {\n newContext.shouldPopulateBreak = false;\n }\n const statementCompletions = _getCompletionRecords(path, newContext);\n if (\n statementCompletions.length > 0 &&\n // we can stop search `paths` when we have seen a `path` that is\n // effectively a `break` statement. Examples are\n // - `break`\n // - `if (true) { 1; break } else { 2; break }`\n // - `{ break }```\n // In other words, the paths after this `path` are unreachable\n statementCompletions.every(c => c.type === BREAK_COMPLETION)\n ) {\n if (\n lastNormalCompletions.length > 0 &&\n statementCompletions.every(c =>\n c.path.isBreakStatement({ label: null }),\n )\n ) {\n // when a break completion has a path as BreakStatement, it must be `{ break }`\n // whose completion value we can not determine, otherwise it would have been\n // replaced by `replaceBreakStatementInBreakCompletion`\n // When we have seen normal completions from the last statement\n // it is safe to stop populating break and mark normal completions as break\n normalCompletionToBreak(lastNormalCompletions);\n completions.push(...lastNormalCompletions);\n // Declarations have empty completion record, however they can not be nested\n // directly in return statement, i.e. `return (var a = 1)` is invalid.\n if (lastNormalCompletions.some(c => c.path.isDeclaration())) {\n completions.push(...statementCompletions);\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ true,\n );\n }\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ false,\n );\n } else {\n completions.push(...statementCompletions);\n if (!context.shouldPopulateBreak) {\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ true,\n );\n }\n }\n break;\n }\n if (i === paths.length - 1) {\n completions.push(...statementCompletions);\n } else {\n lastNormalCompletions = [];\n for (let i = 0; i < statementCompletions.length; i++) {\n const c = statementCompletions[i];\n if (c.type === BREAK_COMPLETION) {\n completions.push(c);\n }\n if (c.type === NORMAL_COMPLETION) {\n lastNormalCompletions.push(c);\n }\n }\n }\n }\n } else if (paths.length) {\n // When we are in a context where `break` must not exist, we can skip linear\n // search on statement lists and assume that the last\n // non-variable-declaration statement determines the completion.\n for (let i = paths.length - 1; i >= 0; i--) {\n const pathCompletions = _getCompletionRecords(paths[i], context);\n if (\n pathCompletions.length > 1 ||\n (pathCompletions.length === 1 &&\n !pathCompletions[0].path.isVariableDeclaration())\n ) {\n completions.push(...pathCompletions);\n break;\n }\n }\n }\n return completions;\n}\n\nfunction _getCompletionRecords(\n path: NodePath,\n context: CompletionContext,\n): Completion[] {\n let records: Completion[] = [];\n if (path.isIfStatement()) {\n records = addCompletionRecords(path.get(\"consequent\"), records, context);\n records = addCompletionRecords(path.get(\"alternate\"), records, context);\n } else if (\n path.isDoExpression() ||\n path.isFor() ||\n path.isWhile() ||\n path.isLabeledStatement()\n ) {\n // @ts-expect-error(flow->ts): todo\n return addCompletionRecords(path.get(\"body\"), records, context);\n } else if (path.isProgram() || path.isBlockStatement()) {\n // @ts-expect-error(flow->ts): todo\n return getStatementListCompletion(path.get(\"body\"), context);\n } else if (path.isFunction()) {\n return _getCompletionRecords(path.get(\"body\"), context);\n } else if (path.isTryStatement()) {\n records = addCompletionRecords(path.get(\"block\"), records, context);\n records = addCompletionRecords(path.get(\"handler\"), records, context);\n } else if (path.isCatchClause()) {\n return addCompletionRecords(path.get(\"body\"), records, context);\n } else if (path.isSwitchStatement()) {\n return completionRecordForSwitch(path.get(\"cases\"), records, context);\n } else if (path.isSwitchCase()) {\n return getStatementListCompletion(path.get(\"consequent\"), {\n canHaveBreak: true,\n shouldPopulateBreak: false,\n inCaseClause: true,\n });\n } else if (path.isBreakStatement()) {\n records.push(BreakCompletion(path));\n } else {\n records.push(NormalCompletion(path));\n }\n\n return records;\n}\n\n/**\n * Retrieve the completion records of a given path.\n * Note: to ensure proper support on `break` statement, this method\n * will manipulate the AST around the break statement. Do not call the method\n * twice for the same path.\n *\n * @export\n * @param {NodePath} this\n * @returns {NodePath[]} Completion records\n */\nexport function getCompletionRecords(this: NodePath): NodePath[] {\n const records = _getCompletionRecords(this, {\n canHaveBreak: false,\n shouldPopulateBreak: false,\n inCaseClause: false,\n });\n return records.map(r => r.path);\n}\n\nexport function getSibling(this: NodePath, key: string | number): NodePath {\n return NodePath.get({\n parentPath: this.parentPath,\n parent: this.parent,\n container: this.container,\n listKey: this.listKey,\n key: key,\n }).setContext(this.context);\n}\n\nexport function getPrevSibling(this: NodePath): NodePath {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n return this.getSibling(this.key - 1);\n}\n\nexport function getNextSibling(this: NodePath): NodePath {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n return this.getSibling(this.key + 1);\n}\n\nexport function getAllNextSiblings(this: NodePath): NodePath[] {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n let _key: number = this.key;\n let sibling = this.getSibling(++_key);\n const siblings = [];\n while (sibling.node) {\n siblings.push(sibling);\n sibling = this.getSibling(++_key);\n }\n return siblings;\n}\n\nexport function getAllPrevSiblings(this: NodePath): NodePath[] {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n let _key: number = this.key;\n let sibling = this.getSibling(--_key);\n const siblings = [];\n while (sibling.node) {\n siblings.push(sibling);\n sibling = this.getSibling(--_key);\n }\n return siblings;\n}\n\n// convert \"1\" to 1 (string index to number index)\ntype MaybeToIndex<T extends string> = T extends `${bigint}` ? number : T;\n\ntype Pattern<Obj extends string, Prop extends string> = `${Obj}.${Prop}`;\n\n// split \"body.body.1\" to [\"body\", \"body\", 1]\ntype Split<P extends string> = P extends Pattern<infer O, infer U>\n ? [MaybeToIndex<O>, ...Split<U>]\n : [MaybeToIndex<P>];\n\n// get all K with Node[K] is t.Node | t.Node[]\ntype NodeKeyOf<Node extends t.Node | t.Node[]> = keyof Pick<\n Node,\n {\n [Key in keyof Node]-?: Node[Key] extends t.Node | t.Node[] ? Key : never;\n }[keyof Node]\n>;\n\n// traverse the Node with tuple path [\"body\", \"body\", 1]\n// Path should be created with Split\ntype Trav<\n Node extends t.Node | t.Node[],\n Path extends unknown[],\n> = Path extends [infer K, ...infer R]\n ? K extends NodeKeyOf<Node>\n ? R extends []\n ? Node[K]\n : // @ts-expect-error ignore since TS is not smart enough\n Trav<Node[K], R>\n : never\n : never;\n\ntype ToNodePath<T> = T extends Array<t.Node | null | undefined>\n ? Array<NodePath<T[number]>>\n : T extends t.Node | null | undefined\n ? NodePath<T>\n : never;\n\nfunction get<T extends t.Node, K extends keyof T>(\n this: NodePath<T>,\n key: K,\n context?: boolean | TraversalContext,\n): T[K] extends Array<t.Node | null | undefined>\n ? Array<NodePath<T[K][number]>>\n : T[K] extends t.Node | null | undefined\n ? NodePath<T[K]>\n : never;\n\nfunction get<T extends t.Node, K extends string>(\n this: NodePath<T>,\n key: K,\n context?: boolean | TraversalContext,\n): ToNodePath<Trav<T, Split<K>>>;\n\nfunction get<T extends t.Node>(\n this: NodePath<T>,\n key: string,\n context?: true | TraversalContext,\n): NodePath | NodePath[];\n\nfunction get<T extends t.Node>(\n this: NodePath<T>,\n key: string,\n context: true | TraversalContext = true,\n): NodePath | NodePath[] {\n if (context === true) context = this.context;\n const parts = key.split(\".\");\n if (parts.length === 1) {\n // \"foo\"\n // @ts-expect-error key may not index T\n return this._getKey(key, context);\n } else {\n // \"foo.bar\"\n return this._getPattern(parts, context);\n }\n}\n\nexport { get };\n\nexport function _getKey<T extends t.Node>(\n this: NodePath<T>,\n key: keyof T & string,\n context?: TraversalContext,\n): NodePath | NodePath[] {\n const node = this.node;\n const container = node[key];\n\n if (Array.isArray(container)) {\n // requested a container so give them all the paths\n return container.map((_, i) => {\n return NodePath.get({\n listKey: key,\n parentPath: this,\n parent: node,\n container: container,\n key: i,\n }).setContext(context);\n });\n } else {\n return NodePath.get({\n parentPath: this,\n parent: node,\n container: node,\n key: key,\n }).setContext(context);\n }\n}\n\nexport function _getPattern(\n this: NodePath,\n parts: string[],\n context?: TraversalContext,\n): NodePath | NodePath[] {\n let path: NodePath | NodePath[] = this;\n for (const part of parts) {\n if (part === \".\") {\n // @ts-expect-error todo(flow-ts): Can path be an array here?\n path = path.parentPath;\n } else {\n if (Array.isArray(path)) {\n // @ts-expect-error part may not index path\n path = path[part];\n } else {\n path = path.get(part, context);\n }\n }\n }\n return path;\n}\n\nfunction getBindingIdentifiers(\n duplicates: true,\n): Record<string, t.Identifier[]>;\nfunction getBindingIdentifiers(\n duplicates?: false,\n): Record<string, t.Identifier>;\nfunction getBindingIdentifiers(\n duplicates: boolean,\n): Record<string, t.Identifier[] | t.Identifier>;\n\nfunction getBindingIdentifiers(\n this: NodePath,\n duplicates?: boolean,\n): Record<string, t.Identifier[] | t.Identifier> {\n return _getBindingIdentifiers(this.node, duplicates);\n}\n\nexport { getBindingIdentifiers };\n\nfunction getOuterBindingIdentifiers(\n duplicates: true,\n): Record<string, t.Identifier[]>;\nfunction getOuterBindingIdentifiers(\n duplicates?: false,\n): Record<string, t.Identifier>;\nfunction getOuterBindingIdentifiers(\n duplicates: boolean,\n): Record<string, t.Identifier[] | t.Identifier>;\n\nfunction getOuterBindingIdentifiers(\n this: NodePath,\n duplicates?: boolean,\n): Record<string, t.Identifier[] | t.Identifier> {\n return _getOuterBindingIdentifiers(this.node, duplicates);\n}\n\nexport { getOuterBindingIdentifiers };\n\nfunction getBindingIdentifierPaths(\n duplicates: true,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier>[]>;\nfunction getBindingIdentifierPaths(\n duplicates: false,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier>>;\nfunction getBindingIdentifierPaths(\n duplicates?: boolean,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;\n\n// original source - https://github.com/babel/babel/blob/main/packages/babel-types/src/retrievers/getBindingIdentifiers.js\n// path.getBindingIdentifiers returns nodes where the following re-implementation returns paths\nfunction getBindingIdentifierPaths(\n this: NodePath,\n duplicates: boolean = false,\n outerOnly: boolean = false,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]> {\n const path = this;\n const search = [path];\n const ids = Object.create(null);\n\n while (search.length) {\n const id = search.shift();\n if (!id) continue;\n if (!id.node) continue;\n\n const keys =\n // @ts-expect-error _getBindingIdentifiers.keys do not cover all node types\n _getBindingIdentifiers.keys[id.node.type];\n\n if (id.isIdentifier()) {\n if (duplicates) {\n const _ids = (ids[id.node.name] = ids[id.node.name] || []);\n _ids.push(id);\n } else {\n ids[id.node.name] = id;\n }\n continue;\n }\n\n if (id.isExportDeclaration()) {\n const declaration = id.get(\"declaration\");\n if (isDeclaration(declaration)) {\n search.push(declaration);\n }\n continue;\n }\n\n if (outerOnly) {\n if (id.isFunctionDeclaration()) {\n search.push(id.get(\"id\"));\n continue;\n }\n if (id.isFunctionExpression()) {\n continue;\n }\n }\n\n if (keys) {\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const child = id.get(key);\n if (Array.isArray(child)) {\n search.push(...child);\n } else if (child.node) {\n search.push(child);\n }\n }\n }\n }\n\n return ids;\n}\n\nexport { getBindingIdentifierPaths };\n\nfunction getOuterBindingIdentifierPaths(\n duplicates: true,\n): Record<string, NodePath<t.Identifier>[]>;\nfunction getOuterBindingIdentifierPaths(\n duplicates?: false,\n): Record<string, NodePath<t.Identifier>>;\nfunction getOuterBindingIdentifierPaths(\n duplicates?: boolean,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;\n\nfunction getOuterBindingIdentifierPaths(\n this: NodePath,\n duplicates: boolean = false,\n) {\n return this.getBindingIdentifierPaths(duplicates, true);\n}\n\nexport { getOuterBindingIdentifierPaths };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;AACA;AAMsB;EALpBA,qBAAqB,EAAIC,sBAAsB;EAC/CC,0BAA0B,EAAIC,2BAA2B;EACzDC,aAAa;EACbC,cAAc;EACdC;AAAe;AAIjB,MAAMC,iBAAiB,GAAG,CAAU;AACpC,MAAMC,gBAAgB,GAAG,CAAU;AAmBnC,SAASC,gBAAgB,CAACC,IAAc,EAAE;EACxC,OAAO;IAAEC,IAAI,EAAEJ,iBAAiB;IAAEG;EAAK,CAAC;AAC1C;AAEA,SAASE,eAAe,CAACF,IAAc,EAAE;EACvC,OAAO;IAAEC,IAAI,EAAEH,gBAAgB;IAAEE;EAAK,CAAC;AACzC;AAEO,SAASG,WAAW,GAAkC;EAC3D,IAAI,IAAI,CAACC,GAAG,KAAK,MAAM,EAAE;IACvB,OAAO,IAAI,CAACC,UAAU,CAAC,OAAO,CAAC;EACjC,CAAC,MAAM,IAAI,IAAI,CAACD,GAAG,KAAK,OAAO,EAAE;IAC/B,OAAO,IAAI,CAACC,UAAU,CAAC,MAAM,CAAC;EAChC;EACA,OAAO,IAAI;AACb;AAEA,SAASC,oBAAoB,CAC3BN,IAAiC,EACjCO,OAAqB,EACrBC,OAA0B,EACZ;EACd,IAAIR,IAAI,EAAE;IACRO,OAAO,CAACE,IAAI,CAAC,GAAGC,qBAAqB,CAACV,IAAI,EAAEQ,OAAO,CAAC,CAAC;EACvD;EACA,OAAOD,OAAO;AAChB;AA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GuF,KAAK,CAAC;QACvB,CAAC,MAAM,IAAIA,KAAK,CAAC3B,IAAI,EAAE;UACrBa,MAAM,CAACzE,IAAI,CAACuF,KAAK,CAAC;QACpB;MACF;IACF;EACF;EAEA,OAAOb,GAAG;AACZ;AAcA,SAASc,8BAA8B,CAErClB,UAAmB,GAAG,KAAK,EAC3B;EACA,OAAO,IAAI,CAACC,yBAAyB,CAACD,UAAU,EAAE,IAAI,CAAC;AACzD"}
package/lib/path/index.js CHANGED
@@ -67,8 +67,7 @@ class NodePath {
67
67
  if (!parent) {
68
68
  throw new Error("To get a node path the parent needs to exist");
69
69
  }
70
- const targetNode =
71
- container[key];
70
+ const targetNode = container[key];
72
71
  let paths = _cache.path.get(parent);
73
72
  if (!paths) {
74
73
  paths = new Map();
@@ -137,7 +136,6 @@ class NodePath {
137
136
  this.listKey = null;
138
137
  }
139
138
  }
140
-
141
139
  get parentKey() {
142
140
  return this.listKey || this.key;
143
141
  }
@@ -176,21 +174,18 @@ Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePat
176
174
  {
177
175
  NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
178
176
  }
179
-
180
177
  for (const type of t.TYPES) {
181
178
  const typeKey = `is${type}`;
182
179
  const fn = t[typeKey];
183
180
  NodePath.prototype[typeKey] = function (opts) {
184
181
  return fn(this.node, opts);
185
182
  };
186
-
187
183
  NodePath.prototype[`assert${type}`] = function (opts) {
188
184
  if (!fn(this.node, opts)) {
189
185
  throw new TypeError(`Expected node path of type ${type}`);
190
186
  }
191
187
  };
192
188
  }
193
-
194
189
  Object.assign(NodePath.prototype, NodePath_virtual_types_validator);
195
190
  for (const type of Object.keys(virtualTypes)) {
196
191
  if (type[0] === "_") continue;
@@ -1 +1 @@
1
- {"version":3,"names":["validate","debug","buildDebug","REMOVED","SHOULD_STOP","SHOULD_SKIP","NodePath","constructor","hub","parent","contexts","state","opts","_traverseFlags","skipKeys","parentPath","container","listKey","key","node","type","data","context","scope","get","Error","targetNode","paths","pathCache","Map","set","path","setup","getScope","isScope","Scope","setData","val","Object","create","getData","def","undefined","hasNode","buildCodeFrameError","msg","SyntaxError","buildError","traverse","visitor","getPathLocation","parts","inList","unshift","join","message","enabled","toString","generator","code","parentKey","shouldSkip","v","shouldStop","removed","assign","prototype","NodePath_ancestry","NodePath_inference","NodePath_replacement","NodePath_evaluation","NodePath_conversion","NodePath_introspection","NodePath_context","NodePath_removal","NodePath_modification","NodePath_family","NodePath_comments","_guessExecutionStatusRelativeToDifferentFunctions","_guessExecutionStatusRelativeTo","t","TYPES","typeKey","fn","TypeError","NodePath_virtual_types_validator","keys","virtualTypes","includes","push"],"sources":["../../src/path/index.ts"],"sourcesContent":["import type { HubInterface } from \"../hub\";\nimport type TraversalContext from \"../context\";\nimport * as virtualTypes from \"./lib/virtual-types\";\nimport buildDebug from \"debug\";\nimport traverse from \"../index\";\nimport type { Visitor } from \"../types\";\nimport Scope from \"../scope\";\nimport { validate } from \"@babel/types\";\nimport * as t from \"@babel/types\";\nimport { path as pathCache } from \"../cache\";\nimport generator from \"@babel/generator\";\n\n// NodePath is split across many files.\nimport * as NodePath_ancestry from \"./ancestry\";\nimport * as NodePath_inference from \"./inference\";\nimport * as NodePath_replacement from \"./replacement\";\nimport * as NodePath_evaluation from \"./evaluation\";\nimport * as NodePath_conversion from \"./conversion\";\nimport * as NodePath_introspection from \"./introspection\";\nimport * as NodePath_context from \"./context\";\nimport * as NodePath_removal from \"./removal\";\nimport * as NodePath_modification from \"./modification\";\nimport * as NodePath_family from \"./family\";\nimport * as NodePath_comments from \"./comments\";\nimport * as NodePath_virtual_types_validator from \"./lib/virtual-types-validator\";\nimport type { NodePathAssertions } from \"./generated/asserts\";\nimport type { NodePathValidators } from \"./generated/validators\";\n\nconst debug = buildDebug(\"babel\");\n\nexport const REMOVED = 1 << 0;\nexport const SHOULD_STOP = 1 << 1;\nexport const SHOULD_SKIP = 1 << 2;\n\nclass NodePath<T extends t.Node = t.Node> {\n constructor(hub: HubInterface, parent: t.ParentMaps[T[\"type\"]]) {\n this.parent = parent;\n this.hub = hub;\n this.data = null;\n\n this.context = null;\n this.scope = null;\n }\n\n declare parent: t.ParentMaps[T[\"type\"]];\n declare hub: HubInterface;\n declare data: Record<string | symbol, unknown>;\n // TraversalContext is configured by setContext\n declare context: TraversalContext;\n declare scope: Scope;\n\n contexts: Array<TraversalContext> = [];\n state: any = null;\n opts: any = null;\n // this.shouldSkip = false; this.shouldStop = false; this.removed = false;\n _traverseFlags: number = 0;\n skipKeys: any = null;\n parentPath: t.ParentMaps[T[\"type\"]] extends null\n ? null\n : NodePath<t.ParentMaps[T[\"type\"]]> | null = null;\n container: t.Node | Array<t.Node> | null = null;\n listKey: string | null = null;\n key: string | number | null = null;\n node: T = null;\n type: T[\"type\"] | null = null;\n\n static get({\n hub,\n parentPath,\n parent,\n container,\n listKey,\n key,\n }: {\n hub?: HubInterface;\n parentPath: NodePath | null;\n parent: t.Node;\n container: t.Node | t.Node[];\n listKey?: string;\n key: string | number;\n }): NodePath {\n if (!hub && parentPath) {\n hub = parentPath.hub;\n }\n\n if (!parent) {\n throw new Error(\"To get a node path the parent needs to exist\");\n }\n\n const targetNode =\n // @ts-expect-error key must present in container\n container[key];\n\n let paths = pathCache.get(parent);\n if (!paths) {\n paths = new Map();\n pathCache.set(parent, paths);\n }\n\n let path = paths.get(targetNode);\n if (!path) {\n path = new NodePath(hub, parent);\n if (targetNode) paths.set(targetNode, path);\n }\n\n path.setup(parentPath, container, listKey, key);\n\n return path;\n }\n\n getScope(scope: Scope): Scope {\n return this.isScope() ? new Scope(this) : scope;\n }\n\n setData(key: string | symbol, val: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n return (this.data[key] = val);\n }\n\n getData(key: string | symbol, def?: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n let val = this.data[key];\n if (val === undefined && def !== undefined) val = this.data[key] = def;\n return val;\n }\n\n hasNode(): this is NodePath<NonNullable<this[\"node\"]>> {\n return this.node != null;\n }\n\n buildCodeFrameError(\n msg: string,\n Error: new () => Error = SyntaxError,\n ): Error {\n return this.hub.buildError(this.node, msg, Error);\n }\n\n traverse<T>(visitor: Visitor<T>, state: T): void;\n traverse(visitor: Visitor): void;\n traverse(visitor: any, state?: any) {\n traverse(this.node, visitor, this.scope, state, this);\n }\n\n set(key: string, node: any) {\n validate(this.node, key, node);\n // @ts-expect-error key must present in this.node\n this.node[key] = node;\n }\n\n getPathLocation(): string {\n const parts = [];\n let path: NodePath = this;\n do {\n let key = path.key;\n if (path.inList) key = `${path.listKey}[${key}]`;\n parts.unshift(key);\n } while ((path = path.parentPath));\n return parts.join(\".\");\n }\n\n debug(message: string) {\n if (!debug.enabled) return;\n debug(`${this.getPathLocation()} ${this.type}: ${message}`);\n }\n\n toString() {\n return generator(this.node).code;\n }\n\n get inList() {\n return !!this.listKey;\n }\n\n set inList(inList) {\n if (!inList) {\n this.listKey = null;\n }\n // ignore inList = true as it should depend on `listKey`\n }\n\n get parentKey(): string {\n return (this.listKey || this.key) as string;\n }\n\n get shouldSkip() {\n return !!(this._traverseFlags & SHOULD_SKIP);\n }\n\n set shouldSkip(v) {\n if (v) {\n this._traverseFlags |= SHOULD_SKIP;\n } else {\n this._traverseFlags &= ~SHOULD_SKIP;\n }\n }\n\n get shouldStop() {\n return !!(this._traverseFlags & SHOULD_STOP);\n }\n\n set shouldStop(v) {\n if (v) {\n this._traverseFlags |= SHOULD_STOP;\n } else {\n this._traverseFlags &= ~SHOULD_STOP;\n }\n }\n\n get removed() {\n return !!(this._traverseFlags & REMOVED);\n }\n set removed(v) {\n if (v) {\n this._traverseFlags |= REMOVED;\n } else {\n this._traverseFlags &= ~REMOVED;\n }\n }\n}\n\nObject.assign(\n NodePath.prototype,\n NodePath_ancestry,\n NodePath_inference,\n NodePath_replacement,\n NodePath_evaluation,\n NodePath_conversion,\n NodePath_introspection,\n NodePath_context,\n NodePath_removal,\n NodePath_modification,\n NodePath_family,\n NodePath_comments,\n);\n\nif (!process.env.BABEL_8_BREAKING) {\n // @ts-expect-error The original _guessExecutionStatusRelativeToDifferentFunctions only worked for paths in\n // different functions, but _guessExecutionStatusRelativeTo works as a replacement in those cases.\n NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions =\n NodePath_introspection._guessExecutionStatusRelativeTo;\n}\n\n// we can not use `import { TYPES } from \"@babel/types\"` here\n// because the transformNamedBabelTypesImportToDestructuring plugin in babel.config.js\n// does not offer live bindings for `TYPES`\n// we can change to `import { TYPES }` when we are publishing ES modules only\nfor (const type of t.TYPES) {\n const typeKey = `is${type}`;\n // @ts-expect-error typeKey must present in t\n const fn = t[typeKey];\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[typeKey] = function (opts: any) {\n return fn(this.node, opts);\n };\n\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[`assert${type}`] = function (opts: any) {\n if (!fn(this.node, opts)) {\n throw new TypeError(`Expected node path of type ${type}`);\n }\n };\n}\n\n// Register virtual types validators after base types validators\nObject.assign(NodePath.prototype, NodePath_virtual_types_validator);\n\nfor (const type of Object.keys(virtualTypes) as (keyof typeof virtualTypes)[]) {\n if (type[0] === \"_\") continue;\n if (!t.TYPES.includes(type)) t.TYPES.push(type);\n}\n\ntype NodePathMixins = typeof NodePath_ancestry &\n typeof NodePath_inference &\n typeof NodePath_replacement &\n typeof NodePath_evaluation &\n typeof NodePath_conversion &\n typeof NodePath_introspection &\n typeof NodePath_context &\n typeof NodePath_removal &\n typeof NodePath_modification &\n typeof NodePath_family &\n typeof NodePath_comments;\n\n// @ts-expect-error TS throws because ensureBlock returns the body node path\n// however, we don't use the return value and treat it as a transform and\n// assertion utilities. For better type inference we annotate it as an\n// assertion method\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ninterface NodePath<T>\n extends NodePathAssertions,\n NodePathValidators,\n NodePathMixins {\n /**\n * @see ./conversion.ts for implementation\n */\n ensureBlock<\n T extends\n | t.Loop\n | t.WithStatement\n | t.Function\n | t.LabeledStatement\n | t.CatchClause,\n >(\n this: NodePath<T>,\n ): asserts this is NodePath<T & { body: t.BlockStatement }>;\n}\n\nexport default NodePath;\n"],"mappings":";;;;;;AAEA;AACA;AACA;AAEA;AACA;AAAwC;AAExC;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAkF;EAjBzEA;AAAQ;AAqBjB,MAAMC,KAAK,GAAGC,MAAU,CAAC,OAAO,CAAC;AAE1B,MAAMC,OAAO,GAAG,CAAC,IAAI,CAAC;AAAC;AACvB,MAAMC,WAAW,GAAG,CAAC,IAAI,CAAC;AAAC;AAC3B,MAAMC,WAAW,GAAG,CAAC,IAAI,CAAC;AAAC;AAElC,MAAMC,QAAQ,CAA4B;EACxCC,WAAW,CAACC,GAAiB,EAAEC,MAA+B,EAAE;IAAA,KAgBhEC,QAAQ,GAA4B,EAAE;IAAA,KACtCC,KAAK,GAAQ,IAAI;IAAA,KACjBC,IAAI,GAAQ,IAAI;IAAA,KAEhBC,cAAc,GAAW,CAAC;IAAA,KAC1BC,QAAQ,GAAQ,IAAI;IAAA,KACpBC,UAAU,GAEqC,IAAI;IAAA,KACnDC,SAAS,GAAkC,IAAI;IAAA,KAC/CC,OAAO,GAAkB,IAAI;IAAA,KAC7BC,GAAG,GAA2B,IAAI;IAAA,KAClCC,IAAI,GAAM,IAAI;IAAA,KACdC,IAAI,GAAqB,IAAI;IA5B3B,IAAI,CAACX,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACD,GAAG,GAAGA,GAAG;IACd,IAAI,CAACa,IAAI,GAAG,IAAI;IAEhB,IAAI,CAACC,OAAO,GAAG,IAAI;IACnB,IAAI,CAACC,KAAK,GAAG,IAAI;EACnB;EAwBA,OAAOC,GAAG,CAAC;IACThB,GAAG;IACHO,UAAU;IACVN,MAAM;IACNO,SAAS;IACTC,OAAO;IACPC;EAQF,CAAC,EAAY;IACX,IAAI,CAACV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mC;EAC7E,IAAInE,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;EACrB,IAAI,CAAC4D,CAAC,CAACC,KAAK,CAACO,QAAQ,CAACpE,IAAI,CAAC,EAAE4D,CAAC,CAACC,KAAK,CAACQ,IAAI,CAACrE,IAAI,CAAC;AACjD;AAAC,eAsCcd,QAAQ;AAAA"}
1
+ {"version":3,"names":["validate","debug","buildDebug","REMOVED","SHOULD_STOP","SHOULD_SKIP","NodePath","constructor","hub","parent","contexts","state","opts","_traverseFlags","skipKeys","parentPath","container","listKey","key","node","type","data","context","scope","get","Error","targetNode","paths","pathCache","Map","set","path","setup","getScope","isScope","Scope","setData","val","Object","create","getData","def","undefined","hasNode","buildCodeFrameError","msg","SyntaxError","buildError","traverse","visitor","getPathLocation","parts","inList","unshift","join","message","enabled","toString","generator","code","parentKey","shouldSkip","v","shouldStop","removed","assign","prototype","NodePath_ancestry","NodePath_inference","NodePath_replacement","NodePath_evaluation","NodePath_conversion","NodePath_introspection","NodePath_context","NodePath_removal","NodePath_modification","NodePath_family","NodePath_comments","_guessExecutionStatusRelativeToDifferentFunctions","_guessExecutionStatusRelativeTo","t","TYPES","typeKey","fn","TypeError","NodePath_virtual_types_validator","keys","virtualTypes","includes","push"],"sources":["../../src/path/index.ts"],"sourcesContent":["import type { HubInterface } from \"../hub\";\nimport type TraversalContext from \"../context\";\nimport * as virtualTypes from \"./lib/virtual-types\";\nimport buildDebug from \"debug\";\nimport traverse from \"../index\";\nimport type { Visitor } from \"../types\";\nimport Scope from \"../scope\";\nimport { validate } from \"@babel/types\";\nimport * as t from \"@babel/types\";\nimport { path as pathCache } from \"../cache\";\nimport generator from \"@babel/generator\";\n\n// NodePath is split across many files.\nimport * as NodePath_ancestry from \"./ancestry\";\nimport * as NodePath_inference from \"./inference\";\nimport * as NodePath_replacement from \"./replacement\";\nimport * as NodePath_evaluation from \"./evaluation\";\nimport * as NodePath_conversion from \"./conversion\";\nimport * as NodePath_introspection from \"./introspection\";\nimport * as NodePath_context from \"./context\";\nimport * as NodePath_removal from \"./removal\";\nimport * as NodePath_modification from \"./modification\";\nimport * as NodePath_family from \"./family\";\nimport * as NodePath_comments from \"./comments\";\nimport * as NodePath_virtual_types_validator from \"./lib/virtual-types-validator\";\nimport type { NodePathAssertions } from \"./generated/asserts\";\nimport type { NodePathValidators } from \"./generated/validators\";\n\nconst debug = buildDebug(\"babel\");\n\nexport const REMOVED = 1 << 0;\nexport const SHOULD_STOP = 1 << 1;\nexport const SHOULD_SKIP = 1 << 2;\n\nclass NodePath<T extends t.Node = t.Node> {\n constructor(hub: HubInterface, parent: t.ParentMaps[T[\"type\"]]) {\n this.parent = parent;\n this.hub = hub;\n this.data = null;\n\n this.context = null;\n this.scope = null;\n }\n\n declare parent: t.ParentMaps[T[\"type\"]];\n declare hub: HubInterface;\n declare data: Record<string | symbol, unknown>;\n // TraversalContext is configured by setContext\n declare context: TraversalContext;\n declare scope: Scope;\n\n contexts: Array<TraversalContext> = [];\n state: any = null;\n opts: any = null;\n // this.shouldSkip = false; this.shouldStop = false; this.removed = false;\n _traverseFlags: number = 0;\n skipKeys: any = null;\n parentPath: t.ParentMaps[T[\"type\"]] extends null\n ? null\n : NodePath<t.ParentMaps[T[\"type\"]]> | null = null;\n container: t.Node | Array<t.Node> | null = null;\n listKey: string | null = null;\n key: string | number | null = null;\n node: T = null;\n type: T[\"type\"] | null = null;\n\n static get({\n hub,\n parentPath,\n parent,\n container,\n listKey,\n key,\n }: {\n hub?: HubInterface;\n parentPath: NodePath | null;\n parent: t.Node;\n container: t.Node | t.Node[];\n listKey?: string;\n key: string | number;\n }): NodePath {\n if (!hub && parentPath) {\n hub = parentPath.hub;\n }\n\n if (!parent) {\n throw new Error(\"To get a node path the parent needs to exist\");\n }\n\n const targetNode =\n // @ts-expect-error key must present in container\n container[key];\n\n let paths = pathCache.get(parent);\n if (!paths) {\n paths = new Map();\n pathCache.set(parent, paths);\n }\n\n let path = paths.get(targetNode);\n if (!path) {\n path = new NodePath(hub, parent);\n if (targetNode) paths.set(targetNode, path);\n }\n\n path.setup(parentPath, container, listKey, key);\n\n return path;\n }\n\n getScope(scope: Scope): Scope {\n return this.isScope() ? new Scope(this) : scope;\n }\n\n setData(key: string | symbol, val: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n return (this.data[key] = val);\n }\n\n getData(key: string | symbol, def?: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n let val = this.data[key];\n if (val === undefined && def !== undefined) val = this.data[key] = def;\n return val;\n }\n\n hasNode(): this is NodePath<NonNullable<this[\"node\"]>> {\n return this.node != null;\n }\n\n buildCodeFrameError(\n msg: string,\n Error: new () => Error = SyntaxError,\n ): Error {\n return this.hub.buildError(this.node, msg, Error);\n }\n\n traverse<T>(visitor: Visitor<T>, state: T): void;\n traverse(visitor: Visitor): void;\n traverse(visitor: any, state?: any) {\n traverse(this.node, visitor, this.scope, state, this);\n }\n\n set(key: string, node: any) {\n validate(this.node, key, node);\n // @ts-expect-error key must present in this.node\n this.node[key] = node;\n }\n\n getPathLocation(): string {\n const parts = [];\n let path: NodePath = this;\n do {\n let key = path.key;\n if (path.inList) key = `${path.listKey}[${key}]`;\n parts.unshift(key);\n } while ((path = path.parentPath));\n return parts.join(\".\");\n }\n\n debug(message: string) {\n if (!debug.enabled) return;\n debug(`${this.getPathLocation()} ${this.type}: ${message}`);\n }\n\n toString() {\n return generator(this.node).code;\n }\n\n get inList() {\n return !!this.listKey;\n }\n\n set inList(inList) {\n if (!inList) {\n this.listKey = null;\n }\n // ignore inList = true as it should depend on `listKey`\n }\n\n get parentKey(): string {\n return (this.listKey || this.key) as string;\n }\n\n get shouldSkip() {\n return !!(this._traverseFlags & SHOULD_SKIP);\n }\n\n set shouldSkip(v) {\n if (v) {\n this._traverseFlags |= SHOULD_SKIP;\n } else {\n this._traverseFlags &= ~SHOULD_SKIP;\n }\n }\n\n get shouldStop() {\n return !!(this._traverseFlags & SHOULD_STOP);\n }\n\n set shouldStop(v) {\n if (v) {\n this._traverseFlags |= SHOULD_STOP;\n } else {\n this._traverseFlags &= ~SHOULD_STOP;\n }\n }\n\n get removed() {\n return !!(this._traverseFlags & REMOVED);\n }\n set removed(v) {\n if (v) {\n this._traverseFlags |= REMOVED;\n } else {\n this._traverseFlags &= ~REMOVED;\n }\n }\n}\n\nObject.assign(\n NodePath.prototype,\n NodePath_ancestry,\n NodePath_inference,\n NodePath_replacement,\n NodePath_evaluation,\n NodePath_conversion,\n NodePath_introspection,\n NodePath_context,\n NodePath_removal,\n NodePath_modification,\n NodePath_family,\n NodePath_comments,\n);\n\nif (!process.env.BABEL_8_BREAKING) {\n // @ts-expect-error The original _guessExecutionStatusRelativeToDifferentFunctions only worked for paths in\n // different functions, but _guessExecutionStatusRelativeTo works as a replacement in those cases.\n NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions =\n NodePath_introspection._guessExecutionStatusRelativeTo;\n}\n\n// we can not use `import { TYPES } from \"@babel/types\"` here\n// because the transformNamedBabelTypesImportToDestructuring plugin in babel.config.js\n// does not offer live bindings for `TYPES`\n// we can change to `import { TYPES }` when we are publishing ES modules only\nfor (const type of t.TYPES) {\n const typeKey = `is${type}`;\n // @ts-expect-error typeKey must present in t\n const fn = t[typeKey];\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[typeKey] = function (opts: any) {\n return fn(this.node, opts);\n };\n\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[`assert${type}`] = function (opts: any) {\n if (!fn(this.node, opts)) {\n throw new TypeError(`Expected node path of type ${type}`);\n }\n };\n}\n\n// Register virtual types validators after base types validators\nObject.assign(NodePath.prototype, NodePath_virtual_types_validator);\n\nfor (const type of Object.keys(virtualTypes) as (keyof typeof virtualTypes)[]) {\n if (type[0] === \"_\") continue;\n if (!t.TYPES.includes(type)) t.TYPES.push(type);\n}\n\ntype NodePathMixins = typeof NodePath_ancestry &\n typeof NodePath_inference &\n typeof NodePath_replacement &\n typeof NodePath_evaluation &\n typeof NodePath_conversion &\n typeof NodePath_introspection &\n typeof NodePath_context &\n typeof NodePath_removal &\n typeof NodePath_modification &\n typeof NodePath_family &\n typeof NodePath_comments;\n\n// @ts-expect-error TS throws because ensureBlock returns the body node path\n// however, we don't use the return value and treat it as a transform and\n// assertion utilities. For better type inference we annotate it as an\n// assertion method\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ninterface NodePath<T>\n extends NodePathAssertions,\n NodePathValidators,\n NodePathMixins {\n /**\n * @see ./conversion.ts for implementation\n */\n ensureBlock<\n T extends\n | t.Loop\n | t.WithStatement\n | t.Function\n | t.LabeledStatement\n | t.CatchClause,\n >(\n this: NodePath<T>,\n ): asserts this is NodePath<T & { body: t.BlockStatement }>;\n}\n\nexport default NodePath;\n"],"mappings":";;;;;;AAEA;AACA;AACA;AAEA;AACA;AAAwC;AAExC;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAkF;EAjBzEA;AAAQ;AAqBjB,MAAMC,KAAK,GAAGC,MAAU,CAAC,OAAO,CAAC;AAE1B,MAAMC,OAAO,GAAG,CAAC,IAAI,CAAC;AAAC;AACvB,MAAMC,WAAW,GAAG,CAAC,IAAI,CAAC;AAAC;AAC3B,MAAMC,WAAW,GAAG,CAAC,IAAI,CAAC;AAAC;AAElC,MAAMC,QAAQ,CAA4B;EACxCC,WAAW,CAACC,GAAiB,EAAEC,MAA+B,EAAE;IAAA,KAgBhEC,QAAQ,GAA4B,EAAE;IAAA,KACtCC,KAAK,GAAQ,IAAI;IAAA,KACjBC,IAAI,GAAQ,IAAI;IAAA,KAEhBC,cAAc,GAAW,CAAC;IAAA,KAC1BC,QAAQ,GAAQ,IAAI;IAAA,KACpBC,UAAU,GAEqC,IAAI;IAAA,KACnDC,SAAS,GAAkC,IAAI;IAAA,KAC/CC,OAAO,GAAkB,IAAI;IAAA,KAC7BC,GAAG,GAA2B,IAAI;IAAA,KAClCC,IAAI,GAAM,IAAI;IAAA,KACdC,I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IAAS,EAAE;IACzD,IAAI,CAACuE,EAAE,CAAC,IAAI,CAAChE,IAAI,EAAEP,IAAI,CAAC,EAAE;MACxB,MAAM,IAAIwE,SAAS,CAAE,8BAA6BhE,IAAK,EAAC,CAAC;IAC3D;EACF,CAAC;AACH;AAGAkB,MAAM,CAAC2B,MAAM,CAAC3D,QAAQ,CAAC4D,SAAS,EAAEmB,gCAAgC,CAAC;AAEnE,KAAK,MAAMjE,IAAI,IAAIkB,MAAM,CAACgD,IAAI,CAACC,YAAY,CAAC,EAAmC;EAC7E,IAAInE,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;EACrB,IAAI,CAAC4D,CAAC,CAACC,KAAK,CAACO,QAAQ,CAACpE,IAAI,CAAC,EAAE4D,CAAC,CAACC,KAAK,CAACQ,IAAI,CAACrE,IAAI,CAAC;AACjD;AAAC,eAsCcd,QAAQ;AAAA"}
@@ -33,7 +33,6 @@ const {
33
33
  stringTypeAnnotation,
34
34
  voidTypeAnnotation
35
35
  } = _t;
36
-
37
36
  function getTypeAnnotation() {
38
37
  let type = this.getData("typeAnnotation");
39
38
  if (type != null) {
@@ -46,20 +45,16 @@ function getTypeAnnotation() {
46
45
  this.setData("typeAnnotation", type);
47
46
  return type;
48
47
  }
49
-
50
48
  const typeAnnotationInferringNodes = new WeakSet();
51
-
52
49
  function _getTypeAnnotation() {
53
50
  const node = this.node;
54
51
  if (!node) {
55
52
  if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
56
53
  const declar = this.parentPath.parentPath;
57
54
  const declarParent = declar.parentPath;
58
-
59
55
  if (declar.key === "left" && declarParent.isForInStatement()) {
60
56
  return stringTypeAnnotation();
61
57
  }
62
-
63
58
  if (declar.key === "left" && declarParent.isForOfStatement()) {
64
59
  return anyTypeAnnotation();
65
60
  }
@@ -68,7 +63,6 @@ function _getTypeAnnotation() {
68
63
  return;
69
64
  }
70
65
  }
71
-
72
66
  if (node.typeAnnotation) {
73
67
  return node.typeAnnotation;
74
68
  }
@@ -78,12 +72,10 @@ function _getTypeAnnotation() {
78
72
  typeAnnotationInferringNodes.add(node);
79
73
  try {
80
74
  var _inferer;
81
- let inferer =
82
- inferers[node.type];
75
+ let inferer = inferers[node.type];
83
76
  if (inferer) {
84
77
  return inferer.call(this, node);
85
78
  }
86
-
87
79
  inferer = inferers[this.parentPath.type];
88
80
  if ((_inferer = inferer) != null && _inferer.validParent) {
89
81
  return this.parentPath.getTypeAnnotation();
@@ -1 +1 @@
1
- {"version":3,"names":["anyTypeAnnotation","isAnyTypeAnnotation","isArrayTypeAnnotation","isBooleanTypeAnnotation","isEmptyTypeAnnotation","isFlowBaseAnnotation","isGenericTypeAnnotation","isIdentifier","isMixedTypeAnnotation","isNumberTypeAnnotation","isStringTypeAnnotation","isTSArrayType","isTSTypeAnnotation","isTSTypeReference","isTupleTypeAnnotation","isTypeAnnotation","isUnionTypeAnnotation","isVoidTypeAnnotation","stringTypeAnnotation","voidTypeAnnotation","getTypeAnnotation","type","getData","_getTypeAnnotation","typeAnnotation","setData","typeAnnotationInferringNodes","WeakSet","node","key","parentPath","isVariableDeclarator","declar","declarParent","isForInStatement","isForOfStatement","has","add","inferer","inferers","call","validParent","delete","isBaseType","baseName","soft","_isBaseType","Error","couldBeBaseType","name","type2","types","baseTypeStrictlyMatches","rightArg","left","right","isGenericType","genericName","id","typeName"],"sources":["../../../src/path/inference/index.ts"],"sourcesContent":["import type NodePath from \"../index\";\nimport * as inferers from \"./inferers\";\nimport {\n anyTypeAnnotation,\n isAnyTypeAnnotation,\n isArrayTypeAnnotation,\n isBooleanTypeAnnotation,\n isEmptyTypeAnnotation,\n isFlowBaseAnnotation,\n isGenericTypeAnnotation,\n isIdentifier,\n isMixedTypeAnnotation,\n isNumberTypeAnnotation,\n isStringTypeAnnotation,\n isTSArrayType,\n isTSTypeAnnotation,\n isTSTypeReference,\n isTupleTypeAnnotation,\n isTypeAnnotation,\n isUnionTypeAnnotation,\n isVoidTypeAnnotation,\n stringTypeAnnotation,\n voidTypeAnnotation,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Infer the type of the current `NodePath`.\n */\n\nexport function getTypeAnnotation(this: NodePath): t.FlowType | t.TSType {\n let type = this.getData(\"typeAnnotation\");\n if (type != null) {\n return type;\n }\n type = this._getTypeAnnotation() || anyTypeAnnotation();\n if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {\n type = type.typeAnnotation;\n }\n this.setData(\"typeAnnotation\", type);\n return type;\n}\n\n// Used to avoid infinite recursion in cases like\n// var b, c; if (0) { c = 1; b = c; } c = b;\n// It also works with indirect recursion.\nconst typeAnnotationInferringNodes = new WeakSet();\n\n/**\n * todo: split up this method\n */\n\nexport function _getTypeAnnotation(this: NodePath): any {\n const node = this.node;\n\n if (!node) {\n // handle initializerless variables, add in checks for loop initializers too\n if (this.key === \"init\" && this.parentPath.isVariableDeclarator()) {\n const declar = this.parentPath.parentPath;\n const declarParent = declar.parentPath;\n\n // for (let NODE in bar) {}\n if (declar.key === \"left\" && declarParent.isForInStatement()) {\n return stringTypeAnnotation();\n }\n\n // for (let NODE of bar) {}\n if (declar.key === \"left\" && declarParent.isForOfStatement()) {\n return anyTypeAnnotation();\n }\n\n return voidTypeAnnotation();\n } else {\n return;\n }\n }\n\n // @ts-expect-error typeAnnotation may not index node\n if (node.typeAnnotation) {\n // @ts-expect-error typeAnnotation may not index node\n return node.typeAnnotation;\n }\n\n if (typeAnnotationInferringNodes.has(node)) {\n // Bail out from type inference to avoid infinite loops\n return;\n }\n typeAnnotationInferringNodes.add(node);\n\n try {\n let inferer =\n // @ts-expect-error inferers do not cover all AST types\n inferers[node.type];\n if (inferer) {\n return inferer.call(this, node);\n }\n\n // @ts-expect-error inferers do not cover all AST types\n inferer = inferers[this.parentPath.type];\n if (inferer?.validParent) {\n return this.parentPath.getTypeAnnotation();\n }\n } finally {\n typeAnnotationInferringNodes.delete(node);\n }\n}\n\nexport function isBaseType(\n this: NodePath,\n baseName: string,\n soft?: boolean,\n): boolean {\n return _isBaseType(baseName, this.getTypeAnnotation(), soft);\n}\n\nfunction _isBaseType(\n baseName: string,\n type?: t.FlowType | t.TSType,\n soft?: boolean,\n): boolean {\n if (baseName === \"string\") {\n return isStringTypeAnnotation(type);\n } else if (baseName === \"number\") {\n return isNumberTypeAnnotation(type);\n } else if (baseName === \"boolean\") {\n return isBooleanTypeAnnotation(type);\n } else if (baseName === \"any\") {\n return isAnyTypeAnnotation(type);\n } else if (baseName === \"mixed\") {\n return isMixedTypeAnnotation(type);\n } else if (baseName === \"empty\") {\n return isEmptyTypeAnnotation(type);\n } else if (baseName === \"void\") {\n return isVoidTypeAnnotation(type);\n } else {\n if (soft) {\n return false;\n } else {\n throw new Error(`Unknown base type ${baseName}`);\n }\n }\n}\n\nexport function couldBeBaseType(this: NodePath, name: string): boolean {\n const type = this.getTypeAnnotation();\n if (isAnyTypeAnnotation(type)) return true;\n\n if (isUnionTypeAnnotation(type)) {\n for (const type2 of type.types) {\n if (isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {\n return true;\n }\n }\n return false;\n } else {\n return _isBaseType(name, type, true);\n }\n}\n\nexport function baseTypeStrictlyMatches(\n this: NodePath,\n rightArg: NodePath,\n): boolean {\n const left = this.getTypeAnnotation();\n const right = rightArg.getTypeAnnotation();\n\n if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) {\n return right.type === left.type;\n }\n return false;\n}\n\nexport function isGenericType(this: NodePath, genericName: string): boolean {\n const type = this.getTypeAnnotation();\n if (genericName === \"Array\") {\n // T[]\n if (\n isTSArrayType(type) ||\n isArrayTypeAnnotation(type) ||\n isTupleTypeAnnotation(type)\n ) {\n return true;\n }\n }\n return (\n (isGenericTypeAnnotation(type) &&\n isIdentifier(type.id, {\n name: genericName,\n })) ||\n (isTSTypeReference(type) &&\n isIdentifier(type.typeName, {\n name: genericName,\n }))\n );\n}\n"],"mappings":";;;;;;;;;;;AACA;AACA;AAqBsB;EApBpBA,iBAAiB;EACjBC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BAAoB,CAACiD,IAAI,CAAC,EAAE;IAC5D,OAAOC,KAAK,CAAClC,IAAI,KAAKiC,IAAI,CAACjC,IAAI;EACjC;EACA,OAAO,KAAK;AACd;AAEO,SAASmC,aAAa,CAAiBC,WAAmB,EAAW;EAC1E,MAAMpC,IAAI,GAAG,IAAI,CAACD,iBAAiB,EAAE;EACrC,IAAIqC,WAAW,KAAK,OAAO,EAAE;IAE3B,IACE9C,aAAa,CAACU,IAAI,CAAC,IACnBnB,qBAAqB,CAACmB,IAAI,CAAC,IAC3BP,qBAAqB,CAACO,IAAI,CAAC,EAC3B;MACA,OAAO,IAAI;IACb;EACF;EACA,OACGf,uBAAuB,CAACe,IAAI,CAAC,IAC5Bd,YAAY,CAACc,IAAI,CAACqC,EAAE,EAAE;IACpBT,IAAI,EAAEQ;EACR,CAAC,CAAC,IACH5C,iBAAiB,CAACQ,IAAI,CAAC,IACtBd,YAAY,CAACc,IAAI,CAACsC,QAAQ,EAAE;IAC1BV,IAAI,EAAEQ;EACR,CAAC,CAAE;AAET"}
1
+ {"version":3,"names":["anyTypeAnnotation","isAnyTypeAnnotation","isArrayTypeAnnotation","isBooleanTypeAnnotation","isEmptyTypeAnnotation","isFlowBaseAnnotation","isGenericTypeAnnotation","isIdentifier","isMixedTypeAnnotation","isNumberTypeAnnotation","isStringTypeAnnotation","isTSArrayType","isTSTypeAnnotation","isTSTypeReference","isTupleTypeAnnotation","isTypeAnnotation","isUnionTypeAnnotation","isVoidTypeAnnotation","stringTypeAnnotation","voidTypeAnnotation","getTypeAnnotation","type","getData","_getTypeAnnotation","typeAnnotation","setData","typeAnnotationInferringNodes","WeakSet","node","key","parentPath","isVariableDeclarator","declar","declarParent","isForInStatement","isForOfStatement","has","add","inferer","inferers","call","validParent","delete","isBaseType","baseName","soft","_isBaseType","Error","couldBeBaseType","name","type2","types","baseTypeStrictlyMatches","rightArg","left","right","isGenericType","genericName","id","typeName"],"sources":["../../../src/path/inference/index.ts"],"sourcesContent":["import type NodePath from \"../index\";\nimport * as inferers from \"./inferers\";\nimport {\n anyTypeAnnotation,\n isAnyTypeAnnotation,\n isArrayTypeAnnotation,\n isBooleanTypeAnnotation,\n isEmptyTypeAnnotation,\n isFlowBaseAnnotation,\n isGenericTypeAnnotation,\n isIdentifier,\n isMixedTypeAnnotation,\n isNumberTypeAnnotation,\n isStringTypeAnnotation,\n isTSArrayType,\n isTSTypeAnnotation,\n isTSTypeReference,\n isTupleTypeAnnotation,\n isTypeAnnotation,\n isUnionTypeAnnotation,\n isVoidTypeAnnotation,\n stringTypeAnnotation,\n voidTypeAnnotation,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Infer the type of the current `NodePath`.\n */\n\nexport function getTypeAnnotation(this: NodePath): t.FlowType | t.TSType {\n let type = this.getData(\"typeAnnotation\");\n if (type != null) {\n return type;\n }\n type = this._getTypeAnnotation() || anyTypeAnnotation();\n if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {\n type = type.typeAnnotation;\n }\n this.setData(\"typeAnnotation\", type);\n return type;\n}\n\n// Used to avoid infinite recursion in cases like\n// var b, c; if (0) { c = 1; b = c; } c = b;\n// It also works with indirect recursion.\nconst typeAnnotationInferringNodes = new WeakSet();\n\n/**\n * todo: split up this method\n */\n\nexport function _getTypeAnnotation(this: NodePath): any {\n const node = this.node;\n\n if (!node) {\n // handle initializerless variables, add in checks for loop initializers too\n if (this.key === \"init\" && this.parentPath.isVariableDeclarator()) {\n const declar = this.parentPath.parentPath;\n const declarParent = declar.parentPath;\n\n // for (let NODE in bar) {}\n if (declar.key === \"left\" && declarParent.isForInStatement()) {\n return stringTypeAnnotation();\n }\n\n // for (let NODE of bar) {}\n if (declar.key === \"left\" && declarParent.isForOfStatement()) {\n return anyTypeAnnotation();\n }\n\n return voidTypeAnnotation();\n } else {\n return;\n }\n }\n\n // @ts-expect-error typeAnnotation may not index node\n if (node.typeAnnotation) {\n // @ts-expect-error typeAnnotation may not index node\n return node.typeAnnotation;\n }\n\n if (typeAnnotationInferringNodes.has(node)) {\n // Bail out from type inference to avoid infinite loops\n return;\n }\n typeAnnotationInferringNodes.add(node);\n\n try {\n let inferer =\n // @ts-expect-error inferers do not cover all AST types\n inferers[node.type];\n if (inferer) {\n return inferer.call(this, node);\n }\n\n // @ts-expect-error inferers do not cover all AST types\n inferer = inferers[this.parentPath.type];\n if (inferer?.validParent) {\n return this.parentPath.getTypeAnnotation();\n }\n } finally {\n typeAnnotationInferringNodes.delete(node);\n }\n}\n\nexport function isBaseType(\n this: NodePath,\n baseName: string,\n soft?: boolean,\n): boolean {\n return _isBaseType(baseName, this.getTypeAnnotation(), soft);\n}\n\nfunction _isBaseType(\n baseName: string,\n type?: t.FlowType | t.TSType,\n soft?: boolean,\n): boolean {\n if (baseName === \"string\") {\n return isStringTypeAnnotation(type);\n } else if (baseName === \"number\") {\n return isNumberTypeAnnotation(type);\n } else if (baseName === \"boolean\") {\n return isBooleanTypeAnnotation(type);\n } else if (baseName === \"any\") {\n return isAnyTypeAnnotation(type);\n } else if (baseName === \"mixed\") {\n return isMixedTypeAnnotation(type);\n } else if (baseName === \"empty\") {\n return isEmptyTypeAnnotation(type);\n } else if (baseName === \"void\") {\n return isVoidTypeAnnotation(type);\n } else {\n if (soft) {\n return false;\n } else {\n throw new Error(`Unknown base type ${baseName}`);\n }\n }\n}\n\nexport function couldBeBaseType(this: NodePath, name: string): boolean {\n const type = this.getTypeAnnotation();\n if (isAnyTypeAnnotation(type)) return true;\n\n if (isUnionTypeAnnotation(type)) {\n for (const type2 of type.types) {\n if (isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {\n return true;\n }\n }\n return false;\n } else {\n return _isBaseType(name, type, true);\n }\n}\n\nexport function baseTypeStrictlyMatches(\n this: NodePath,\n rightArg: NodePath,\n): boolean {\n const left = this.getTypeAnnotation();\n const right = rightArg.getTypeAnnotation();\n\n if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) {\n return right.type === left.type;\n }\n return false;\n}\n\nexport function isGenericType(this: NodePath, genericName: string): boolean {\n const type = this.getTypeAnnotation();\n if (genericName === \"Array\") {\n // T[]\n if (\n isTSArrayType(type) ||\n isArrayTypeAnnotation(type) ||\n isTupleTypeAnnotation(type)\n ) {\n return true;\n }\n }\n return (\n (isGenericTypeAnnotation(type) &&\n isIdentifier(type.id, {\n name: genericName,\n })) ||\n (isTSTypeReference(type) &&\n isIdentifier(type.typeName, {\n name: genericName,\n }))\n );\n}\n"],"mappings":";;;;;;;;;;;AACA;AACA;AAqBsB;EApBpBA,iBAAiB;EACjBC,mBAAmB;EACnBC,qBAAqB;EACrBC,uBAAuB;EACvBC,qBAAqB;EACrBC,oBAAoB;EACpBC,uBAAuB;EACvBC,YAAY;EACZC,qBAAqB;EACrBC,sBAAsB;EACtBC,sBAAsB;EACtBC,aAAa;EACbC,kBAAkB;EAClBC,iBAAiB;EACjBC,qBAAqB;EACrBC,gBAAgB;EAChBC,qBAAqB;EACrBC,oBAAoB;EACpBC,oBAAoB;EACpBC;AAAkB;AAQb,SAASC,iBAAiB,GAAwC;EACvE,IAAIC,IAAI,GAAG,IAAI,CAACC,OAAO,CAAC,gBAAgB,CAAC;EACzC,IAAID,IAAI,IAAI,IAAI,EAAE;IAChB,OAAOA,IAAI;EACb;EACAA,IAAI,GAAG,IAAI,CAACE,kBAAkB,EAAE,IAAIvB,iBAAiB,EAAE;EACvD,IAAIe,gBAAgB,CAACM,IAAI,CAAC,IAAIT,kBAAkB,CAACS,IAAI,CAAC,EAAE;IACtDA,IAAI,GAAGA,IAAI,CAACG,cAAc;EAC5B;EACA,IAAI,CAACC,OAAO,CAAC,gBAAgB,EAAEJ,IAAI,CAAC;EACpC,OAAOA,IAAI;AACb;AAKA,MAAMK,4BAA4B,GAAG,IAAIC,OAAO,EAAE;AAM3C,SAASJ,kBAAkB,GAAsB;EACtD,MAAMK,IAAI,GAAG,IAAI,CAACA,IAAI;EAEtB,IAAI,CAACA,IAAI,EAAE;IAET,IAAI,IAAI,C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