@babel/traverse 7.22.8 → 8.0.0-alpha.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.
- package/lib/cache.js +7 -18
- package/lib/cache.js.map +1 -1
- package/lib/context.js +7 -14
- package/lib/context.js.map +1 -1
- package/lib/hub.js +1 -8
- package/lib/hub.js.map +1 -1
- package/lib/index.js +4846 -33
- package/lib/index.js.map +1 -1
- package/lib/path/ancestry.js +11 -26
- package/lib/path/ancestry.js.map +1 -1
- package/lib/path/comments.js +4 -12
- package/lib/path/comments.js.map +1 -1
- package/lib/path/context.js +35 -63
- package/lib/path/context.js.map +1 -1
- package/lib/path/conversion.js +18 -38
- package/lib/path/conversion.js.map +1 -1
- package/lib/path/evaluation.js +4 -11
- package/lib/path/evaluation.js.map +1 -1
- package/lib/path/family.js +19 -33
- package/lib/path/family.js.map +1 -1
- package/lib/path/index.js +42 -54
- package/lib/path/index.js.map +1 -1
- package/lib/path/inference/index.js +9 -21
- package/lib/path/inference/index.js.map +1 -1
- package/lib/path/inference/inferer-reference.js +5 -11
- package/lib/path/inference/inferer-reference.js.map +1 -1
- package/lib/path/inference/inferers.js +30 -65
- package/lib/path/inference/inferers.js.map +1 -1
- package/lib/path/inference/util.js +6 -16
- package/lib/path/inference/util.js.map +1 -1
- package/lib/path/introspection.js +20 -45
- package/lib/path/introspection.js.map +1 -1
- package/lib/path/lib/hoister.js +10 -17
- package/lib/path/lib/hoister.js.map +1 -1
- package/lib/path/lib/removal-hooks.js +1 -8
- package/lib/path/lib/removal-hooks.js.map +1 -1
- package/lib/path/lib/virtual-types-validator.js +19 -42
- package/lib/path/lib/virtual-types-validator.js.map +1 -1
- package/lib/path/lib/virtual-types.js +18 -42
- package/lib/path/lib/virtual-types.js.map +1 -1
- package/lib/path/modification.js +20 -35
- package/lib/path/modification.js.map +1 -1
- package/lib/path/removal.js +13 -25
- package/lib/path/removal.js.map +1 -1
- package/lib/path/replacement.js +25 -38
- package/lib/path/replacement.js.map +1 -1
- package/lib/scope/binding.js +10 -17
- package/lib/scope/binding.js.map +1 -1
- package/lib/scope/index.js +49 -66
- package/lib/scope/index.js.map +1 -1
- package/lib/scope/lib/renamer.js +12 -20
- package/lib/scope/lib/renamer.js.map +1 -1
- package/lib/traverse-node.js +4 -10
- package/lib/traverse-node.js.map +1 -1
- package/lib/visitors.js +16 -24
- package/lib/visitors.js.map +1 -1
- package/package.json +17 -13
package/lib/cache.js
CHANGED
@@ -1,25 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.clear = clear;
|
7
|
-
exports.clearPath = clearPath;
|
8
|
-
exports.clearScope = clearScope;
|
9
|
-
exports.scope = exports.path = void 0;
|
10
|
-
let path = new WeakMap();
|
11
|
-
exports.path = path;
|
12
|
-
let scope = new WeakMap();
|
13
|
-
exports.scope = scope;
|
14
|
-
function clear() {
|
1
|
+
export let path = new WeakMap();
|
2
|
+
export let scope = new WeakMap();
|
3
|
+
export function clear() {
|
15
4
|
clearPath();
|
16
5
|
clearScope();
|
17
6
|
}
|
18
|
-
function clearPath() {
|
19
|
-
|
7
|
+
export function clearPath() {
|
8
|
+
path = new WeakMap();
|
20
9
|
}
|
21
|
-
function clearScope() {
|
22
|
-
|
10
|
+
export function clearScope() {
|
11
|
+
scope = new WeakMap();
|
23
12
|
}
|
24
13
|
|
25
14
|
//# sourceMappingURL=cache.js.map
|
package/lib/cache.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["path","WeakMap","
|
1
|
+
{"version":3,"names":["path","WeakMap","scope","clear","clearPath","clearScope"],"sources":["../src/cache.ts"],"sourcesContent":["import type { Node } from \"@babel/types\";\nimport type NodePath from \"./path\";\nimport type Scope from \"./scope\";\n\nexport let path: WeakMap<Node, Map<Node, NodePath>> = new WeakMap();\nexport let scope: WeakMap<Node, 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":"AAIA,OAAO,IAAIA,IAAwC,GAAG,IAAIC,OAAO,CAAC,CAAC;AACnE,OAAO,IAAIC,KAA2B,GAAG,IAAID,OAAO,CAAC,CAAC;AAEtD,OAAO,SAASE,KAAKA,CAAA,EAAG;EACtBC,SAAS,CAAC,CAAC;EACXC,UAAU,CAAC,CAAC;AACd;AAEA,OAAO,SAASD,SAASA,CAAA,EAAG;EAC1BJ,IAAI,GAAG,IAAIC,OAAO,CAAC,CAAC;AACtB;AAEA,OAAO,SAASI,UAAUA,CAAA,EAAG;EAC3BH,KAAK,GAAG,IAAID,OAAO,CAAC,CAAC;AACvB"}
|
package/lib/context.js
CHANGED
@@ -1,29 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
var _path = require("./path");
|
8
|
-
var _t = require("@babel/types");
|
1
|
+
import NodePath from "./path/index.js";
|
2
|
+
import * as _t from "@babel/types";
|
9
3
|
const {
|
10
4
|
VISITOR_KEYS
|
11
5
|
} = _t;
|
12
|
-
class TraversalContext {
|
6
|
+
export default class TraversalContext {
|
13
7
|
constructor(scope, opts, state, parentPath) {
|
14
|
-
this.queue = null;
|
15
|
-
this.priorityQueue = null;
|
16
8
|
this.parentPath = parentPath;
|
17
9
|
this.scope = scope;
|
18
10
|
this.state = state;
|
19
11
|
this.opts = opts;
|
20
12
|
}
|
13
|
+
queue = null;
|
14
|
+
priorityQueue = null;
|
21
15
|
shouldVisit(node) {
|
22
16
|
const opts = this.opts;
|
23
17
|
if (opts.enter || opts.exit) return true;
|
24
18
|
if (opts[node.type]) return true;
|
25
19
|
const keys = VISITOR_KEYS[node.type];
|
26
|
-
if (!
|
20
|
+
if (!keys?.length) return false;
|
27
21
|
for (const key of keys) {
|
28
22
|
if (node[key]) {
|
29
23
|
return true;
|
@@ -32,7 +26,7 @@ class TraversalContext {
|
|
32
26
|
return false;
|
33
27
|
}
|
34
28
|
create(node, container, key, listKey) {
|
35
|
-
return
|
29
|
+
return NodePath.get({
|
36
30
|
parentPath: this.parentPath,
|
37
31
|
parent: node,
|
38
32
|
container,
|
@@ -110,6 +104,5 @@ class TraversalContext {
|
|
110
104
|
}
|
111
105
|
}
|
112
106
|
}
|
113
|
-
exports.default = TraversalContext;
|
114
107
|
|
115
108
|
//# sourceMappingURL=context.js.map
|
package/lib/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["NodePath","_t","VISITOR_KEYS","TraversalContext","constructor","scope","opts","state","parentPath","queue","priorityQueue","shouldVisit","node","enter","exit","type","keys","length","key","create","container","listKey","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 { ExplodedTraverseOptions } 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: ExplodedTraverseOptions<S>,\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: ExplodedTraverseOptions<S>;\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,OAAOA,QAAQ,MAAM,iBAAQ;AAC7B,YAAAC,EAAA,MAA6B,cAAc;AAAC;EAAnCC;AAAY,IAAAD,EAAA;AAMrB,eAAe,MAAME,gBAAgB,CAAc;EACjDC,WAAWA,CACTC,KAAY,EACZC,IAAgC,EAChCC,KAAQ,EACRC,UAAoB,EACpB;IACA,IAAI,CAACA,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACH,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACD,IAAI,GAAGA,IAAI;EAClB;EAMAG,KAAK,GAA2B,IAAI;EACpCC,aAAa,GAA2B,IAAI;EAO5CC,WAAWA,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,CAACC,IAAI,EAAEC,MAAM,EAAE,OAAO,KAAK;IAG/B,KAAK,MAAMC,GAAG,IAAIF,IAAI,EAAE;MACtB,IAEEJ,IAAI,CAACM,GAAG,CAAC,EACT;QACA,OAAO,IAAI;MACb;IACF;IAEA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CAAC;IACnB;IAGA,IAAI,CAAC/B,KAAK,GAAG,IAAI;IAEjB,OAAOwB,IAAI;EACb;EAEAM,KAAKA,CAAC3B,IAAY,EAAEM,GAAW,EAAE;IAE/B,MAAMuB,KAAK,GAAG7B,IAAI,CAACM,GAAG,CAA6B;IACnD,IAAI,CAACuB,KAAK,EAAE,OAAO,KAAK;IAExB,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACxB,OAAO,IAAI,CAACb,aAAa,CAACa,KAAK,EAAE7B,IAAI,EAAEM,GAAG,CAAC;IAC7C,CAAC,MAAM;MACL,OAAO,IAAI,CAACY,WAAW,CAAClB,IAAI,EAAEM,GAAG,CAAC;IACpC;EACF;AACF"}
|
package/lib/hub.js
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
class Hub {
|
1
|
+
export default class Hub {
|
8
2
|
getCode() {}
|
9
3
|
getScope() {}
|
10
4
|
addHelper() {
|
@@ -14,6 +8,5 @@ class Hub {
|
|
14
8
|
return new Error(msg);
|
15
9
|
}
|
16
10
|
}
|
17
|
-
exports.default = Hub;
|
18
11
|
|
19
12
|
//# sourceMappingURL=hub.js.map
|
package/lib/hub.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Hub","getCode","getScope","addHelper","Error","buildError","node","msg","TypeError"
|
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":"AAUA,eAAe,MAAMA,GAAG,CAAyB;EAC/CC,OAAOA,CAAA,EAAG,CAAC;EAEXC,QAAQA,CAAA,EAAG,CAAC;EAEZC,SAASA,CAAA,EAAG;IACV,MAAM,IAAIC,KAAK,CAAC,+CAA+C,CAAC;EAClE;EAEAC,UAAUA,CAACC,IAAU,EAAEC,GAAW,EAAEH,KAAK,GAAGI,SAAS,EAAS;IAC5D,OAAO,IAAIJ,KAAK,CAACG,GAAG,CAAC;EACvB;AACF"}
|