@babel/traverse 7.20.10 → 7.20.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @babel/traverse might be problematic. Click here for more details.
- package/lib/context.js +2 -14
- package/lib/context.js.map +1 -1
- package/lib/index.js +1 -4
- package/lib/index.js.map +1 -1
- package/lib/path/ancestry.js +0 -19
- package/lib/path/ancestry.js.map +1 -1
- package/lib/path/comments.js +0 -2
- package/lib/path/comments.js.map +1 -1
- package/lib/path/context.js +5 -21
- package/lib/path/context.js.map +1 -1
- package/lib/path/conversion.js +6 -30
- package/lib/path/conversion.js.map +1 -1
- package/lib/path/evaluation.js +14 -20
- package/lib/path/evaluation.js.map +1 -1
- package/lib/path/family.js +3 -9
- package/lib/path/family.js.map +1 -1
- package/lib/path/index.js +1 -6
- package/lib/path/index.js.map +1 -1
- package/lib/path/inference/index.js +1 -9
- package/lib/path/inference/index.js.map +1 -1
- package/lib/path/inference/inferer-reference.js +1 -13
- package/lib/path/inference/inferer-reference.js.map +1 -1
- package/lib/path/inference/inferers.js +2 -5
- package/lib/path/inference/inferers.js.map +1 -1
- package/lib/path/introspection.js +1 -45
- package/lib/path/introspection.js.map +1 -1
- package/lib/path/lib/hoister.js +1 -22
- package/lib/path/lib/hoister.js.map +1 -1
- package/lib/path/lib/removal-hooks.js +1 -7
- package/lib/path/lib/removal-hooks.js.map +1 -1
- package/lib/path/lib/virtual-types-validator.js +0 -2
- package/lib/path/lib/virtual-types-validator.js.map +1 -1
- package/lib/path/lib/virtual-types.js +0 -1
- package/lib/path/lib/virtual-types.js.map +1 -1
- package/lib/path/modification.js +7 -24
- package/lib/path/modification.js.map +1 -1
- package/lib/path/removal.js +0 -1
- package/lib/path/removal.js.map +1 -1
- package/lib/path/replacement.js +2 -16
- package/lib/path/replacement.js.map +1 -1
- package/lib/scope/binding.js +1 -6
- package/lib/scope/binding.js.map +1 -1
- package/lib/scope/index.js +5 -50
- package/lib/scope/index.js.map +1 -1
- package/lib/scope/lib/renamer.js +1 -6
- package/lib/scope/lib/renamer.js.map +1 -1
- package/lib/visitors.js +2 -23
- package/lib/visitors.js.map +1 -1
- package/package.json +1 -1
package/lib/context.js
CHANGED
@@ -18,19 +18,14 @@ class TraversalContext {
|
|
18
18
|
this.state = state;
|
19
19
|
this.opts = opts;
|
20
20
|
}
|
21
|
-
|
22
21
|
shouldVisit(node) {
|
23
22
|
const opts = this.opts;
|
24
23
|
if (opts.enter || opts.exit) return true;
|
25
|
-
|
26
24
|
if (opts[node.type]) return true;
|
27
|
-
|
28
25
|
const keys = VISITOR_KEYS[node.type];
|
29
26
|
if (!(keys != null && keys.length)) return false;
|
30
|
-
|
31
27
|
for (const key of keys) {
|
32
|
-
if (
|
33
|
-
node[key]) {
|
28
|
+
if (node[key]) {
|
34
29
|
return true;
|
35
30
|
}
|
36
31
|
}
|
@@ -57,7 +52,6 @@ class TraversalContext {
|
|
57
52
|
visitMultiple(container, parent, listKey) {
|
58
53
|
if (container.length === 0) return false;
|
59
54
|
const queue = [];
|
60
|
-
|
61
55
|
for (let key = 0; key < container.length; key++) {
|
62
56
|
const node = container[key];
|
63
57
|
if (node && this.shouldVisit(node)) {
|
@@ -67,8 +61,7 @@ class TraversalContext {
|
|
67
61
|
return this.visitQueue(queue);
|
68
62
|
}
|
69
63
|
visitSingle(node, key) {
|
70
|
-
if (this.shouldVisit(
|
71
|
-
node[key])) {
|
64
|
+
if (this.shouldVisit(node[key])) {
|
72
65
|
return this.visitQueue([this.create(node, node, key)]);
|
73
66
|
} else {
|
74
67
|
return false;
|
@@ -79,15 +72,12 @@ class TraversalContext {
|
|
79
72
|
this.priorityQueue = [];
|
80
73
|
const visited = new WeakSet();
|
81
74
|
let stop = false;
|
82
|
-
|
83
75
|
for (const path of queue) {
|
84
76
|
path.resync();
|
85
77
|
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
|
86
78
|
path.pushContext(this);
|
87
79
|
}
|
88
|
-
|
89
80
|
if (path.key === null) continue;
|
90
|
-
|
91
81
|
const {
|
92
82
|
node
|
93
83
|
} = path;
|
@@ -104,11 +94,9 @@ class TraversalContext {
|
|
104
94
|
if (stop) break;
|
105
95
|
}
|
106
96
|
}
|
107
|
-
|
108
97
|
for (const path of queue) {
|
109
98
|
path.popContext();
|
110
99
|
}
|
111
|
-
|
112
100
|
this.queue = null;
|
113
101
|
return stop;
|
114
102
|
}
|
package/lib/context.js.map
CHANGED
@@ -1 +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;AAA4C;EAAnCA;AAAY;AAMN,MAAMC,gBAAgB,CAAc;EACjDC,WAAW,CACTC,KAAY,EACZC,IAAqB,EACrBC,KAAQ,EACRC,UAAoB,EACpB;IAAA,KAWFC,KAAK,GAA2B,IAAI;IAAA,KACpCC,aAAa,GAA2B,IAAI;IAX1C,IAAI,CAACF,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACH,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACD,IAAI,GAAGA,IAAI;EAClB
|
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;AAA4C;EAAnCA;AAAY;AAMN,MAAMC,gBAAgB,CAAc;EACjDC,WAAW,CACTC,KAAY,EACZC,IAAqB,EACrBC,KAAQ,EACRC,UAAoB,EACpB;IAAA,KAWFC,KAAK,GAA2B,IAAI;IAAA,KACpCC,aAAa,GAA2B,IAAI;IAX1C,IAAI,CAACF,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACH,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACD,IAAI,GAAGA,IAAI;EAClB;EAcAK,WAAW,CAACC,IAAY,EAAW;IACjC,MAAMN,IAAI,GAAG,IAAI,CAACA,IAAe;IACjC,IAAIA,IAAI,CAACO,KAAK,IAAIP,IAAI,CAACQ,IAAI,EAAE,OAAO,IAAI;IAGxC,IAAIR,IAAI,CAACM,IAAI,CAACG,IAAI,CAAC,EAAE,OAAO,IAAI;IAGhC,MAAMC,IAA+B,GAAGd,YAAY,CAACU,IAAI,CAACG,IAAI,CAAC;IAC/D,IAAI,EAACC,IAAI,YAAJA,IAAI,CAAEC,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AAK;QAClB,IAAIyB,IAAI,EAAE;MACZ;IACF;IAGA,KAAK,MAAMR,IAAI,IAAIjB,KAAK,EAAE;MACxBiB,IAAI,CAACe,UAAU,EAAE;IACnB;IAGA,IAAI,CAAChC,KAAK,GAAG,IAAI;IAEjB,OAAOyB,IAAI;EACb;EAEAM,KAAK,CAAC5B,IAAY,EAAEM,GAAW,EAAE;IAE/B,MAAMwB,KAAK,GAAG9B,IAAI,CAACM,GAAG,CAA6B;IACnD,IAAI,CAACwB,KAAK,EAAE,OAAO,KAAK;IAExB,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACxB,OAAO,IAAI,CAACb,aAAa,CAACa,KAAK,EAAE9B,IAAI,EAAEM,GAAG,CAAC;IAC7C,CAAC,MAAM;MACL,OAAO,IAAI,CAACa,WAAW,CAACnB,IAAI,EAAEM,GAAG,CAAC;IACpC;EACF;AACF;AAAC"}
|
package/lib/index.js
CHANGED
@@ -35,8 +35,7 @@ const {
|
|
35
35
|
removeProperties,
|
36
36
|
traverseFast
|
37
37
|
} = _t;
|
38
|
-
function traverse(parent,
|
39
|
-
opts = {}, scope, state, parentPath) {
|
38
|
+
function traverse(parent, opts = {}, scope, state, parentPath) {
|
40
39
|
if (!parent) return;
|
41
40
|
if (!opts.noScope && !scope) {
|
42
41
|
if (parent.type !== "Program" && parent.type !== "File") {
|
@@ -60,7 +59,6 @@ traverse.cheap = function (node, enter) {
|
|
60
59
|
traverse.node = function (node, opts, scope, state, path, skipKeys) {
|
61
60
|
(0, _traverseNode.traverseNode)(node, opts, scope, state, path, skipKeys);
|
62
61
|
};
|
63
|
-
|
64
62
|
traverse.clearNode = function (node, opts) {
|
65
63
|
removeProperties(node, opts);
|
66
64
|
cache.path.delete(node);
|
@@ -77,7 +75,6 @@ function hasDenylistedType(path, state) {
|
|
77
75
|
}
|
78
76
|
traverse.hasType = function (tree, type, denylistTypes) {
|
79
77
|
if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
|
80
|
-
|
81
78
|
if (tree.type === type) return true;
|
82
79
|
const state = {
|
83
80
|
has: false,
|
package/lib/index.js.map
CHANGED
@@ -1 +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;AAAuC;AACvC;AAOA;AAIA;AAGA;AACA;AACA;AAAuC;EAfrCA,YAAY;EACZC,gBAAgB;EAEhBC;AAAY;AAuCd,SAASC,QAAQ,CACfC,MAAc
|
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;AAAuC;AACvC;AAOA;AAIA;AAGA;AACA;AACA;AAAuC;EAfrCA,YAAY;EACZC,gBAAgB;EAEhBC;AAAY;AAuCd,SAASC,QAAQ,CACfC,MAAc,EAEdC,IAAa,GAAG,CAAC,CAAC,EAClBC,KAAa,EACbC,KAAW,EACXC,UAAqB,EACrB;EACA,IAAI,CAACJ,MAAM,EAAE;EAEb,IAAI,CAACC,IAAI,CAACI,OAAO,IAAI,CAACH,KAAK,EAAE;IAC3B,IAAIF,MAAM,CA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AQ,CAACkB,SAAS,EAAEhB,IAAI,CAAC;EAC5C,OAAOmB,IAAI;AACb,CAAC;AAMD,SAASC,iBAAiB,CAACN,IAAc,EAAEZ,KAA6B,EAAE;EACxE,IAAIY,IAAI,CAACF,IAAI,CAACP,IAAI,KAAKH,KAAK,CAACG,IAAI,EAAE;IACjCH,KAAK,CAACmB,GAAG,GAAG,IAAI;IAChBP,IAAI,CAACQ,IAAI,EAAE;EACb;AACF;AAEAxB,QAAQ,CAACyB,OAAO,GAAG,UACjBJ,IAAY,EACZd,IAAoB,EACpBmB,aAA6B,EACpB;EAET,IAAIA,aAAa,YAAbA,aAAa,CAAEC,QAAQ,CAACN,IAAI,CAACd,IAAI,CAAC,EAAE,OAAO,KAAK;EAGpD,IAAIc,IAAI,CAACd,IAAI,KAAKA,IAAI,EAAE,OAAO,IAAI;EAEnC,MAAMH,KAA6B,GAAG;IACpCmB,GAAG,EAAE,KAAK;IACVhB,IAAI,EAAEA;EACR,CAAC;EAEDP,QAAQ,CACNqB,IAAI,EACJ;IACEf,OAAO,EAAE,IAAI;IACbsB,QAAQ,EAAEF,aAAa;IACvBX,KAAK,EAAEO;EACT,CAAC,EACD,IAAI,EACJlB,KAAK,CACN;EAED,OAAOA,KAAK,CAACmB,GAAG;AAClB,CAAC;AAEDvB,QAAQ,CAACmB,KAAK,GAAGA,KAAK"}
|
package/lib/path/ancestry.js
CHANGED
@@ -17,7 +17,6 @@ var _t = require("@babel/types");
|
|
17
17
|
const {
|
18
18
|
VISITOR_KEYS
|
19
19
|
} = _t;
|
20
|
-
|
21
20
|
function findParent(callback) {
|
22
21
|
let path = this;
|
23
22
|
while (path = path.parentPath) {
|
@@ -25,7 +24,6 @@ function findParent(callback) {
|
|
25
24
|
}
|
26
25
|
return null;
|
27
26
|
}
|
28
|
-
|
29
27
|
function find(callback) {
|
30
28
|
let path = this;
|
31
29
|
do {
|
@@ -33,11 +31,9 @@ function find(callback) {
|
|
33
31
|
} while (path = path.parentPath);
|
34
32
|
return null;
|
35
33
|
}
|
36
|
-
|
37
34
|
function getFunctionParent() {
|
38
35
|
return this.findParent(p => p.isFunction());
|
39
36
|
}
|
40
|
-
|
41
37
|
function getStatementParent() {
|
42
38
|
let path = this;
|
43
39
|
do {
|
@@ -52,26 +48,22 @@ function getStatementParent() {
|
|
52
48
|
}
|
53
49
|
return path;
|
54
50
|
}
|
55
|
-
|
56
51
|
function getEarliestCommonAncestorFrom(paths) {
|
57
52
|
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
|
58
53
|
let earliest;
|
59
54
|
const keys = VISITOR_KEYS[deepest.type];
|
60
55
|
for (const ancestry of ancestries) {
|
61
56
|
const path = ancestry[i + 1];
|
62
|
-
|
63
57
|
if (!earliest) {
|
64
58
|
earliest = path;
|
65
59
|
continue;
|
66
60
|
}
|
67
|
-
|
68
61
|
if (path.listKey && earliest.listKey === path.listKey) {
|
69
62
|
if (path.key < earliest.key) {
|
70
63
|
earliest = path;
|
71
64
|
continue;
|
72
65
|
}
|
73
66
|
}
|
74
|
-
|
75
67
|
const earliestKeyIndex = keys.indexOf(earliest.parentKey);
|
76
68
|
const currentKeyIndex = keys.indexOf(path.parentKey);
|
77
69
|
if (earliestKeyIndex > currentKeyIndex) {
|
@@ -81,7 +73,6 @@ function getEarliestCommonAncestorFrom(paths) {
|
|
81
73
|
return earliest;
|
82
74
|
});
|
83
75
|
}
|
84
|
-
|
85
76
|
function getDeepestCommonAncestorFrom(paths, filter) {
|
86
77
|
if (!paths.length) {
|
87
78
|
return this;
|
@@ -89,25 +80,19 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
89
80
|
if (paths.length === 1) {
|
90
81
|
return paths[0];
|
91
82
|
}
|
92
|
-
|
93
83
|
let minDepth = Infinity;
|
94
|
-
|
95
84
|
let lastCommonIndex, lastCommon;
|
96
|
-
|
97
85
|
const ancestries = paths.map(path => {
|
98
86
|
const ancestry = [];
|
99
87
|
do {
|
100
88
|
ancestry.unshift(path);
|
101
89
|
} while ((path = path.parentPath) && path !== this);
|
102
|
-
|
103
90
|
if (ancestry.length < minDepth) {
|
104
91
|
minDepth = ancestry.length;
|
105
92
|
}
|
106
93
|
return ancestry;
|
107
94
|
});
|
108
|
-
|
109
95
|
const first = ancestries[0];
|
110
|
-
|
111
96
|
depthLoop: for (let i = 0; i < minDepth; i++) {
|
112
97
|
const shouldMatch = first[i];
|
113
98
|
for (const ancestry of ancestries) {
|
@@ -115,7 +100,6 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
115
100
|
break depthLoop;
|
116
101
|
}
|
117
102
|
}
|
118
|
-
|
119
103
|
lastCommonIndex = i;
|
120
104
|
lastCommon = shouldMatch;
|
121
105
|
}
|
@@ -129,7 +113,6 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
129
113
|
throw new Error("Couldn't find intersection");
|
130
114
|
}
|
131
115
|
}
|
132
|
-
|
133
116
|
function getAncestry() {
|
134
117
|
let path = this;
|
135
118
|
const paths = [];
|
@@ -138,11 +121,9 @@ function getAncestry() {
|
|
138
121
|
} while (path = path.parentPath);
|
139
122
|
return paths;
|
140
123
|
}
|
141
|
-
|
142
124
|
function isAncestor(maybeDescendant) {
|
143
125
|
return maybeDescendant.isDescendant(this);
|
144
126
|
}
|
145
|
-
|
146
127
|
function isDescendant(maybeAncestor) {
|
147
128
|
return !!this.findParent(parent => parent === maybeAncestor);
|
148
129
|
}
|
package/lib/path/ancestry.js.map
CHANGED
@@ -1 +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;AAA4C;EAAnCA;AAAY;;AAWd,SAASC,UAAU,CAExBC,QAAqC,EACpB;EACjB,IAAIC,IAAI,GAAG,IAAI;EACf,OAAQA,IAAI,GAAGA,IAAI,CAACC,UAAU,EAAG;IAC/B,IAAIF,QAAQ,CAACC,IAAI,CAAC,EAAE,OAAOA,IAAI;EACjC;EACA,OAAO,IAAI;AACb;;AAQO,SAASE,IAAI,CAElBH,QAAqC,EACpB;EACjB,IAAIC,IAAI,GAAG,IAAI;EACf,GAAG;IACD,IAAID,QAAQ,CAACC,IAAI,CAAC,EAAE,OAAOA,IAAI;EACjC,CAAC,QAASA,IAAI,GAAGA,IAAI,CAACC,UAAU;EAChC,OAAO,IAAI;AACb;;AAMO,SAASE,iBAAiB,GAA8C;EAC7E,OAAO,IAAI,CAACL,UAAU,CAACM,CAAC,IAAIA,CAAC,CAACC,UAAU,EAAE,CAAC;AAC7C;;AAMO,SAASC,kBAAkB,GAAwC;EACxE,IAAIN,IAAI,GAAG,IAAI;EAEf,GAAG;IACD,IACE,CAACA,IAA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AAU,CAAC;IACxD,CAAC,MAAM;MACL,OAAOgB,UAAU;IACnB;EACF,CAAC,MAAM;IACL,MAAM,IAAItB,KAAK,CAAC,4BAA4B,CAAC;EAC/C;AACF;;AAQO,SAAS4B,WAAW,GAAkC;EAC3D,IAAIzC,IAAI,GAAG,IAAI;EACf,MAAMe,KAAK,GAAG,EAAE;EAChB,GAAG;IACDA,KAAK,CAAC2B,IAAI,CAAC1C,IAAI,CAAC;EAClB,CAAC,QAASA,IAAI,GAAGA,IAAI,CAACC,UAAU;EAChC,OAAOc,KAAK;AACd;;AAKO,SAAS4B,UAAU,CAAiBC,eAAyB,EAAW;EAC7E,OAAOA,eAAe,CAACC,YAAY,CAAC,IAAI,CAAC;AAC3C;;AAKO,SAASA,YAAY,CAAiBC,aAAuB,EAAW;EAC7E,OAAO,CAAC,CAAC,IAAI,CAAChD,UAAU,CAACiD,MAAM,IAAIA,MAAM,KAAKD,aAAa,CAAC;AAC9D;AAEO,SAASE,MAAM,CAAiB,GAAGC,cAAwB,EAAW;EAC3E,IAAIjD,IAAI,GAAG,IAAI;EACf,OAAOA,IAAI,EAAE;IACX,KAAK,MAAMsB,IAAI,IAAI2B,cAAc,EAAE;MACjC,IAAIjD,IAAI,CAACkD,IAAI,CAAC5B,IAAI,KAAKA,IAAI,EAAE,OAAO,IAAI;IAC1C;IACAtB,IAAI,GAAGA,IAAI,CAACC,UAAU;EACxB;EAEA,OAAO,KAAK;AACd"}
|
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;AAA4C;EAAnCA;AAAY;AAWd,SAASC,UAAU,CAExBC,QAAqC,EACpB;EACjB,IAAIC,IAAI,GAAG,IAAI;EACf,OAAQA,IAAI,GAAGA,IAAI,CAACC,UAAU,EAAG;IAC/B,IAAIF,QAAQ,CAACC,IAAI,CAAC,EAAE,OAAOA,IAAI;EACjC;EACA,OAAO,IAAI;AACb;AAQO,SAASE,IAAI,CAElBH,QAAqC,EACpB;EACjB,IAAIC,IAAI,GAAG,IAAI;EACf,GAAG;IACD,IAAID,QAAQ,CAACC,IAAI,CAAC,EAAE,OAAOA,IAAI;EACjC,CAAC,QAASA,IAAI,GAAGA,IAAI,CAACC,UAAU;EAChC,OAAO,IAAI;AACb;AAMO,SAASE,iBAAiB,GAA8C;EAC7E,OAAO,IAAI,CAACL,UAAU,CAACM,CAAC,IAAIA,CAAC,CAACC,UAAU,EAAE,CAAC;AAC7C;AAMO,SAASC,kBAAkB,GAAwC;EACxE,IAAIN,IAAI,GAAG,IAAI;EAEf,GAAG;IACD,IACE,CAACA,IAAI,CAACC,UAAU,IACfM,KAAK,C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UAAU;IACnB;EACF,CAAC,MAAM;IACL,MAAM,IAAItB,KAAK,CAAC,4BAA4B,CAAC;EAC/C;AACF;AAQO,SAAS4B,WAAW,GAAkC;EAC3D,IAAIzC,IAAI,GAAG,IAAI;EACf,MAAMe,KAAK,GAAG,EAAE;EAChB,GAAG;IACDA,KAAK,CAAC2B,IAAI,CAAC1C,IAAI,CAAC;EAClB,CAAC,QAASA,IAAI,GAAGA,IAAI,CAACC,UAAU;EAChC,OAAOc,KAAK;AACd;AAKO,SAAS4B,UAAU,CAAiBC,eAAyB,EAAW;EAC7E,OAAOA,eAAe,CAACC,YAAY,CAAC,IAAI,CAAC;AAC3C;AAKO,SAASA,YAAY,CAAiBC,aAAuB,EAAW;EAC7E,OAAO,CAAC,CAAC,IAAI,CAAChD,UAAU,CAACiD,MAAM,IAAIA,MAAM,KAAKD,aAAa,CAAC;AAC9D;AAEO,SAASE,MAAM,CAAiB,GAAGC,cAAwB,EAAW;EAC3E,IAAIjD,IAAI,GAAG,IAAI;EACf,OAAOA,IAAI,EAAE;IACX,KAAK,MAAMsB,IAAI,IAAI2B,cAAc,EAAE;MACjC,IAAIjD,IAAI,CAACkD,IAAI,CAAC5B,IAAI,KAAKA,IAAI,EAAE,OAAO,IAAI;IAC1C;IACAtB,IAAI,GAAGA,IAAI,CAACC,UAAU;EACxB;EAEA,OAAO,KAAK;AACd"}
|
package/lib/path/comments.js
CHANGED
@@ -11,7 +11,6 @@ const {
|
|
11
11
|
addComment: _addComment,
|
12
12
|
addComments: _addComments
|
13
13
|
} = _t;
|
14
|
-
|
15
14
|
function shareCommentsWithSiblings() {
|
16
15
|
if (typeof this.key === "string") return;
|
17
16
|
const node = this.node;
|
@@ -32,7 +31,6 @@ function shareCommentsWithSiblings() {
|
|
32
31
|
function addComment(type, content, line) {
|
33
32
|
_addComment(this.node, type, content, line);
|
34
33
|
}
|
35
|
-
|
36
34
|
function addComments(type, comments) {
|
37
35
|
_addComments(this.node, type, comments);
|
38
36
|
}
|
package/lib/path/comments.js.map
CHANGED
@@ -1 +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;AAGsB;EAFpBA,UAAU,EAAIC,WAAW;EACzBC,WAAW,EAAIC;AAAY
|
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;AAGsB;EAFpBA,UAAU,EAAIC,WAAW;EACzBC,WAAW,EAAIC;AAAY;AAOtB,SAASC,yBAAyB,GAAiB;EAExD,IAAI,OAAO,IAAI,CAACC,GAAG,KAAK,QAAQ,EAAE;EAElC,MAAMC,IAAI,GAAG,IAAI,CAACA,IAAI;EACtB,IAAI,CAACA,IAAI,EAAE;EAEX,MAAMC,QAAQ,GAAGD,IAAI,CAACE,gBAAgB;EACtC,MAAMC,OAAO,GAAGH,IAAI,CAACI,eAAe;EACpC,IAAI,CAACH,QAAQ,IAAI,CAACE,OAAO,EAAE;EAE3B,MAAME,IAAI,GAAG,IAAI,CAACC,UAAU,CAAC,IAAI,CAACP,GAAG,GAAG,CAAC,CAAC;EAC1C,MAAMQ,IAAI,GAAG,IAAI,CAACD,UAAU,CAAC,IAAI,CAACP,GAAG,GAAG,CAAC,CAAC;EAC1C,MAAMS,OAAO,GAAGC,OAAO,CAACJ,IAAI,CAACL,IAAI,CAAC;EAClC,MAAMU,OAAO,GAAGD,OAAO,CAACF,IAAI,CAACP,IAAI,CAAC;EAClC,IAAIQ,OAAO,IAAI,CAACE,OAAO,EAAE;IACvBL,IAAI,CAACT,WAAW,CAAC,UAAU,EAAEK,QAAQ,CAAC;EACxC,CAAC,MAAM,IAAIS,OAAO,IAAI,CAACF,OAAO,EAAE;IAC9BD,IAAI,CAACX,WAAW,CAAC,SAAS,EAAEO,OAAO,CAAC;EACtC;AACF;AAEO,SAAST,UAAU,CAExBiB,IAA4B,EAC5BC,OAAe,EACfC,IAAc,EACd;EACAlB,WAAW,CAAC,IAAI,CAACK,IAAI,EAAEW,IAAI,EAAEC,OAAO,EAAEC,IAAI,CAAC;AAC7C;AAMO,SAASjB,WAAW,CAEzBe,IAA4B,EAC5BG,QAAqB,EACrB;EACAjB,YAAY,CAAC,IAAI,CAACG,IAAI,EAAEW,IAAI,EAAEG,QAAQ,CAAC;AACzC"}
|
package/lib/path/context.js
CHANGED
@@ -25,7 +25,6 @@ exports.stop = stop;
|
|
25
25
|
exports.visit = visit;
|
26
26
|
var _traverseNode = require("../traverse-node");
|
27
27
|
var _index = require("./index");
|
28
|
-
|
29
28
|
function call(key) {
|
30
29
|
const opts = this.opts;
|
31
30
|
this.debug(key);
|
@@ -50,9 +49,7 @@ function _call(fns) {
|
|
50
49
|
if (ret) {
|
51
50
|
throw new Error(`Unexpected return value from visitor method ${fn}`);
|
52
51
|
}
|
53
|
-
|
54
52
|
if (this.node !== node) return true;
|
55
|
-
|
56
53
|
if (this._traverseFlags > 0) return true;
|
57
54
|
}
|
58
55
|
return false;
|
@@ -62,7 +59,6 @@ function isDenylisted() {
|
|
62
59
|
const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
|
63
60
|
return denylist && denylist.indexOf(this.node.type) > -1;
|
64
61
|
}
|
65
|
-
|
66
62
|
function restoreContext(path, context) {
|
67
63
|
if (path.context !== context) {
|
68
64
|
path.context = context;
|
@@ -107,9 +103,7 @@ function stop() {
|
|
107
103
|
function setScope() {
|
108
104
|
if (this.opts && this.opts.noScope) return;
|
109
105
|
let path = this.parentPath;
|
110
|
-
if (
|
111
|
-
(this.key === "key" || this.listKey === "decorators") && path.isMethod() ||
|
112
|
-
this.key === "discriminant" && path.isSwitchStatement()) {
|
106
|
+
if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
|
113
107
|
path = path.parentPath;
|
114
108
|
}
|
115
109
|
let target;
|
@@ -134,14 +128,12 @@ function setContext(context) {
|
|
134
128
|
this.setScope();
|
135
129
|
return this;
|
136
130
|
}
|
137
|
-
|
138
131
|
function resync() {
|
139
132
|
if (this.removed) return;
|
140
133
|
this._resyncParent();
|
141
134
|
this._resyncList();
|
142
135
|
this._resyncKey();
|
143
136
|
}
|
144
|
-
|
145
137
|
function _resyncParent() {
|
146
138
|
if (this.parentPath) {
|
147
139
|
this.parent = this.parentPath.node;
|
@@ -149,11 +141,9 @@ function _resyncParent() {
|
|
149
141
|
}
|
150
142
|
function _resyncKey() {
|
151
143
|
if (!this.container) return;
|
152
|
-
if (this.node ===
|
153
|
-
this.container[this.key]) {
|
144
|
+
if (this.node === this.container[this.key]) {
|
154
145
|
return;
|
155
146
|
}
|
156
|
-
|
157
147
|
if (Array.isArray(this.container)) {
|
158
148
|
for (let i = 0; i < this.container.length; i++) {
|
159
149
|
if (this.container[i] === this.node) {
|
@@ -167,20 +157,16 @@ function _resyncKey() {
|
|
167
157
|
}
|
168
158
|
}
|
169
159
|
}
|
170
|
-
|
171
160
|
this.key = null;
|
172
161
|
}
|
173
162
|
function _resyncList() {
|
174
163
|
if (!this.parent || !this.inList) return;
|
175
|
-
const newContainer =
|
176
|
-
this.parent[this.listKey];
|
164
|
+
const newContainer = this.parent[this.listKey];
|
177
165
|
if (this.container === newContainer) return;
|
178
|
-
|
179
166
|
this.container = newContainer || null;
|
180
167
|
}
|
181
168
|
function _resyncRemoved() {
|
182
|
-
if (this.key == null || !this.container ||
|
183
|
-
this.container[this.key] !== this.node) {
|
169
|
+
if (this.key == null || !this.container || this.container[this.key] !== this.node) {
|
184
170
|
this._markRemoved();
|
185
171
|
}
|
186
172
|
}
|
@@ -205,13 +191,11 @@ function setup(parentPath, container, listKey, key) {
|
|
205
191
|
function setKey(key) {
|
206
192
|
var _this$node;
|
207
193
|
this.key = key;
|
208
|
-
this.node =
|
209
|
-
this.container[this.key];
|
194
|
+
this.node = this.container[this.key];
|
210
195
|
this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
|
211
196
|
}
|
212
197
|
function requeue(pathToQueue = this) {
|
213
198
|
if (pathToQueue.removed) return;
|
214
|
-
|
215
199
|
;
|
216
200
|
const contexts = this.contexts;
|
217
201
|
for (const context of contexts) {
|
package/lib/path/context.js.map
CHANGED
@@ -1 +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","isSwitchStatement","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 if (\n // Skip method scope if is computed method key or decorator expression\n ((this.key === \"key\" || this.listKey === \"decorators\") &&\n path.isMethod()) ||\n // Skip switch scope if for discriminant (`x` in `switch (x) {}`).\n (this.key === \"discriminant\" && path.isSwitchStatement())\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,IAAI,CAAiBC,GAAW,EAAW;EACzD,MAAMC,IAAI,GAAG,IAAI,CAACA,IAAI;EAEtB,IAAI,CAACC,KAAK,CAACF,GAAG,CAAC;EAEf,IAAI,IAAI,CAACG,IAAI,EAAE;IACb,IAAI,IAAI,CAACC,KAAK,CAACH,IAAI,CAACD,GAAG,CAAC,CAAC,EAAE,OAAO,IAAI;EACxC;EAEA,IAAI,IAAI,CAACG,IAAI,EAAE;IACb,OAAO,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC,IAAI,CAACE,IAAI,CAACE,IAAI,CAAC,IAAIJ,IAAI,CAAC,IAAI,CAACE,IAAI,CAACE,IAAI,CAAC,CAACL,GAAG,CAAC,CAAC;EACtE;EAEA,OAAO,KAAK;AACd;AAEO,SAASI,KAAK,CAAiBE,GAAqB,EAAW;EACpE,IAAI,CAACA,GAAG,EAAE,OAAO,KAAK;EAEtB,KAAK,MAAMC,EAAE,IAAID,GAAG,EAAE;IACpB,IAAI,CAACC,EAAE,EAAE;IAET,MAAMJ,IAAI,GAAG,IAAI,CAACA,IAAI;IACtB,IAAI,CAACA,IAAI,EAAE,OAAO,IAAI;IAEtB,MAAMK,GAAG,GAAGD,EAAE,CAACR,IAAI,CAAC,IAAI,CAACU,KAAK,EAAE,IAAI,EAAE,IAAI,CAACA,KAAK,CAAC;IACjD,IAAID,GAAG,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAI,OAAOA,GAAG,CAACE,IAAI,KAAK,UAAU,EAAE;MACpE,MAAM,IAAIC,KAAK,CACZ,mEAAkE,GAChE,wDAAuD,GACvD,8DAA6D,GAC7D,2BAA0B,CAC9B;IACH;IACA,IAAIH,GAAG,EAAE;MACP,MAAM,IAAIG,KA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ACgB,UAAU;IACtB,IAAI,CAAChB,IAAI,EAAE;IACX2C,QAAQ,GAAG3C,IAAI,CAAC2C,QAAQ;EAC1B;EACA,OAAOA,QAAQ;AACjB"}
|
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","isSwitchStatement","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 if (\n // Skip method scope if is computed method key or decorator expression\n ((this.key === \"key\" || this.listKey === \"decorators\") &&\n path.isMethod()) ||\n // Skip switch scope if for discriminant (`x` in `switch (x) {}`).\n (this.key === \"discriminant\" && path.isSwitchStatement())\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,IAAI,CAAiBC,GAAW,EAAW;EACzD,MAAMC,IAAI,GAAG,IAAI,CAACA,IAAI;EAEtB,IAAI,CAACC,KAAK,CAACF,GAAG,CAAC;EAEf,IAAI,IAAI,CAACG,IAAI,EAAE;IACb,IAAI,IAAI,CAACC,KAAK,CAACH,IAAI,CAACD,GAAG,CAAC,CAAC,EAAE,OAAO,IAAI;EAC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