@babel/traverse 7.22.7 → 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.
Files changed (57) hide show
  1. package/lib/cache.js +7 -32
  2. package/lib/cache.js.map +1 -1
  3. package/lib/context.js +7 -14
  4. package/lib/context.js.map +1 -1
  5. package/lib/hub.js +1 -8
  6. package/lib/hub.js.map +1 -1
  7. package/lib/index.js +4847 -36
  8. package/lib/index.js.map +1 -1
  9. package/lib/path/ancestry.js +11 -26
  10. package/lib/path/ancestry.js.map +1 -1
  11. package/lib/path/comments.js +4 -12
  12. package/lib/path/comments.js.map +1 -1
  13. package/lib/path/context.js +35 -63
  14. package/lib/path/context.js.map +1 -1
  15. package/lib/path/conversion.js +18 -38
  16. package/lib/path/conversion.js.map +1 -1
  17. package/lib/path/evaluation.js +4 -11
  18. package/lib/path/evaluation.js.map +1 -1
  19. package/lib/path/family.js +19 -33
  20. package/lib/path/family.js.map +1 -1
  21. package/lib/path/index.js +45 -53
  22. package/lib/path/index.js.map +1 -1
  23. package/lib/path/inference/index.js +9 -21
  24. package/lib/path/inference/index.js.map +1 -1
  25. package/lib/path/inference/inferer-reference.js +5 -11
  26. package/lib/path/inference/inferer-reference.js.map +1 -1
  27. package/lib/path/inference/inferers.js +30 -65
  28. package/lib/path/inference/inferers.js.map +1 -1
  29. package/lib/path/inference/util.js +6 -16
  30. package/lib/path/inference/util.js.map +1 -1
  31. package/lib/path/introspection.js +20 -45
  32. package/lib/path/introspection.js.map +1 -1
  33. package/lib/path/lib/hoister.js +10 -17
  34. package/lib/path/lib/hoister.js.map +1 -1
  35. package/lib/path/lib/removal-hooks.js +1 -8
  36. package/lib/path/lib/removal-hooks.js.map +1 -1
  37. package/lib/path/lib/virtual-types-validator.js +19 -42
  38. package/lib/path/lib/virtual-types-validator.js.map +1 -1
  39. package/lib/path/lib/virtual-types.js +18 -42
  40. package/lib/path/lib/virtual-types.js.map +1 -1
  41. package/lib/path/modification.js +20 -35
  42. package/lib/path/modification.js.map +1 -1
  43. package/lib/path/removal.js +13 -27
  44. package/lib/path/removal.js.map +1 -1
  45. package/lib/path/replacement.js +25 -38
  46. package/lib/path/replacement.js.map +1 -1
  47. package/lib/scope/binding.js +10 -17
  48. package/lib/scope/binding.js.map +1 -1
  49. package/lib/scope/index.js +49 -66
  50. package/lib/scope/index.js.map +1 -1
  51. package/lib/scope/lib/renamer.js +12 -20
  52. package/lib/scope/lib/renamer.js.map +1 -1
  53. package/lib/traverse-node.js +5 -15
  54. package/lib/traverse-node.js.map +1 -1
  55. package/lib/visitors.js +16 -24
  56. package/lib/visitors.js.map +1 -1
  57. package/package.json +17 -14
package/lib/cache.js CHANGED
@@ -1,39 +1,14 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clear = clear;
7
- exports.clearPath = clearPath;
8
- exports.clearScope = clearScope;
9
- exports.getCachedPaths = getCachedPaths;
10
- exports.getOrCreateCachedPaths = getOrCreateCachedPaths;
11
- exports.scope = exports.path = void 0;
12
- let pathsCache = new WeakMap();
13
- exports.path = pathsCache;
14
- let scope = new WeakMap();
15
- exports.scope = scope;
16
- function clear() {
1
+ export let path = new WeakMap();
2
+ export let scope = new WeakMap();
3
+ export function clear() {
17
4
  clearPath();
18
5
  clearScope();
19
6
  }
20
- function clearPath() {
21
- exports.path = pathsCache = new WeakMap();
22
- }
23
- function clearScope() {
24
- exports.scope = scope = new WeakMap();
25
- }
26
- const nullHub = Object.freeze({});
27
- function getCachedPaths(hub, parent) {
28
- var _pathsCache$get;
29
- return (_pathsCache$get = pathsCache.get(hub != null ? hub : nullHub)) == null ? void 0 : _pathsCache$get.get(parent);
7
+ export function clearPath() {
8
+ path = new WeakMap();
30
9
  }
31
- function getOrCreateCachedPaths(hub, parent) {
32
- let parents = pathsCache.get(hub != null ? hub : nullHub);
33
- if (!parents) pathsCache.set(hub != null ? hub : nullHub, parents = new WeakMap());
34
- let paths = parents.get(parent);
35
- if (!paths) parents.set(parent, paths = new Map());
36
- return paths;
10
+ export function clearScope() {
11
+ scope = new WeakMap();
37
12
  }
38
13
 
39
14
  //# sourceMappingURL=cache.js.map
package/lib/cache.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["pathsCache","WeakMap","exports","path","scope","clear","clearPath","clearScope","nullHub","Object","freeze","getCachedPaths","hub","parent","_pathsCache$get","get","getOrCreateCachedPaths","parents","set","paths","Map"],"sources":["../src/cache.ts"],"sourcesContent":["import type { Node } from \"@babel/types\";\nimport type NodePath from \"./path\";\nimport type Scope from \"./scope\";\nimport type { HubInterface } from \"./hub\";\n\nlet pathsCache: WeakMap<\n HubInterface | typeof nullHub,\n WeakMap<Node, Map<Node, NodePath>>\n> = new WeakMap();\nexport { pathsCache as path };\nexport let scope: WeakMap<Node, Scope> = new WeakMap();\n\nexport function clear() {\n clearPath();\n clearScope();\n}\n\nexport function clearPath() {\n pathsCache = new WeakMap();\n}\n\nexport function clearScope() {\n scope = new WeakMap();\n}\n\n// NodePath#hub can be null, but it's not a valid weakmap key because it\n// cannot be collected by GC. Use an object, knowing tht it will not be\n// collected anyway. It's not a memory leak because pathsCache.get(nullHub)\n// is itself a weakmap, so its entries can still be collected.\nconst nullHub = Object.freeze({} as const);\n\nexport function getCachedPaths(hub: HubInterface | null, parent: Node) {\n return pathsCache.get(hub ?? nullHub)?.get(parent);\n}\n\nexport function getOrCreateCachedPaths(hub: HubInterface | null, parent: Node) {\n let parents = pathsCache.get(hub ?? nullHub);\n if (!parents) pathsCache.set(hub ?? nullHub, (parents = new WeakMap()));\n\n let paths = parents.get(parent);\n if (!paths) parents.set(parent, (paths = new Map()));\n\n return paths;\n}\n"],"mappings":";;;;;;;;;;;AAKA,IAAIA,UAGH,GAAG,IAAIC,OAAO,CAAC,CAAC;AAACC,OAAA,CAAAC,IAAA,GAAAH,UAAA;AAEX,IAAII,KAA2B,GAAG,IAAIH,OAAO,CAAC,CAAC;AAACC,OAAA,CAAAE,KAAA,GAAAA,KAAA;AAEhD,SAASC,KAAKA,CAAA,EAAG;EACtBC,SAAS,CAAC,CAAC;EACXC,UAAU,CAAC,CAAC;AACd;AAEO,SAASD,SAASA,CAAA,EAAG;EAC1BJ,OAAA,CAAAC,IAAA,GAAAH,UAAU,GAAG,IAAIC,OAAO,CAAC,CAAC;AAC5B;AAEO,SAASM,UAAUA,CAAA,EAAG;EAC3BL,OAAA,CAAAE,KAAA,GAAAA,KAAK,GAAG,IAAIH,OAAO,CAAC,CAAC;AACvB;AAMA,MAAMO,OAAO,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAU,CAAC;AAEnC,SAASC,cAAcA,CAACC,GAAwB,EAAEC,MAAY,EAAE;EAAA,IAAAC,eAAA;EACrE,QAAAA,eAAA,GAAOd,UAAU,CAACe,GAAG,CAACH,GAAG,WAAHA,GAAG,GAAIJ,OAAO,CAAC,qBAA9BM,eAAA,CAAgCC,GAAG,CAACF,MAAM,CAAC;AACpD;AAEO,SAASG,sBAAsBA,CAACJ,GAAwB,EAAEC,MAAY,EAAE;EAC7E,IAAII,OAAO,GAAGjB,UAAU,CAACe,GAAG,CAACH,GAAG,WAAHA,GAAG,GAAIJ,OAAO,CAAC;EAC5C,IAAI,CAACS,OAAO,EAAEjB,UAAU,CAACkB,GAAG,CAACN,GAAG,WAAHA,GAAG,GAAIJ,OAAO,EAAGS,OAAO,GAAG,IAAIhB,OAAO,CAAC,CAAE,CAAC;EAEvE,IAAIkB,KAAK,GAAGF,OAAO,CAACF,GAAG,CAACF,MAAM,CAAC;EAC/B,IAAI,CAACM,KAAK,EAAEF,OAAO,CAACC,GAAG,CAACL,MAAM,EAAGM,KAAK,GAAG,IAAIC,GAAG,CAAC,CAAE,CAAC;EAEpD,OAAOD,KAAK;AACd"}
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
- "use strict";
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 (!(keys != null && keys.length)) return false;
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 _path.default.get({
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
@@ -1 +1 @@
1
- {"version":3,"names":["_path","require","_t","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","exports","default"],"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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,EAAA,GAAAD,OAAA;AAA4C;EAAnCE;AAAY,IAAAD,EAAA;AAMN,MAAME,gBAAgB,CAAc;EACjDC,WAAWA,CACTC,KAAY,EACZC,IAAgC,EAChCC,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,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,EAACC,IAAI,YAAJA,IAAI,CAAEC,MAAM,GAAE,OAAO,KAAK;IAG/B,KAAK,MAAMC,GAAG,IAAIF,IAAI,EAAE;MACtB,IAEEJ,IAAI,CAACM,GAAG,CAAC,EACT;QACA,OAAO,IAAI;MACb;IACF;IAEA,OAAO,KAAK;EACd;EAEAC,MAAMA,CACJP,IAAY,EACZQ,SAA4B,EAC5BF,GAAoB,EACpBG,OA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AAKA,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;AAAC2B,OAAA,CAAAC,OAAA,GAAA3C,gBAAA"}
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,IA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CAACe,UAAU,CAAC,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
- "use strict";
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","exports","default"],"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,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;AAACE,OAAA,CAAAC,OAAA,GAAAV,GAAA"}
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"}