@babel/traverse 7.18.10 → 7.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @babel/traverse might be problematic. Click here for more details.
- package/lib/cache.js +3 -1
- package/lib/cache.js.map +1 -0
- package/lib/context.js +3 -1
- package/lib/context.js.map +1 -0
- package/lib/hub.js +3 -1
- package/lib/hub.js.map +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -0
- package/lib/path/ancestry.js +3 -3
- package/lib/path/ancestry.js.map +1 -0
- package/lib/path/comments.js +3 -1
- package/lib/path/comments.js.map +1 -0
- package/lib/path/context.js +3 -1
- package/lib/path/context.js.map +1 -0
- package/lib/path/conversion.js +3 -1
- package/lib/path/conversion.js.map +1 -0
- package/lib/path/evaluation.js +13 -6
- package/lib/path/evaluation.js.map +1 -0
- package/lib/path/family.js +4 -2
- package/lib/path/family.js.map +1 -0
- package/lib/path/generated/asserts.js +1 -3
- package/lib/path/generated/asserts.js.map +1 -0
- package/lib/path/generated/validators.js +3 -0
- package/lib/path/generated/validators.js.map +1 -0
- package/lib/path/index.js +3 -1
- package/lib/path/index.js.map +1 -0
- package/lib/path/inference/index.js +3 -1
- package/lib/path/inference/index.js.map +1 -0
- package/lib/path/inference/inferer-reference.js +3 -1
- package/lib/path/inference/inferer-reference.js.map +1 -0
- package/lib/path/inference/inferers.js +3 -1
- package/lib/path/inference/inferers.js.map +1 -0
- package/lib/path/inference/util.js +3 -1
- package/lib/path/inference/util.js.map +1 -0
- package/lib/path/introspection.js +3 -1
- package/lib/path/introspection.js.map +1 -0
- package/lib/path/lib/hoister.js +3 -1
- package/lib/path/lib/hoister.js.map +1 -0
- package/lib/path/lib/removal-hooks.js +4 -5
- package/lib/path/lib/removal-hooks.js.map +1 -0
- package/lib/path/lib/virtual-types-validator.js +3 -1
- package/lib/path/lib/virtual-types-validator.js.map +1 -0
- package/lib/path/lib/virtual-types.js +3 -1
- package/lib/path/lib/virtual-types.js.map +1 -0
- package/lib/path/modification.js +3 -1
- package/lib/path/modification.js.map +1 -0
- package/lib/path/removal.js +3 -1
- package/lib/path/removal.js.map +1 -0
- package/lib/path/replacement.js +3 -1
- package/lib/path/replacement.js.map +1 -0
- package/lib/scope/binding.js +3 -1
- package/lib/scope/binding.js.map +1 -0
- package/lib/scope/index.js +3 -1
- package/lib/scope/index.js.map +1 -0
- package/lib/scope/lib/renamer.js +3 -3
- package/lib/scope/lib/renamer.js.map +1 -0
- package/lib/traverse-node.js +3 -1
- package/lib/traverse-node.js.map +1 -0
- package/lib/types.js +2 -2
- package/lib/types.js.map +1 -0
- package/lib/visitors.js +4 -2
- package/lib/visitors.js.map +1 -0
- package/package.json +5 -5
- package/scripts/generators/asserts.js +2 -2
package/lib/cache.js
CHANGED
package/lib/cache.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["path","WeakMap","scope","clear","clearPath","clearScope"],"sources":["../src/cache.ts"],"sourcesContent":["export let path = new WeakMap();\nexport let scope = new WeakMap();\n\nexport function clear() {\n clearPath();\n clearScope();\n}\n\nexport function clearPath() {\n path = new WeakMap();\n}\n\nexport function clearScope() {\n scope = new WeakMap();\n}\n"],"mappings":";;;;;;;;;AAAO,IAAIA,IAAI,GAAG,IAAIC,OAAJ,EAAX;;AACA,IAAIC,KAAK,GAAG,IAAID,OAAJ,EAAZ;;;AAEA,SAASE,KAAT,GAAiB;EACtBC,SAAS;EACTC,UAAU;AACX;;AAEM,SAASD,SAAT,GAAqB;EAC1B,eAAAJ,IAAI,GAAG,IAAIC,OAAJ,EAAP;AACD;;AAEM,SAASI,UAAT,GAAsB;EAC3B,gBAAAH,KAAK,GAAG,IAAID,OAAJ,EAAR;AACD"}
|
package/lib/context.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["VISITOR_KEYS","TraversalContext","constructor","scope","opts","state","parentPath","queue","priorityQueue","shouldVisit","node","enter","exit","type","keys","length","key","create","container","listKey","NodePath","get","parent","maybeQueue","path","notPriority","push","visitMultiple","visitQueue","visitSingle","visited","WeakSet","stop","resync","contexts","pushContext","has","add","visit","popContext","nodes","Array","isArray"],"sources":["../src/context.ts"],"sourcesContent":["import NodePath from \"./path\";\nimport { VISITOR_KEYS } from \"@babel/types\";\nimport type Scope from \"./scope\";\nimport type { TraverseOptions } from \".\";\nimport type * as t from \"@babel/types\";\nimport type { Visitor } from \"./types\";\n\nexport default class TraversalContext<S = unknown> {\n constructor(\n scope: Scope,\n opts: TraverseOptions,\n state: S,\n parentPath: NodePath,\n ) {\n this.parentPath = parentPath;\n this.scope = scope;\n this.state = state;\n this.opts = opts;\n }\n\n declare parentPath: NodePath;\n declare scope: Scope;\n declare state: S;\n declare opts: TraverseOptions;\n queue: Array<NodePath> | null = null;\n priorityQueue: Array<NodePath> | null = null;\n\n /**\n * This method does a simple check to determine whether or not we really need to attempt\n * visit a node. This will prevent us from constructing a NodePath.\n */\n\n shouldVisit(node: t.Node): boolean {\n const opts = this.opts as Visitor;\n if (opts.enter || opts.exit) return true;\n\n // check if we have a visitor for this node\n if (opts[node.type]) return true;\n\n // check if we're going to traverse into this node\n const keys: Array<string> | undefined = VISITOR_KEYS[node.type];\n if (!keys?.length) return false;\n\n // we need to traverse into this node so ensure that it has children to traverse into!\n for (const key of keys) {\n if (\n // @ts-expect-error key is from visitor keys\n node[key]\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n create(\n node: t.Node,\n container: t.Node | t.Node[],\n key: string | number,\n listKey?: string,\n ): NodePath {\n // We don't need to `.setContext()` here, since `.visitQueue()` already\n // calls `.pushContext`.\n return NodePath.get({\n parentPath: this.parentPath,\n parent: node,\n container,\n key: key,\n listKey,\n });\n }\n\n maybeQueue(path: NodePath, notPriority?: boolean) {\n if (this.queue) {\n if (notPriority) {\n this.queue.push(path);\n } else {\n this.priorityQueue.push(path);\n }\n }\n }\n\n visitMultiple(container: t.Node[], parent: t.Node, listKey: string) {\n // nothing to traverse!\n if (container.length === 0) return false;\n\n const queue = [];\n\n // build up initial queue\n for (let key = 0; key < container.length; key++) {\n const node = container[key];\n if (node && this.shouldVisit(node)) {\n queue.push(this.create(parent, container, key, listKey));\n }\n }\n\n return this.visitQueue(queue);\n }\n\n visitSingle(node: t.Node, key: string): boolean {\n if (\n this.shouldVisit(\n // @ts-expect-error key may not index node\n node[key],\n )\n ) {\n return this.visitQueue([this.create(node, node, key)]);\n } else {\n return false;\n }\n }\n\n visitQueue(queue: Array<NodePath>): boolean {\n // set queue\n this.queue = queue;\n this.priorityQueue = [];\n\n const visited = new WeakSet();\n let stop = false;\n\n // visit the queue\n for (const path of queue) {\n path.resync();\n\n if (\n path.contexts.length === 0 ||\n path.contexts[path.contexts.length - 1] !== this\n ) {\n // The context might already have been pushed when this path was inserted and queued.\n // If we always re-pushed here, we could get duplicates and risk leaving contexts\n // on the stack after the traversal has completed, which could break things.\n path.pushContext(this);\n }\n\n // this path no longer belongs to the tree\n if (path.key === null) continue;\n\n // ensure we don't visit the same node twice\n const { node } = path;\n if (visited.has(node)) continue;\n if (node) visited.add(node);\n\n if (path.visit()) {\n stop = true;\n break;\n }\n\n if (this.priorityQueue.length) {\n stop = this.visitQueue(this.priorityQueue);\n this.priorityQueue = [];\n this.queue = queue;\n if (stop) break;\n }\n }\n\n // clear queue\n for (const path of queue) {\n path.popContext();\n }\n\n // clear queue\n this.queue = null;\n\n return stop;\n }\n\n visit(node: t.Node, key: string) {\n // @ts-expect-error key may not index node\n const nodes = node[key] as t.Node | t.Node[] | null;\n if (!nodes) return false;\n\n if (Array.isArray(nodes)) {\n return this.visitMultiple(nodes, node, key);\n } else {\n return this.visitSingle(node, key);\n }\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;;EAASA;;;AAMM,MAAMC,gBAAN,CAAoC;EACjDC,WAAW,CACTC,KADS,EAETC,IAFS,EAGTC,KAHS,EAITC,UAJS,EAKT;IAAA,KAWFC,KAXE,GAW8B,IAX9B;IAAA,KAYFC,a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,CAACR,GAAL,KAAa,IAAjB,EAAuB;MAGvB,MAAM;QAAEN;MAAF,IAAWc,IAAjB;MACA,IAAIM,OAAO,CAACM,GAAR,CAAY1B,IAAZ,CAAJ,EAAuB;MACvB,IAAIA,IAAJ,EAAUoB,OAAO,CAACO,GAAR,CAAY3B,IAAZ;;MAEV,IAAIc,IAAI,CAACc,KAAL,EAAJ,EAAkB;QAChBN,IAAI,GAAG,IAAP;QACA;MACD;;MAED,IAAI,KAAKxB,aAAL,CAAmBO,MAAvB,EAA+B;QAC7BiB,IAAI,GAAG,KAAKJ,UAAL,CAAgB,KAAKpB,aAArB,CAAP;QACA,KAAKA,aAAL,GAAqB,EAArB;QACA,KAAKD,KAAL,GAAaA,KAAb;QACA,IAAIyB,IAAJ,EAAU;MACX;IACF;;IAGD,KAAK,MAAMR,IAAX,IAAmBjB,KAAnB,EAA0B;MACxBiB,IAAI,CAACe,UAAL;IACD;;IAGD,KAAKhC,KAAL,GAAa,IAAb;IAEA,OAAOyB,IAAP;EACD;;EAEDM,KAAK,CAAC5B,IAAD,EAAeM,GAAf,EAA4B;IAE/B,MAAMwB,KAAK,GAAG9B,IAAI,CAACM,GAAD,CAAlB;IACA,IAAI,CAACwB,KAAL,EAAY,OAAO,KAAP;;IAEZ,IAAIC,KAAK,CAACC,OAAN,CAAcF,KAAd,CAAJ,EAA0B;MACxB,OAAO,KAAKb,aAAL,CAAmBa,KAAnB,EAA0B9B,IAA1B,EAAgCM,GAAhC,CAAP;IACD,CAFD,MAEO;MACL,OAAO,KAAKa,WAAL,CAAiBnB,IAAjB,EAAuBM,GAAvB,CAAP;IACD;EACF;;AA1KgD"}
|
package/lib/hub.js
CHANGED
package/lib/hub.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["Hub","getCode","getScope","addHelper","Error","buildError","node","msg","TypeError"],"sources":["../src/hub.ts"],"sourcesContent":["import type Scope from \"./scope\";\nimport type { Node } from \"@babel/types\";\n\nexport interface HubInterface {\n getCode(): string | void;\n getScope(): Scope | void;\n addHelper(name: string): any;\n buildError(node: Node, msg: string, Error: new () => Error): Error;\n}\n\nexport default class Hub implements HubInterface {\n getCode() {}\n\n getScope() {}\n\n addHelper() {\n throw new Error(\"Helpers are not supported by the default hub.\");\n }\n\n buildError(node: Node, msg: string, Error = TypeError): Error {\n return new Error(msg);\n }\n}\n"],"mappings":";;;;;;;AAUe,MAAMA,GAAN,CAAkC;EAC/CC,OAAO,GAAG,CAAE;;EAEZC,QAAQ,GAAG,CAAE;;EAEbC,SAAS,GAAG;IACV,MAAM,IAAIC,KAAJ,CAAU,+CAAV,CAAN;EACD;;EAEDC,UAAU,CAACC,IAAD,EAAaC,GAAb,EAA0BH,KAAK,GAAGI,SAAlC,EAAoD;IAC5D,OAAO,IAAIJ,KAAJ,CAAUG,GAAV,CAAP;EACD;;AAX8C"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["VISITOR_KEYS","removeProperties","traverseFast","traverse","parent","opts","scope","state","parentPath","noScope","type","Error","visitors","explode","traverseNode","verify","cheap","node","enter","path","skipKeys","clearNode","cache","delete","tree","hasDenylistedType","has","stop","hasType","denylistTypes","includes","denylist"],"sources":["../src/index.ts"],"sourcesContent":["import * as visitors from \"./visitors\";\nimport {\n VISITOR_KEYS,\n removeProperties,\n type RemovePropertiesOptions,\n traverseFast,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport * as cache from \"./cache\";\nimport type NodePath from \"./path\";\nimport type { default as Scope, Binding } from \"./scope\";\nimport type { Visitor } from \"./types\";\nimport { traverseNode } from \"./traverse-node\";\n\nexport type { Visitor, Binding };\nexport { default as NodePath } from \"./path\";\nexport { default as Scope } from \"./scope\";\nexport { default as Hub } from \"./hub\";\nexport type { HubInterface } from \"./hub\";\n\nexport { visitors };\n\nexport type TraverseOptions<S = t.Node> = {\n scope?: Scope;\n noScope?: boolean;\n denylist?: string[];\n} & Visitor<S>;\n\nfunction traverse<S>(\n parent: t.Node,\n opts: TraverseOptions<S>,\n scope: Scope | undefined,\n state: S,\n parentPath?: NodePath,\n): void;\n\nfunction traverse(\n parent: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n): void;\n\nfunction traverse<Options extends TraverseOptions>(\n parent: t.Node,\n // @ts-expect-error provide {} as default value for Options\n opts: Options = {},\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n) {\n if (!parent) return;\n\n if (!opts.noScope && !scope) {\n if (parent.type !== \"Program\" && parent.type !== \"File\") {\n throw new Error(\n \"You must pass a scope and parentPath unless traversing a Program/File. \" +\n `Instead of that you tried to traverse a ${parent.type} node without ` +\n \"passing scope and parentPath.\",\n );\n }\n }\n\n if (!VISITOR_KEYS[parent.type]) {\n return;\n }\n\n visitors.explode(opts as Visitor);\n\n traverseNode(parent, opts, scope, state, parentPath);\n}\n\nexport default traverse;\n\ntraverse.visitors = visitors;\ntraverse.verify = visitors.verify;\ntraverse.explode = visitors.explode;\n\ntraverse.cheap = function (node: t.Node, enter: (node: t.Node) => void) {\n return traverseFast(node, enter);\n};\n\ntraverse.node = function (\n node: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n path?: NodePath,\n skipKeys?: Record<string, boolean>,\n) {\n traverseNode(node, opts, scope, state, path, skipKeys);\n // traverse.node always returns undefined\n};\n\ntraverse.clearNode = function (node: t.Node, opts?: RemovePropertiesOptions) {\n removeProperties(node, opts);\n\n cache.path.delete(node);\n};\n\ntraverse.removeProperties = function (\n tree: t.Node,\n opts?: RemovePropertiesOptions,\n) {\n traverseFast(tree, traverse.clearNode, opts);\n return tree;\n};\n\ntype HasDenylistedTypeState = {\n has: boolean;\n type: t.Node[\"type\"];\n};\nfunction hasDenylistedType(path: NodePath, state: HasDenylistedTypeState) {\n if (path.node.type === state.type) {\n state.has = true;\n path.stop();\n }\n}\n\ntraverse.hasType = function (\n tree: t.Node,\n type: t.Node[\"type\"],\n denylistTypes?: Array<string>,\n): boolean {\n // the node we're searching in is denylisted\n if (denylistTypes?.includes(tree.type)) return false;\n\n // the type we're looking for is the same as the passed node\n if (tree.type === type) return true;\n\n const state: HasDenylistedTypeState = {\n has: false,\n type: type,\n };\n\n traverse(\n tree,\n {\n noScope: true,\n denylist: denylistTypes,\n enter: hasDenylistedType,\n },\n null,\n state,\n );\n\n return state.has;\n};\n\ntraverse.cache = cache;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;AAOA;;AAIA;;AAGA;;AACA;;AACA;;;EAfEA,Y;EACAC,gB;EAEAC;;;AAuCF,SAASC,QAAT,CACEC,MADF,EAGEC,IAAa,GAAG,EAHlB,EAIEC,KAJF,EAKEC,KALF,EAMEC,UANF,EAOE;EACA,IAAI,CAACJ,MAAL,EAAa;;EAEb,IAAI,CAACC,IAAI,CAACI,OAAN,IAAiB,CAACH,KAAtB,EAA6B;IAC3B,IAAIF,MAAM,CAACM,IAAP,KAAgB,SAAhB,IAA6BN,MAAM,CAACM,IAAP,KAAgB,MAAjD,EAAyD;MACvD,MAAM,IAAIC,KAAJ,CACJ,4EACG,2CAA0CP,MAAM,CAACM,IAAK,gBADzD,GAEE,+BAHE,CAAN;IAKD;EACF;;EAED,IAAI,CAACV,YAAY,CAACI,MAAM,CAACM,IAAR,CAAjB,EAAgC;IAC9B;EACD;;EAEDE,QAAQ,CAACC,OAAT,CAAiBR,IAAjB;EAEA,IAAAS,0BAAA,EAAaV,MAAb,EAAqBC,IAArB,EAA2BC,KAA3B,EAAkCC,KAAlC,EAAyCC,UAAzC;AACD;;eAEcL,Q;;AAEfA,QAAQ,CAACS,QAAT,GAAoBA,QAApB;AACAT,QAAQ,CAACY,MAAT,GAAkBH,QAAQ,CAACG,MAA3B;AACAZ,QAAQ,CAACU,OAAT,GAAmBD,QAAQ,CAACC,OAA5B;;AAEAV,QAAQ,CAACa,KAAT,GAAiB,UAAUC,IAAV,EAAwBC,KA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I,EAAEA;EAF8B,CAAtC;EAKAP,QAAQ,CACNqB,IADM,EAEN;IACEf,OAAO,EAAE,IADX;IAEEsB,QAAQ,EAAEF,aAFZ;IAGEX,KAAK,EAAEO;EAHT,CAFM,EAON,IAPM,EAQNlB,KARM,CAAR;EAWA,OAAOA,KAAK,CAACmB,GAAb;AACD,CA5BD;;AA8BAvB,QAAQ,CAACmB,KAAT,GAAiBA,KAAjB"}
|
package/lib/path/ancestry.js
CHANGED
@@ -16,8 +16,6 @@ exports.isDescendant = isDescendant;
|
|
16
16
|
|
17
17
|
var _t = require("@babel/types");
|
18
18
|
|
19
|
-
var _index = require("./index");
|
20
|
-
|
21
19
|
const {
|
22
20
|
VISITOR_KEYS
|
23
21
|
} = _t;
|
@@ -177,4 +175,6 @@ function inType(...candidateTypes) {
|
|
177
175
|
}
|
178
176
|
|
179
177
|
return false;
|
180
|
-
}
|
178
|
+
}
|
179
|
+
|
180
|
+
//# sourceMappingURL=ancestry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["VISITOR_KEYS","findParent","callback","path","parentPath","find","getFunctionParent","p","isFunction","getStatementParent","Array","isArray","container","isStatement","isProgram","isFile","Error","getEarliestCommonAncestorFrom","paths","getDeepestCommonAncestorFrom","deepest","i","ancestries","earliest","keys","type","ancestry","listKey","key","earliestKeyIndex","indexOf","parentKey","currentKeyIndex","filter","length","minDepth","Infinity","lastCommonIndex","lastCommon","map","unshift","first","depthLoop","shouldMatch","getAncestry","push","isAncestor","maybeDescendant","isDescendant","maybeAncestor","parent","inType","candidateTypes","node"],"sources":["../../src/path/ancestry.ts"],"sourcesContent":["// This file contains that retrieve or validate anything related to the current paths ancestry.\n\nimport { VISITOR_KEYS } from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index\";\n\n/**\n * Starting at the parent path of the current `NodePath` and going up the\n * tree, return the first `NodePath` that causes the provided `callback`\n * to return a truthy value, or `null` if the `callback` never returns a\n * truthy value.\n */\n\nexport function findParent(\n this: NodePath,\n callback: (path: NodePath) => boolean,\n): NodePath | null {\n let path = this;\n while ((path = path.parentPath)) {\n if (callback(path)) return path;\n }\n return null;\n}\n\n/**\n * Starting at current `NodePath` and going up the tree, return the first\n * `NodePath` that causes the provided `callback` to return a truthy value,\n * or `null` if the `callback` never returns a truthy value.\n */\n\nexport function find(\n this: NodePath,\n callback: (path: NodePath) => boolean,\n): NodePath | null {\n let path = this;\n do {\n if (callback(path)) return path;\n } while ((path = path.parentPath));\n return null;\n}\n\n/**\n * Get the parent function of the current path.\n */\n\nexport function getFunctionParent(this: NodePath): NodePath<t.Function> | null {\n return this.findParent(p => p.isFunction()) as NodePath<t.Function> | null;\n}\n\n/**\n * Walk up the tree until we hit a parent node path in a list.\n */\n\nexport function getStatementParent(this: NodePath): NodePath<t.Statement> {\n let path = this;\n\n do {\n if (\n !path.parentPath ||\n (Array.isArray(path.container) && path.isStatement())\n ) {\n break;\n } else {\n path = path.parentPath;\n }\n } while (path);\n\n if (path && (path.isProgram() || path.isFile())) {\n throw new Error(\n \"File/Program node, we can't possibly find a statement parent to this\",\n );\n }\n\n return path as NodePath<t.Statement>;\n}\n\n/**\n * Get the deepest common ancestor and then from it, get the earliest relationship path\n * to that ancestor.\n *\n * Earliest is defined as being \"before\" all the other nodes in terms of list container\n * position and visiting key.\n */\n\nexport function getEarliestCommonAncestorFrom(\n this: NodePath,\n paths: Array<NodePath>,\n): NodePath {\n return this.getDeepestCommonAncestorFrom(\n paths,\n function (deepest, i, ancestries) {\n let earliest;\n const keys = VISITOR_KEYS[deepest.type];\n\n for (const ancestry of ancestries) {\n const path = ancestry[i + 1];\n\n // first path\n if (!earliest) {\n earliest = path;\n continue;\n }\n\n // handle containers\n if (path.listKey && earliest.listKey === path.listKey) {\n // we're in the same container so check if we're earlier\n if (path.key < earliest.key) {\n earliest = path;\n continue;\n }\n }\n\n // handle keys\n const earliestKeyIndex = keys.indexOf(earliest.parentKey);\n const currentKeyIndex = keys.indexOf(path.parentKey as string);\n if (earliestKeyIndex > currentKeyIndex) {\n // key appears before so it's earlier\n earliest = path;\n }\n }\n\n return earliest;\n },\n );\n}\n\n/**\n * Get the earliest path in the tree where the provided `paths` intersect.\n *\n * TODO: Possible optimisation target.\n */\n\nexport function getDeepestCommonAncestorFrom(\n this: NodePath,\n paths: Array<NodePath>,\n filter?: (deepest: NodePath, i: number, ancestries: NodePath[][]) => NodePath,\n): NodePath {\n if (!paths.length) {\n return this;\n }\n\n if (paths.length === 1) {\n return paths[0];\n }\n\n // minimum depth of the tree so we know the highest node\n let minDepth = Infinity;\n\n // last common ancestor\n let lastCommonIndex, lastCommon;\n\n // get the ancestors of the path, breaking when the parent exceeds ourselves\n const ancestries = paths.map(path => {\n const ancestry: NodePath[] = [];\n\n do {\n ancestry.unshift(path);\n } while ((path = path.parentPath) && path !== this);\n\n // save min depth to avoid going too far in\n if (ancestry.length < minDepth) {\n minDepth = ancestry.length;\n }\n\n return ancestry;\n });\n\n // get the first ancestry so we have a seed to assess all other ancestries with\n const first = ancestries[0];\n\n // check ancestor equality\n depthLoop: for (let i = 0; i < minDepth; i++) {\n const shouldMatch = first[i];\n\n for (const ancestry of ancestries) {\n if (ancestry[i] !== shouldMatch) {\n // we've hit a snag\n break depthLoop;\n }\n }\n\n // next iteration may break so store these so they can be returned\n lastCommonIndex = i;\n lastCommon = shouldMatch;\n }\n\n if (lastCommon) {\n if (filter) {\n return filter(lastCommon, lastCommonIndex, ancestries);\n } else {\n return lastCommon;\n }\n } else {\n throw new Error(\"Couldn't find intersection\");\n }\n}\n\n/**\n * Build an array of node paths containing the entire ancestry of the current node path.\n *\n * NOTE: The current node path is included in this.\n */\n\nexport function getAncestry(this: NodePath): Array<NodePath> {\n let path = this;\n const paths = [];\n do {\n paths.push(path);\n } while ((path = path.parentPath));\n return paths;\n}\n\n/**\n * A helper to find if `this` path is an ancestor of @param maybeDescendant\n */\nexport function isAncestor(this: NodePath, maybeDescendant: NodePath): boolean {\n return maybeDescendant.isDescendant(this);\n}\n\n/**\n * A helper to find if `this` path is a descendant of @param maybeAncestor\n */\nexport function isDescendant(this: NodePath, maybeAncestor: NodePath): boolean {\n return !!this.findParent(parent => parent === maybeAncestor);\n}\n\nexport function inType(this: NodePath, ...candidateTypes: string[]): boolean {\n let path = this;\n while (path) {\n for (const type of candidateTypes) {\n if (path.node.type === type) return true;\n }\n path = path.parentPath;\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAEA;;;EAASA;;;AAWF,SAASC,UAAT,CAELC,QAFK,EAGY;EACjB,IAAIC,IAAI,GAAG,IAAX;;EACA,OAAQA,IAAI,GAAGA,IAAI,CAACC,UAApB,EAAiC;IAC/B,IAAIF,QAAQ,CAACC,IAAD,CAAZ,EAAoB,OAAOA,IAAP;EACrB;;EACD,OAAO,IAAP;AACD;;AAQM,SAASE,IAAT,CAELH,QAFK,EAGY;EACjB,IAAIC,IAAI,GAAG,IAAX;;EACA,GAAG;IACD,IAAID,QAAQ,CAACC,IAAD,CAAZ,EAAoB,OAAOA,IAAP;EACrB,CAFD,QAEUA,IAAI,GAAGA,IAAI,CAACC,UAFtB;;EAGA,OAAO,IAAP;AACD;;AAMM,SAASE,iBAAT,GAAwE;EAC7E,OAAO,KAAKL,UAAL,CAAgBM,CAAC,IAAIA,CAAC,CAACC,UAAF,EAArB,CAAP;AACD;;AAMM,SAASC,kBAAT,GAAmE;EACxE,IAAIN,IAAI,GAAG,IAAX;;EAEA,GAAG;IACD,IACE,CAACA,IAAI,CAACC,UAAN,IACCM,KAAK,CAACC,OAAN,CAAcR,IAAI,CAACS,SAAnB,KAAiCT,IAAI,CAACU,WAAL,EAFpC,EAGE;MACA;IACD,CALD,MAKO;MACLV,IAAI,GAAGA,IAAI,CAACC,UAAZ;IACD;EACF,CATD,QASSD,IATT;;EAWA,IAAIA,IAAI,KAAKA,IAAI,CAACW,SAAL,MAAoBX,IAAI,CAACY,MAAL,EAAzB,CAAR,EAAiD;IAC/C,MAAM,IAAIC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GAAGA,IAAI,CAACC,UAFtB;;EAGA,OAAOc,KAAP;AACD;;AAKM,SAAS4B,UAAT,CAAoCC,eAApC,EAAwE;EAC7E,OAAOA,eAAe,CAACC,YAAhB,CAA6B,IAA7B,CAAP;AACD;;AAKM,SAASA,YAAT,CAAsCC,aAAtC,EAAwE;EAC7E,OAAO,CAAC,CAAC,KAAKhD,UAAL,CAAgBiD,MAAM,IAAIA,MAAM,KAAKD,aAArC,CAAT;AACD;;AAEM,SAASE,MAAT,CAAgC,GAAGC,cAAnC,EAAsE;EAC3E,IAAIjD,IAAI,GAAG,IAAX;;EACA,OAAOA,IAAP,EAAa;IACX,KAAK,MAAMsB,IAAX,IAAmB2B,cAAnB,EAAmC;MACjC,IAAIjD,IAAI,CAACkD,IAAL,CAAU5B,IAAV,KAAmBA,IAAvB,EAA6B,OAAO,IAAP;IAC9B;;IACDtB,IAAI,GAAGA,IAAI,CAACC,UAAZ;EACD;;EAED,OAAO,KAAP;AACD"}
|
package/lib/path/comments.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["addComment","_addComment","addComments","_addComments","shareCommentsWithSiblings","key","node","trailing","trailingComments","leading","leadingComments","prev","getSibling","next","hasPrev","Boolean","hasNext","type","content","line","comments"],"sources":["../../src/path/comments.ts"],"sourcesContent":["// This file contains methods responsible for dealing with comments.\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index\";\nimport {\n addComment as _addComment,\n addComments as _addComments,\n} from \"@babel/types\";\n\n/**\n * Share comments amongst siblings.\n */\n\nexport function shareCommentsWithSiblings(this: NodePath) {\n // NOTE: this assumes numbered keys\n if (typeof this.key === \"string\") return;\n\n const node = this.node;\n if (!node) return;\n\n const trailing = node.trailingComments;\n const leading = node.leadingComments;\n if (!trailing && !leading) return;\n\n const prev = this.getSibling(this.key - 1);\n const next = this.getSibling(this.key + 1);\n const hasPrev = Boolean(prev.node);\n const hasNext = Boolean(next.node);\n if (hasPrev && !hasNext) {\n prev.addComments(\"trailing\", trailing);\n } else if (hasNext && !hasPrev) {\n next.addComments(\"leading\", leading);\n }\n}\n\nexport function addComment(\n this: NodePath,\n type: t.CommentTypeShorthand,\n content: string,\n line?: boolean,\n) {\n _addComment(this.node, type, content, line);\n}\n\n/**\n * Give node `comments` of the specified `type`.\n */\n\nexport function addComments(\n this: NodePath,\n type: t.CommentTypeShorthand,\n comments: t.Comment[],\n) {\n _addComments(this.node, type, comments);\n}\n"],"mappings":";;;;;;;;;AAGA;;;EACEA,U,EAAcC,W;EACdC,W,EAAeC;;;AAOV,SAASC,yBAAT,GAAmD;EAExD,IAAI,OAAO,KAAKC,GAAZ,KAAoB,QAAxB,EAAkC;EAElC,MAAMC,IAAI,GAAG,KAAKA,IAAlB;EACA,IAAI,CAACA,IAAL,EAAW;EAEX,MAAMC,QAAQ,GAAGD,IAAI,CAACE,gBAAtB;EACA,MAAMC,OAAO,GAAGH,IAAI,CAACI,eAArB;EACA,IAAI,CAACH,QAAD,IAAa,CAACE,OAAlB,EAA2B;EAE3B,MAAME,IAAI,GAAG,KAAKC,UAAL,CAAgB,KAAKP,GAAL,GAAW,CAA3B,CAAb;EACA,MAAMQ,IAAI,GAAG,KAAKD,UAAL,CAAgB,KAAKP,GAAL,GAAW,CAA3B,CAAb;EACA,MAAMS,OAAO,GAAGC,OAAO,CAACJ,IAAI,CAACL,IAAN,CAAvB;EACA,MAAMU,OAAO,GAAGD,OAAO,CAACF,IAAI,CAACP,IAAN,CAAvB;;EACA,IAAIQ,OAAO,IAAI,CAACE,OAAhB,EAAyB;IACvBL,IAAI,CAACT,WAAL,CAAiB,UAAjB,EAA6BK,QAA7B;EACD,CAFD,MAEO,IAAIS,OAAO,IAAI,CAACF,OAAhB,EAAyB;IAC9BD,IAAI,CAACX,WAAL,CAAiB,SAAjB,EAA4BO,OAA5B;EACD;AACF;;AAEM,SAAST,UAAT,CAELiB,IAFK,EAGLC,OAHK,EAILC,IAJK,EAKL;EACAlB,WAAW,CAAC,KAAKK,IAAN,EAAYW,IAAZ,EAAkBC,OAAlB,EAA2BC,IAA3B,CAAX;AACD;;AAMM,SAASjB,WAAT,CAELe,IAFK,EAGLG,QAHK,EAIL;EACAjB,YAAY,CAAC,KAAKG,IAAN,EAAYW,IAAZ,EAAkBG,QAAlB,CAAZ;AACD"}
|
package/lib/path/context.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["call","key","opts","debug","node","_call","type","fns","fn","ret","state","then","Error","_traverseFlags","isDenylisted","denylist","blacklist","indexOf","restoreContext","path","context","visit","shouldSkip","currentContext","shouldStop","traverseNode","scope","skipKeys","skip","skipKey","stop","SHOULD_SKIP","SHOULD_STOP","setScope","noScope","parentPath","listKey","isMethod","target","getScope","init","setContext","resync","removed","_resyncParent","_resyncList","_resyncKey","parent","container","Array","isArray","i","length","setKey","Object","keys","inList","newContainer","_resyncRemoved","_markRemoved","popContext","contexts","pop","undefined","pushContext","push","setup","requeue","pathToQueue","maybeQueue","_getQueueContexts"],"sources":["../../src/path/context.ts"],"sourcesContent":["// This file contains methods responsible for maintaining a TraversalContext.\n\nimport { traverseNode } from \"../traverse-node\";\nimport { SHOULD_SKIP, SHOULD_STOP } from \"./index\";\nimport type TraversalContext from \"../context\";\nimport type NodePath from \"./index\";\nimport type * as t from \"@babel/types\";\n\nexport function call(this: NodePath, key: string): boolean {\n const opts = this.opts;\n\n this.debug(key);\n\n if (this.node) {\n if (this._call(opts[key])) return true;\n }\n\n if (this.node) {\n return this._call(opts[this.node.type] && opts[this.node.type][key]);\n }\n\n return false;\n}\n\nexport function _call(this: NodePath, fns?: Array<Function>): boolean {\n if (!fns) return false;\n\n for (const fn of fns) {\n if (!fn) continue;\n\n const node = this.node;\n if (!node) return true;\n\n const ret = fn.call(this.state, this, this.state);\n if (ret && typeof ret === \"object\" && typeof ret.then === \"function\") {\n throw new Error(\n `You appear to be using a plugin with an async traversal visitor, ` +\n `which your current version of Babel does not support. ` +\n `If you're using a published plugin, you may need to upgrade ` +\n `your @babel/core version.`,\n );\n }\n if (ret) {\n throw new Error(`Unexpected return value from visitor method ${fn}`);\n }\n\n // node has been replaced, it will have been requeued\n if (this.node !== node) return true;\n\n // this.shouldSkip || this.shouldStop || this.removed\n if (this._traverseFlags > 0) return true;\n }\n\n return false;\n}\n\nexport function isDenylisted(this: NodePath): boolean {\n const denylist = this.opts.denylist ?? this.opts.blacklist;\n return denylist && denylist.indexOf(this.node.type) > -1;\n}\n\n// TODO: Remove in Babel 8\nexport { isDenylisted as isBlacklisted };\n\nfunction restoreContext(path: NodePath, context: TraversalContext) {\n if (path.context !== context) {\n path.context = context;\n path.state = context.state;\n path.opts = context.opts;\n }\n}\n\nexport function visit(this: NodePath): boolean {\n if (!this.node) {\n return false;\n }\n\n if (this.isDenylisted()) {\n return false;\n }\n\n if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {\n return false;\n }\n\n const currentContext = this.context;\n // Note: We need to check \"this.shouldSkip\" first because\n // another visitor can set it to true. Usually .shouldSkip is false\n // before calling the enter visitor, but it can be true in case of\n // a requeued node (e.g. by .replaceWith()) that is then marked\n // with .skip().\n if (this.shouldSkip || this.call(\"enter\")) {\n this.debug(\"Skip...\");\n return this.shouldStop;\n }\n restoreContext(this, currentContext);\n\n this.debug(\"Recursing into...\");\n this.shouldStop = traverseNode(\n this.node,\n this.opts,\n this.scope,\n this.state,\n this,\n this.skipKeys,\n );\n\n restoreContext(this, currentContext);\n\n this.call(\"exit\");\n\n return this.shouldStop;\n}\n\nexport function skip(this: NodePath) {\n this.shouldSkip = true;\n}\n\nexport function skipKey(this: NodePath, key: string) {\n if (this.skipKeys == null) {\n this.skipKeys = {};\n }\n this.skipKeys[key] = true;\n}\n\nexport function stop(this: NodePath) {\n // this.shouldSkip = true; this.shouldStop = true;\n this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;\n}\n\nexport function setScope(this: NodePath) {\n if (this.opts && this.opts.noScope) return;\n\n let path = this.parentPath;\n\n // Skip method scope if is computed method key or decorator expression\n if (\n (this.key === \"key\" || this.listKey === \"decorators\") &&\n path.isMethod()\n ) {\n path = path.parentPath;\n }\n\n let target;\n while (path && !target) {\n if (path.opts && path.opts.noScope) return;\n\n target = path.scope;\n path = path.parentPath;\n }\n\n this.scope = this.getScope(target);\n if (this.scope) this.scope.init();\n}\n\nexport function setContext<S = unknown>(\n this: NodePath,\n context?: TraversalContext<S>,\n) {\n if (this.skipKeys != null) {\n this.skipKeys = {};\n }\n // this.shouldSkip = false; this.shouldStop = false; this.removed = false;\n this._traverseFlags = 0;\n\n if (context) {\n this.context = context;\n this.state = context.state;\n this.opts = context.opts;\n }\n\n this.setScope();\n\n return this;\n}\n\n/**\n * Here we resync the node paths `key` and `container`. If they've changed according\n * to what we have stored internally then we attempt to resync by crawling and looking\n * for the new values.\n */\n\nexport function resync(this: NodePath) {\n if (this.removed) return;\n\n this._resyncParent();\n this._resyncList();\n this._resyncKey();\n //this._resyncRemoved();\n}\n\nexport function _resyncParent(this: NodePath) {\n if (this.parentPath) {\n this.parent = this.parentPath.node;\n }\n}\n\nexport function _resyncKey(this: NodePath) {\n if (!this.container) return;\n\n if (\n this.node ===\n // @ts-expect-error this.key should present in this.container\n this.container[this.key]\n ) {\n return;\n }\n\n // grrr, path key is out of sync. this is likely due to a modification to the AST\n // not done through our path APIs\n\n if (Array.isArray(this.container)) {\n for (let i = 0; i < this.container.length; i++) {\n if (this.container[i] === this.node) {\n return this.setKey(i);\n }\n }\n } else {\n for (const key of Object.keys(this.container)) {\n // @ts-expect-error this.key should present in this.container\n if (this.container[key] === this.node) {\n return this.setKey(key);\n }\n }\n }\n\n // ¯\\_(ツ)_/¯ who knows where it's gone lol\n this.key = null;\n}\n\nexport function _resyncList(this: NodePath) {\n if (!this.parent || !this.inList) return;\n\n const newContainer =\n // @ts-expect-error this.listKey should present in this.parent\n this.parent[this.listKey];\n if (this.container === newContainer) return;\n\n // container is out of sync. this is likely the result of it being reassigned\n this.container = newContainer || null;\n}\n\nexport function _resyncRemoved(this: NodePath) {\n if (\n this.key == null ||\n !this.container ||\n // @ts-expect-error this.key should present in this.container\n this.container[this.key] !== this.node\n ) {\n this._markRemoved();\n }\n}\n\nexport function popContext(this: NodePath) {\n this.contexts.pop();\n if (this.contexts.length > 0) {\n this.setContext(this.contexts[this.contexts.length - 1]);\n } else {\n this.setContext(undefined);\n }\n}\n\nexport function pushContext(this: NodePath, context: TraversalContext) {\n this.contexts.push(context);\n this.setContext(context);\n}\n\nexport function setup(\n this: NodePath,\n parentPath: NodePath | undefined,\n container: t.Node,\n listKey: string,\n key: string | number,\n) {\n this.listKey = listKey;\n this.container = container;\n\n this.parentPath = parentPath || this.parentPath;\n this.setKey(key);\n}\n\nexport function setKey(this: NodePath, key: string | number) {\n this.key = key;\n this.node =\n // @ts-expect-error this.key must present in this.container\n this.container[this.key];\n this.type = this.node?.type;\n}\n\nexport function requeue(this: NodePath, pathToQueue = this) {\n if (pathToQueue.removed) return;\n\n // If a path is skipped, and then replaced with a\n // new one, the new one shouldn't probably be skipped.\n if (process.env.BABEL_8_BREAKING) {\n pathToQueue.shouldSkip = false;\n }\n\n // TODO(loganfsmyth): This should be switched back to queue in parent contexts\n // automatically once #2892 and #4135 have been resolved. See #4140.\n // let contexts = this._getQueueContexts();\n const contexts = this.contexts;\n\n for (const context of contexts) {\n context.maybeQueue(pathToQueue);\n }\n}\n\nexport function _getQueueContexts(this: NodePath) {\n let path = this;\n let contexts = this.contexts;\n while (!contexts.length) {\n path = path.parentPath;\n if (!path) break;\n contexts = path.contexts;\n }\n return contexts;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AAKO,SAASA,IAAT,CAA8BC,GAA9B,EAAoD;EACzD,MAAMC,IAAI,GAAG,KAAKA,IAAlB;EAEA,KAAKC,KAAL,CAAWF,GAAX;;EAEA,IAAI,KAAKG,IAAT,EAAe;IACb,IAAI,KAAKC,KAAL,CAAWH,IAAI,CAACD,GAAD,CAAf,CAAJ,EAA2B,OAAO,I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AAgC;IAC9BzC,OAAO,CAACiD,UAAR,CAAmBD,WAAnB;EACD;AACF;;AAEM,SAASE,iBAAT,GAA2C;EAChD,IAAInD,IAAI,GAAG,IAAX;EACA,IAAI0C,QAAQ,GAAG,KAAKA,QAApB;;EACA,OAAO,CAACA,QAAQ,CAACT,MAAjB,EAAyB;IACvBjC,IAAI,GAAGA,IAAI,CAACgB,UAAZ;IACA,IAAI,CAAChB,IAAL,EAAW;IACX0C,QAAQ,GAAG1C,IAAI,CAAC0C,QAAhB;EACD;;EACD,OAAOA,QAAP;AACD"}
|
package/lib/path/conversion.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["arrowFunctionExpression","assignmentExpression","binaryExpression","blockStatement","callExpression","conditionalExpression","expressionStatement","identifier","isIdentifier","jsxIdentifier","logicalExpression","LOGICAL_OPERATORS","memberExpression","metaProperty","numericLiteral","objectExpression","restElement","returnStatement","sequenceExpression","spreadElement","stringLiteral","super","_super","thisExpression","toExpression","unaryExpression","toComputedKey","key","isMemberExpression","node","property","isProperty","isMethod","ReferenceError","computed","name","ensureBlock","body","get","bodyNode","Array","isArray","Error","isBlockStatement","statements","stringPath","listKey","isStatement","push","isFunction","parentPath","setup","arrowFunctionToShadowed","isArrowFunctionExpression","arrowFunctionToExpression","unwrapFunctionEnvironment","isFunctionExpression","isFunctionDeclaration","buildCodeFrameError","hoistFunctionEnvironment","setType","path","type","allowInsertArrow","specCompliant","noNewArrows","thisBinding","fnPath","fn","checkBinding","scope","generateUidIdentifier","id","init","unshiftContainer","hub","addHelper","replaceWith","nameFunction","getSuperCallsVisitor","mergeVisitors","CallExpression","child","allSuperCalls","isSuper","environmentVisitor","arrowParent","thisEnvFn","findParent","p","isProgram","isClassProperty","static","isClassPrivateProperty","inConstructor","isClassMethod","kind","thisPaths","argumentsPaths","newTargetPaths","superProps","superCalls","getScopeInformation","length","traverse","superBinding","getSuperBinding","forEach","superCall","callee","loc","argumentsBinding","getBinding","args","buildUndefinedNode","argumentsChild","argsRef","newTargetBinding","targetChild","targetRef","flatSuperProps","reduce","acc","superProp","concat","standardizeSuperProperty","superParentPath","isAssignment","isAssignmentExpression","left","isCall","isCallExpression","getSuperPropBinding","value","right","call","getThisBinding","hasSuperClass","thisChild","thisRef","isJSX","isLogicalOp","op","includes","operator","assignmentPath","slice","isLogicalAssignment","tmp","generateDeclaredUidIdentifier","object","rightExpression","isUpdateExpression","updateExpr","computedKey","parts","prefix","superClass","assignSuperThisVisitor","supers","has","add","replaceWithMultiple","WeakSet","argsBinding","propName","argsList","fnBody","method","unshift","valueIdent","cacheKey","data","getData","setData","getScopeInformationVisitor","ThisExpression","JSXIdentifier","isJSXMemberExpression","isJSXOpeningElement","MemberExpression","Identifier","isReferencedIdentifier","curr","hasOwnBinding","rename","parent","MetaProperty"],"sources":["../../src/path/conversion.ts"],"sourcesContent":["// This file contains methods that convert the path node into another node or some other type of data.\n\nimport {\n arrowFunctionExpression,\n assignmentExpression,\n binaryExpression,\n blockStatement,\n callExpression,\n conditionalExpression,\n expressionStatement,\n identifier,\n isIdentifier,\n jsxIdentifier,\n logicalExpression,\n LOGICAL_OPERATORS,\n memberExpression,\n metaProperty,\n numericLiteral,\n objectExpression,\n restElement,\n returnStatement,\n sequenceExpression,\n spreadElement,\n stringLiteral,\n super as _super,\n thisExpression,\n toExpression,\n unaryExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport environmentVisitor from \"@babel/helper-environment-visitor\";\nimport nameFunction from \"@babel/helper-function-name\";\nimport { merge as mergeVisitors } from \"../visitors\";\nimport type NodePath from \"./index\";\n\nexport function toComputedKey(this: NodePath) {\n let key;\n if (this.isMemberExpression()) {\n key = this.node.property;\n } else if (this.isProperty() || this.isMethod()) {\n key = this.node.key;\n } else {\n throw new ReferenceError(\"todo\");\n }\n\n // @ts-expect-error todo(flow->ts) computed does not exist in ClassPrivateProperty\n if (!this.node.computed) {\n if (isIdentifier(key)) key = stringLiteral(key.name);\n }\n\n return key;\n}\n\nexport function ensureBlock(\n this: NodePath<\n t.Loop | t.WithStatement | t.Function | t.LabeledStatement | t.CatchClause\n >,\n) {\n const body = this.get(\"body\");\n const bodyNode = body.node;\n\n if (Array.isArray(body)) {\n throw new Error(\"Can't convert array path to a block statement\");\n }\n if (!bodyNode) {\n throw new Error(\"Can't convert node without a body\");\n }\n\n if (body.isBlockStatement()) {\n return bodyNode;\n }\n\n const statements: Array<t.Statement> = [];\n\n let stringPath = \"body\";\n let key;\n let listKey;\n if (body.isStatement()) {\n listKey = \"body\";\n key = 0;\n statements.push(body.node);\n } else {\n stringPath += \".body.0\";\n if (this.isFunction()) {\n key = \"argument\";\n statements.push(returnStatement(body.node as t.Expression));\n } else {\n key = \"expression\";\n statements.push(expressionStatement(body.node as t.Expression));\n }\n }\n\n this.node.body = blockStatement(statements);\n const parentPath = this.get(stringPath) as NodePath;\n body.setup(\n parentPath,\n listKey\n ? // @ts-expect-error listKey must present in parent path\n parentPath.node[listKey]\n : parentPath.node,\n listKey,\n key,\n );\n\n return this.node;\n}\n\n/**\n * Keeping this for backward-compatibility. You should use arrowFunctionToExpression() for >=7.x.\n */\n// TODO(Babel 8): Remove this\nexport function arrowFunctionToShadowed(this: NodePath) {\n if (!this.isArrowFunctionExpression()) return;\n\n this.arrowFunctionToExpression();\n}\n\n/**\n * Given an arbitrary function, process its content as if it were an arrow function, moving references\n * to \"this\", \"arguments\", \"super\", and such into the function's parent scope. This method is useful if\n * you have wrapped some set of items in an IIFE or other function, but want \"this\", \"arguments\", and super\"\n * to continue behaving as expected.\n */\nexport function unwrapFunctionEnvironment(this: NodePath) {\n if (\n !this.isArrowFunctionExpression() &&\n !this.isFunctionExpression() &&\n !this.isFunctionDeclaration()\n ) {\n throw this.buildCodeFrameError(\n \"Can only unwrap the environment of a function.\",\n );\n }\n\n hoistFunctionEnvironment(this);\n}\n\nfunction setType<N extends t.Node, T extends N[\"type\"]>(\n path: NodePath<N>,\n type: T,\n): asserts path is NodePath<Extract<N, { type: T }>> {\n path.node.type = type;\n}\n\n/**\n * Convert a given arrow function into a normal ES5 function expression.\n */\nexport function arrowFunctionToExpression(\n this: NodePath<t.ArrowFunctionExpression>,\n {\n allowInsertArrow = true,\n /** @deprecated Use `noNewArrows` instead */\n specCompliant = false,\n // TODO(Babel 8): Consider defaulting to `false` for spec compliancy\n noNewArrows = !specCompliant,\n }: {\n allowInsertArrow?: boolean | void;\n specCompliant?: boolean | void;\n noNewArrows?: boolean;\n } = {},\n): NodePath<Exclude<t.Function, t.Method | t.ArrowFunctionExpression>> {\n if (!this.isArrowFunctionExpression()) {\n throw (this as NodePath).buildCodeFrameError(\n \"Cannot convert non-arrow function to a function expression.\",\n );\n }\n\n const { thisBinding, fnPath: fn } = hoistFunctionEnvironment(\n this,\n noNewArrows,\n allowInsertArrow,\n );\n\n // @ts-expect-error TS requires explicit fn type annotation\n fn.ensureBlock();\n setType(fn, \"FunctionExpression\");\n\n if (!noNewArrows) {\n const checkBinding = thisBinding\n ? null\n : fn.scope.generateUidIdentifier(\"arrowCheckId\");\n if (checkBinding) {\n fn.parentPath.scope.push({\n id: checkBinding,\n init: objectExpression([]),\n });\n }\n\n fn.get(\"body\").unshiftContainer(\n \"body\",\n expressionStatement(\n callExpression(this.hub.addHelper(\"newArrowCheck\"), [\n thisExpression(),\n checkBinding\n ? identifier(checkBinding.name)\n : identifier(thisBinding),\n ]),\n ),\n );\n\n fn.replaceWith(\n callExpression(\n memberExpression(\n // @ts-expect-error TS can't infer nameFunction returns CallExpression | ArrowFunctionExpression here\n nameFunction(this, true) || fn.node,\n identifier(\"bind\"),\n ),\n [checkBinding ? identifier(checkBinding.name) : thisExpression()],\n ),\n );\n\n return fn.get(\"callee.object\");\n }\n\n return fn;\n}\n\nconst getSuperCallsVisitor = mergeVisitors<{\n allSuperCalls: NodePath<t.CallExpression>[];\n}>([\n {\n CallExpression(child, { allSuperCalls }) {\n if (!child.get(\"callee\").isSuper()) return;\n allSuperCalls.push(child);\n },\n },\n environmentVisitor,\n]);\n\n/**\n * Given a function, traverse its contents, and if there are references to \"this\", \"arguments\", \"super\",\n * or \"new.target\", ensure that these references reference the parent environment around this function.\n *\n * @returns `thisBinding`: the name of the injected reference to `this`; for example \"_this\"\n * @returns `fnPath`: the new path to the function node. This is different from the fnPath\n * parameter when the function node is wrapped in another node.\n */\nfunction hoistFunctionEnvironment(\n fnPath: NodePath<t.Function>,\n // TODO(Babel 8): Consider defaulting to `false` for spec compliancy\n noNewArrows: boolean | void = true,\n allowInsertArrow: boolean | void = true,\n): { thisBinding: string; fnPath: NodePath<t.Function> } {\n let arrowParent;\n let thisEnvFn: NodePath<t.Function> = fnPath.findParent(p => {\n if (p.isArrowFunctionExpression()) {\n arrowParent ??= p;\n return false;\n }\n return (\n p.isFunction() ||\n p.isProgram() ||\n p.isClassProperty({ static: false }) ||\n p.isClassPrivateProperty({ static: false })\n );\n }) as NodePath<t.Function>;\n const inConstructor = thisEnvFn.isClassMethod({ kind: \"constructor\" });\n\n if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) {\n if (arrowParent) {\n thisEnvFn = arrowParent;\n } else if (allowInsertArrow) {\n // It's safe to wrap this function in another and not hoist to the\n // top level because the 'this' binding is constant in class\n // properties (since 'super()' has already been called), so we don't\n // need to capture/reassign it at the top level.\n fnPath.replaceWith(\n callExpression(\n arrowFunctionExpression([], toExpression(fnPath.node)),\n [],\n ),\n );\n thisEnvFn = fnPath.get(\"callee\") as NodePath<t.ArrowFunctionExpression>;\n fnPath = thisEnvFn.get(\"body\") as NodePath<t.FunctionExpression>;\n } else {\n throw fnPath.buildCodeFrameError(\n \"Unable to transform arrow inside class property\",\n );\n }\n }\n\n const { thisPaths, argumentsPaths, newTargetPaths, superProps, superCalls } =\n getScopeInformation(fnPath);\n\n // Convert all super() calls in the constructor, if super is used in an arrow.\n if (inConstructor && superCalls.length > 0) {\n if (!allowInsertArrow) {\n throw superCalls[0].buildCodeFrameError(\n \"Unable to handle nested super() usage in arrow\",\n );\n }\n const allSuperCalls: NodePath<t.CallExpression>[] = [];\n thisEnvFn.traverse(getSuperCallsVisitor, { allSuperCalls });\n const superBinding = getSuperBinding(thisEnvFn);\n allSuperCalls.forEach(superCall => {\n const callee = identifier(superBinding);\n callee.loc = superCall.node.callee.loc;\n\n superCall.get(\"callee\").replaceWith(callee);\n });\n }\n\n // Convert all \"arguments\" references in the arrow to point at the alias.\n if (argumentsPaths.length > 0) {\n const argumentsBinding = getBinding(thisEnvFn, \"arguments\", () => {\n const args = () => identifier(\"arguments\");\n if (thisEnvFn.scope.path.isProgram()) {\n return conditionalExpression(\n binaryExpression(\n \"===\",\n unaryExpression(\"typeof\", args()),\n stringLiteral(\"undefined\"),\n ),\n thisEnvFn.scope.buildUndefinedNode(),\n args(),\n );\n } else {\n return args();\n }\n });\n\n argumentsPaths.forEach(argumentsChild => {\n const argsRef = identifier(argumentsBinding);\n argsRef.loc = argumentsChild.node.loc;\n\n argumentsChild.replaceWith(argsRef);\n });\n }\n\n // Convert all \"new.target\" references in the arrow to point at the alias.\n if (newTargetPaths.length > 0) {\n const newTargetBinding = getBinding(thisEnvFn, \"newtarget\", () =>\n metaProperty(identifier(\"new\"), identifier(\"target\")),\n );\n\n newTargetPaths.forEach(targetChild => {\n const targetRef = identifier(newTargetBinding);\n targetRef.loc = targetChild.node.loc;\n\n targetChild.replaceWith(targetRef);\n });\n }\n\n // Convert all \"super.prop\" references to point at aliases.\n if (superProps.length > 0) {\n if (!allowInsertArrow) {\n throw superProps[0].buildCodeFrameError(\n \"Unable to handle nested super.prop usage\",\n );\n }\n\n const flatSuperProps: NodePath<t.MemberExpression>[] = superProps.reduce(\n (acc, superProp) => acc.concat(standardizeSuperProperty(superProp)),\n [],\n );\n\n flatSuperProps.forEach(superProp => {\n const key = superProp.node.computed\n ? \"\"\n : // @ts-expect-error super property must not contain private name\n superProp.get(\"property\").node.name;\n\n const superParentPath = superProp.parentPath;\n\n const isAssignment = superParentPath.isAssignmentExpression({\n left: superProp.node,\n });\n const isCall = superParentPath.isCallExpression({\n callee: superProp.node,\n });\n const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);\n\n const args: t.Expression[] = [];\n if (superProp.node.computed) {\n // SuperProperty must not be a private name\n args.push(superProp.get(\"property\").node as t.Expression);\n }\n\n if (isAssignment) {\n const value = superParentPath.node.right;\n args.push(value);\n }\n\n const call = callExpression(identifier(superBinding), args);\n\n if (isCall) {\n superParentPath.unshiftContainer(\"arguments\", thisExpression());\n superProp.replaceWith(memberExpression(call, identifier(\"call\")));\n\n thisPaths.push(\n superParentPath.get(\"arguments.0\") as NodePath<t.ThisExpression>,\n );\n } else if (isAssignment) {\n // Replace not only the super.prop, but the whole assignment\n superParentPath.replaceWith(call);\n } else {\n superProp.replaceWith(call);\n }\n });\n }\n\n // Convert all \"this\" references in the arrow to point at the alias.\n let thisBinding: string | null;\n if (thisPaths.length > 0 || !noNewArrows) {\n thisBinding = getThisBinding(thisEnvFn, inConstructor);\n\n if (\n noNewArrows ||\n // In subclass constructors, still need to rewrite because \"this\" can't be bound in spec mode\n // because it might not have been initialized yet.\n (inConstructor && hasSuperClass(thisEnvFn))\n ) {\n thisPaths.forEach(thisChild => {\n const thisRef = thisChild.isJSX()\n ? jsxIdentifier(thisBinding)\n : identifier(thisBinding);\n\n thisRef.loc = thisChild.node.loc;\n thisChild.replaceWith(thisRef);\n });\n\n if (!noNewArrows) thisBinding = null;\n }\n }\n\n return { thisBinding, fnPath };\n}\n\ntype LogicalOp = Parameters<typeof logicalExpression>[0];\ntype BinaryOp = Parameters<typeof binaryExpression>[0];\n\nfunction isLogicalOp(op: string): op is LogicalOp {\n return LOGICAL_OPERATORS.includes(op);\n}\n\nfunction standardizeSuperProperty(\n superProp: NodePath<t.MemberExpression>,\n):\n | [NodePath<t.MemberExpression>]\n | [NodePath<t.MemberExpression>, NodePath<t.MemberExpression>] {\n if (\n superProp.parentPath.isAssignmentExpression() &&\n superProp.parentPath.node.operator !== \"=\"\n ) {\n const assignmentPath = superProp.parentPath;\n\n const op = assignmentPath.node.operator.slice(0, -1) as\n | LogicalOp\n | BinaryOp;\n\n const value = assignmentPath.node.right;\n\n const isLogicalAssignment = isLogicalOp(op);\n\n if (superProp.node.computed) {\n // from: super[foo] **= 4;\n // to: super[tmp = foo] = super[tmp] ** 4;\n\n // from: super[foo] ??= 4;\n // to: super[tmp = foo] ?? super[tmp] = 4;\n\n const tmp = superProp.scope.generateDeclaredUidIdentifier(\"tmp\");\n\n const object = superProp.node.object;\n const property = superProp.node.property as t.Expression;\n\n assignmentPath\n .get(\"left\")\n .replaceWith(\n memberExpression(\n object,\n assignmentExpression(\"=\", tmp, property),\n true /* computed */,\n ),\n );\n\n assignmentPath\n .get(\"right\")\n .replaceWith(\n rightExpression(\n isLogicalAssignment ? \"=\" : op,\n memberExpression(object, identifier(tmp.name), true /* computed */),\n value,\n ),\n );\n } else {\n // from: super.foo **= 4;\n // to: super.foo = super.foo ** 4;\n\n // from: super.foo ??= 4;\n // to: super.foo ?? super.foo = 4;\n\n const object = superProp.node.object;\n const property = superProp.node.property as t.Identifier;\n\n assignmentPath\n .get(\"left\")\n .replaceWith(memberExpression(object, property));\n\n assignmentPath\n .get(\"right\")\n .replaceWith(\n rightExpression(\n isLogicalAssignment ? \"=\" : op,\n memberExpression(object, identifier(property.name)),\n value,\n ),\n );\n }\n\n if (isLogicalAssignment) {\n assignmentPath.replaceWith(\n logicalExpression(\n op,\n assignmentPath.node.left as t.MemberExpression,\n assignmentPath.node.right as t.Expression,\n ),\n );\n } else {\n assignmentPath.node.operator = \"=\";\n }\n\n return [\n assignmentPath.get(\"left\") as NodePath<t.MemberExpression>,\n assignmentPath.get(\"right\").get(\"left\"),\n ];\n } else if (superProp.parentPath.isUpdateExpression()) {\n const updateExpr = superProp.parentPath;\n\n const tmp = superProp.scope.generateDeclaredUidIdentifier(\"tmp\");\n const computedKey = superProp.node.computed\n ? superProp.scope.generateDeclaredUidIdentifier(\"prop\")\n : null;\n\n const parts: t.Expression[] = [\n assignmentExpression(\n \"=\",\n tmp,\n memberExpression(\n superProp.node.object,\n computedKey\n ? assignmentExpression(\n \"=\",\n computedKey,\n superProp.node.property as t.Expression,\n )\n : superProp.node.property,\n superProp.node.computed,\n ),\n ),\n assignmentExpression(\n \"=\",\n memberExpression(\n superProp.node.object,\n computedKey ? identifier(computedKey.name) : superProp.node.property,\n superProp.node.computed,\n ),\n binaryExpression(\n // map `++` to `+`, and `--` to `-`\n superProp.parentPath.node.operator[0] as \"+\" | \"-\",\n identifier(tmp.name),\n numericLiteral(1),\n ),\n ),\n ];\n\n if (!superProp.parentPath.node.prefix) {\n parts.push(identifier(tmp.name));\n }\n\n updateExpr.replaceWith(sequenceExpression(parts));\n\n const left = updateExpr.get(\n \"expressions.0.right\",\n ) as NodePath<t.MemberExpression>;\n const right = updateExpr.get(\n \"expressions.1.left\",\n ) as NodePath<t.MemberExpression>;\n return [left, right];\n }\n\n return [superProp];\n\n function rightExpression(\n op: BinaryOp | \"=\",\n left: t.MemberExpression,\n right: t.Expression,\n ) {\n if (op === \"=\") {\n return assignmentExpression(\"=\", left, right);\n } else {\n return binaryExpression(op, left, right);\n }\n }\n}\n\nfunction hasSuperClass(thisEnvFn: NodePath<t.Function>) {\n return (\n thisEnvFn.isClassMethod() &&\n !!(thisEnvFn.parentPath.parentPath.node as t.Class).superClass\n );\n}\n\nconst assignSuperThisVisitor = mergeVisitors<{\n supers: WeakSet<t.CallExpression>;\n thisBinding: string;\n}>([\n {\n CallExpression(child, { supers, thisBinding }) {\n if (!child.get(\"callee\").isSuper()) return;\n if (supers.has(child.node)) return;\n supers.add(child.node);\n\n child.replaceWithMultiple([\n child.node,\n assignmentExpression(\"=\", identifier(thisBinding), identifier(\"this\")),\n ]);\n },\n },\n environmentVisitor,\n]);\n\n// Create a binding that evaluates to the \"this\" of the given function.\nfunction getThisBinding(\n thisEnvFn: NodePath<t.Function>,\n inConstructor: boolean,\n) {\n return getBinding(thisEnvFn, \"this\", thisBinding => {\n if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression();\n\n thisEnvFn.traverse(assignSuperThisVisitor, {\n supers: new WeakSet(),\n thisBinding,\n });\n });\n}\n\n// Create a binding for a function that will call \"super()\" with arguments passed through.\nfunction getSuperBinding(thisEnvFn: NodePath<t.Function>) {\n return getBinding(thisEnvFn, \"supercall\", () => {\n const argsBinding = thisEnvFn.scope.generateUidIdentifier(\"args\");\n return arrowFunctionExpression(\n [restElement(argsBinding)],\n callExpression(_super(), [spreadElement(identifier(argsBinding.name))]),\n );\n });\n}\n\n// Create a binding for a function that will call \"super.foo\" or \"super[foo]\".\nfunction getSuperPropBinding(\n thisEnvFn: NodePath<t.Function>,\n isAssignment: boolean,\n propName: string,\n) {\n const op = isAssignment ? \"set\" : \"get\";\n\n return getBinding(thisEnvFn, `superprop_${op}:${propName || \"\"}`, () => {\n const argsList = [];\n\n let fnBody;\n if (propName) {\n // () => super.foo\n fnBody = memberExpression(_super(), identifier(propName));\n } else {\n const method = thisEnvFn.scope.generateUidIdentifier(\"prop\");\n // (method) => super[method]\n argsList.unshift(method);\n fnBody = memberExpression(\n _super(),\n identifier(method.name),\n true /* computed */,\n );\n }\n\n if (isAssignment) {\n const valueIdent = thisEnvFn.scope.generateUidIdentifier(\"value\");\n argsList.push(valueIdent);\n\n fnBody = assignmentExpression(\"=\", fnBody, identifier(valueIdent.name));\n }\n\n return arrowFunctionExpression(argsList, fnBody);\n });\n}\n\nfunction getBinding(\n thisEnvFn: NodePath,\n key: string,\n init: (name: string) => t.Expression,\n) {\n const cacheKey = \"binding:\" + key;\n let data: string | undefined = thisEnvFn.getData(cacheKey);\n if (!data) {\n const id = thisEnvFn.scope.generateUidIdentifier(key);\n data = id.name;\n thisEnvFn.setData(cacheKey, data);\n\n thisEnvFn.scope.push({\n id: id,\n init: init(data),\n });\n }\n\n return data;\n}\n\ntype ScopeInfo = {\n thisPaths: NodePath<t.ThisExpression | t.JSXIdentifier>[];\n superCalls: NodePath<t.CallExpression>[];\n superProps: NodePath<t.MemberExpression>[];\n argumentsPaths: NodePath<t.Identifier | t.JSXIdentifier>[];\n newTargetPaths: NodePath<t.MetaProperty>[];\n};\n\nconst getScopeInformationVisitor = mergeVisitors<ScopeInfo>([\n {\n ThisExpression(child, { thisPaths }) {\n thisPaths.push(child);\n },\n JSXIdentifier(child, { thisPaths }) {\n if (child.node.name !== \"this\") return;\n if (\n !child.parentPath.isJSXMemberExpression({ object: child.node }) &&\n !child.parentPath.isJSXOpeningElement({ name: child.node })\n ) {\n return;\n }\n\n thisPaths.push(child);\n },\n CallExpression(child, { superCalls }) {\n if (child.get(\"callee\").isSuper()) superCalls.push(child);\n },\n MemberExpression(child, { superProps }) {\n if (child.get(\"object\").isSuper()) superProps.push(child);\n },\n Identifier(child, { argumentsPaths }) {\n if (!child.isReferencedIdentifier({ name: \"arguments\" })) return;\n\n let curr = child.scope;\n do {\n if (curr.hasOwnBinding(\"arguments\")) {\n curr.rename(\"arguments\");\n return;\n }\n if (curr.path.isFunction() && !curr.path.isArrowFunctionExpression()) {\n break;\n }\n } while ((curr = curr.parent));\n\n argumentsPaths.push(child);\n },\n MetaProperty(child, { newTargetPaths }) {\n if (!child.get(\"meta\").isIdentifier({ name: \"new\" })) return;\n if (!child.get(\"property\").isIdentifier({ name: \"target\" })) return;\n\n newTargetPaths.push(child);\n },\n },\n environmentVisitor,\n]);\n\nfunction getScopeInformation(fnPath: NodePath) {\n const thisPaths: ScopeInfo[\"thisPaths\"] = [];\n const argumentsPaths: ScopeInfo[\"argumentsPaths\"] = [];\n const newTargetPaths: ScopeInfo[\"newTargetPaths\"] = [];\n const superProps: ScopeInfo[\"superProps\"] = [];\n const superCalls: ScopeInfo[\"superCalls\"] = [];\n\n fnPath.traverse(getScopeInformationVisitor, {\n thisPaths,\n argumentsPaths,\n newTargetPaths,\n superProps,\n superCalls,\n });\n\n return {\n thisPaths,\n argumentsPaths,\n newTargetPaths,\n superProps,\n superCalls,\n };\n}\n"],"mappings":";;;;;;;;;;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AL,EAA6D;IAE7DgE,cAAc,CAACnD,IAAf,CAAoBkC,KAApB;EACD;;AA1CH,CAD0D,EA6C1DG,iCA7C0D,CAAzB,CAAnC;;AAgDA,SAASiB,mBAAT,CAA6BnC,MAA7B,EAA+C;EAC7C,MAAM8B,SAAiC,GAAG,EAA1C;EACA,MAAMC,cAA2C,GAAG,EAApD;EACA,MAAMC,cAA2C,GAAG,EAApD;EACA,MAAMC,UAAmC,GAAG,EAA5C;EACA,MAAMC,UAAmC,GAAG,EAA5C;EAEAlC,MAAM,CAACqC,QAAP,CAAgBuE,0BAAhB,EAA4C;IAC1C9E,SAD0C;IAE1CC,cAF0C;IAG1CC,cAH0C;IAI1CC,UAJ0C;IAK1CC;EAL0C,CAA5C;EAQA,OAAO;IACLJ,SADK;IAELC,cAFK;IAGLC,cAHK;IAILC,UAJK;IAKLC;EALK,CAAP;AAOD"}
|
package/lib/path/evaluation.js
CHANGED
@@ -219,20 +219,20 @@ function _evaluate(path, state) {
|
|
219
219
|
}
|
220
220
|
|
221
221
|
const keyPath = prop.get("key");
|
222
|
-
let key
|
222
|
+
let key;
|
223
223
|
|
224
224
|
if (prop.node.computed) {
|
225
|
-
key =
|
225
|
+
key = keyPath.evaluate();
|
226
226
|
|
227
227
|
if (!key.confident) {
|
228
228
|
return deopt(key.deopt, state);
|
229
229
|
}
|
230
230
|
|
231
231
|
key = key.value;
|
232
|
-
} else if (
|
233
|
-
key =
|
232
|
+
} else if (keyPath.isIdentifier()) {
|
233
|
+
key = keyPath.node.name;
|
234
234
|
} else {
|
235
|
-
key =
|
235
|
+
key = keyPath.node.value;
|
236
236
|
}
|
237
237
|
|
238
238
|
const valuePath = prop.get("value");
|
@@ -267,6 +267,11 @@ function _evaluate(path, state) {
|
|
267
267
|
state.confident = leftConfident && (!left || rightConfident);
|
268
268
|
if (!state.confident) return;
|
269
269
|
return left && right;
|
270
|
+
|
271
|
+
case "??":
|
272
|
+
state.confident = leftConfident && (left != null || rightConfident);
|
273
|
+
if (!state.confident) return;
|
274
|
+
return left != null ? left : right;
|
270
275
|
}
|
271
276
|
}
|
272
277
|
|
@@ -406,4 +411,6 @@ function evaluate() {
|
|
406
411
|
deopt: state.deoptPath,
|
407
412
|
value: value
|
408
413
|
};
|
409
|
-
}
|
414
|
+
}
|
415
|
+
|
416
|
+
//# sourceMappingURL=evaluation.js.map
|
@@ -0,0 +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,aAAa,GAAG,CAAC,QAAD,EAAW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ACA,IAAIE,IAAJ,EAAUH,GAAG,IAAII,MAAM,CAACxF,cAAc,CAACuF,IAAD,EAAOzF,KAAP,CAAf,CAAb;EACX;;EAED,IAAI,CAACA,KAAK,CAACJ,SAAX,EAAsB;EACtB,OAAO0F,GAAP;AACD;;AAkBM,SAAS3F,QAAT,GAIL;EACA,MAAMK,KAAY,GAAG;IACnBJ,SAAS,EAAE,IADQ;IAEnBK,SAAS,EAAE,IAFQ;IAGnBG,IAAI,EAAE,IAAIuF,GAAJ;EAHa,CAArB;EAKA,IAAI9F,KAAK,GAAGK,cAAc,CAAC,IAAD,EAAOF,KAAP,CAA1B;EACA,IAAI,CAACA,KAAK,CAACJ,SAAX,EAAsBC,KAAK,GAAGgD,SAAR;EAEtB,OAAO;IACLjD,SAAS,EAAEI,KAAK,CAACJ,SADZ;IAELE,KAAK,EAAEE,KAAK,CAACC,SAFR;IAGLJ,KAAK,EAAEA;EAHF,CAAP;AAKD"}
|
package/lib/path/family.js
CHANGED
@@ -402,6 +402,8 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
|
|
402
402
|
return ids;
|
403
403
|
}
|
404
404
|
|
405
|
-
function getOuterBindingIdentifierPaths(duplicates) {
|
405
|
+
function getOuterBindingIdentifierPaths(duplicates = false) {
|
406
406
|
return this.getBindingIdentifierPaths(duplicates, true);
|
407
|
-
}
|
407
|
+
}
|
408
|
+
|
409
|
+
//# sourceMappingURL=family.js.map
|
@@ -0,0 +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;;;EACEA,qB,EAAyBC,sB;EACzBC,0B,EAA8BC,2B;EAC9BC,a;EACAC,c;EACAC;;AAIF,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,gBAAgB,GAAG,CAAzB;;AAmBA,SAASC,gBAAT,CAA0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