@babel/traverse 7.17.9 → 7.23.3

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 (67) hide show
  1. package/README.md +1 -1
  2. package/lib/cache.js +27 -9
  3. package/lib/cache.js.map +1 -0
  4. package/lib/context.js +9 -31
  5. package/lib/context.js.map +1 -0
  6. package/lib/hub.js +2 -6
  7. package/lib/hub.js.map +1 -0
  8. package/lib/index.js +18 -35
  9. package/lib/index.js.map +1 -0
  10. package/lib/path/ancestry.js +3 -42
  11. package/lib/path/ancestry.js.map +1 -0
  12. package/lib/path/comments.js +23 -11
  13. package/lib/path/comments.js.map +1 -0
  14. package/lib/path/context.js +24 -65
  15. package/lib/path/context.js.map +1 -0
  16. package/lib/path/conversion.js +37 -100
  17. package/lib/path/conversion.js.map +1 -0
  18. package/lib/path/evaluation.js +69 -123
  19. package/lib/path/evaluation.js.map +1 -0
  20. package/lib/path/family.js +5 -76
  21. package/lib/path/family.js.map +1 -0
  22. package/lib/path/index.js +28 -96
  23. package/lib/path/index.js.map +1 -0
  24. package/lib/path/inference/index.js +26 -33
  25. package/lib/path/inference/index.js.map +1 -0
  26. package/lib/path/inference/inferer-reference.js +6 -61
  27. package/lib/path/inference/inferer-reference.js.map +1 -0
  28. package/lib/path/inference/inferers.js +32 -86
  29. package/lib/path/inference/inferers.js.map +1 -0
  30. package/lib/path/inference/util.js +30 -0
  31. package/lib/path/inference/util.js.map +1 -0
  32. package/lib/path/introspection.js +55 -107
  33. package/lib/path/introspection.js.map +1 -0
  34. package/lib/path/lib/hoister.js +2 -37
  35. package/lib/path/lib/hoister.js.map +1 -0
  36. package/lib/path/lib/removal-hooks.js +4 -5
  37. package/lib/path/lib/removal-hooks.js.map +1 -0
  38. package/lib/path/lib/virtual-types-validator.js +161 -0
  39. package/lib/path/lib/virtual-types-validator.js.map +1 -0
  40. package/lib/path/lib/virtual-types.js +20 -224
  41. package/lib/path/lib/virtual-types.js.map +1 -0
  42. package/lib/path/modification.js +17 -61
  43. package/lib/path/modification.js.map +1 -0
  44. package/lib/path/removal.js +9 -22
  45. package/lib/path/removal.js.map +1 -0
  46. package/lib/path/replacement.js +80 -76
  47. package/lib/path/replacement.js.map +1 -0
  48. package/lib/scope/binding.js +20 -12
  49. package/lib/scope/binding.js.map +1 -0
  50. package/lib/scope/index.js +117 -247
  51. package/lib/scope/index.js.map +1 -0
  52. package/lib/scope/lib/renamer.js +41 -74
  53. package/lib/scope/lib/renamer.js.map +1 -0
  54. package/lib/traverse-node.js +10 -11
  55. package/lib/traverse-node.js.map +1 -0
  56. package/lib/types.js +1 -3
  57. package/lib/types.js.map +1 -0
  58. package/lib/visitors.js +62 -83
  59. package/lib/visitors.js.map +1 -0
  60. package/package.json +13 -11
  61. package/lib/path/generated/asserts.js +0 -5
  62. package/lib/path/generated/validators.js +0 -5
  63. package/lib/path/generated/virtual-types.js +0 -3
  64. package/scripts/generators/asserts.js +0 -25
  65. package/scripts/generators/validators.js +0 -42
  66. package/scripts/generators/virtual-types.js +0 -24
  67. package/scripts/package.json +0 -1
package/lib/visitors.js CHANGED
@@ -4,54 +4,53 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.explode = explode;
7
+ exports.isExplodedVisitor = isExplodedVisitor;
7
8
  exports.merge = merge;
8
9
  exports.verify = verify;
9
-
10
- var virtualTypes = require("./path/lib/virtual-types");
11
-
10
+ var virtualTypes = require("./path/lib/virtual-types.js");
11
+ var virtualTypesValidators = require("./path/lib/virtual-types-validator.js");
12
12
  var _t = require("@babel/types");
13
-
14
13
  const {
15
14
  DEPRECATED_KEYS,
15
+ DEPRECATED_ALIASES,
16
16
  FLIPPED_ALIAS_KEYS,
17
- TYPES
17
+ TYPES,
18
+ __internal__deprecationWarning: deprecationWarning
18
19
  } = _t;
19
-
20
+ function isVirtualType(type) {
21
+ return type in virtualTypes;
22
+ }
23
+ function isExplodedVisitor(visitor) {
24
+ return visitor == null ? void 0 : visitor._exploded;
25
+ }
20
26
  function explode(visitor) {
21
- if (visitor._exploded) return visitor;
27
+ if (isExplodedVisitor(visitor)) return visitor;
22
28
  visitor._exploded = true;
23
-
24
29
  for (const nodeType of Object.keys(visitor)) {
25
30
  if (shouldIgnoreKey(nodeType)) continue;
26
31
  const parts = nodeType.split("|");
27
32
  if (parts.length === 1) continue;
28
33
  const fns = visitor[nodeType];
29
34
  delete visitor[nodeType];
30
-
31
35
  for (const part of parts) {
32
36
  visitor[part] = fns;
33
37
  }
34
38
  }
35
-
36
39
  verify(visitor);
37
40
  delete visitor.__esModule;
38
41
  ensureEntranceObjects(visitor);
39
42
  ensureCallbackArrays(visitor);
40
-
41
43
  for (const nodeType of Object.keys(visitor)) {
42
44
  if (shouldIgnoreKey(nodeType)) continue;
43
- const wrapper = virtualTypes[nodeType];
44
- if (!wrapper) continue;
45
+ if (!isVirtualType(nodeType)) continue;
45
46
  const fns = visitor[nodeType];
46
-
47
47
  for (const type of Object.keys(fns)) {
48
- fns[type] = wrapCheck(wrapper, fns[type]);
48
+ fns[type] = wrapCheck(nodeType, fns[type]);
49
49
  }
50
-
51
50
  delete visitor[nodeType];
52
-
53
- if (wrapper.types) {
54
- for (const type of wrapper.types) {
51
+ const types = virtualTypes[nodeType];
52
+ if (types !== null) {
53
+ for (const type of types) {
55
54
  if (visitor[type]) {
56
55
  mergePair(visitor[type], fns);
57
56
  } else {
@@ -62,24 +61,23 @@ function explode(visitor) {
62
61
  mergePair(visitor, fns);
63
62
  }
64
63
  }
65
-
66
64
  for (const nodeType of Object.keys(visitor)) {
67
65
  if (shouldIgnoreKey(nodeType)) continue;
68
- const fns = visitor[nodeType];
69
66
  let aliases = FLIPPED_ALIAS_KEYS[nodeType];
70
- const deprecatedKey = DEPRECATED_KEYS[nodeType];
71
-
72
- if (deprecatedKey) {
73
- console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecatedKey}`);
67
+ if (nodeType in DEPRECATED_KEYS) {
68
+ const deprecatedKey = DEPRECATED_KEYS[nodeType];
69
+ deprecationWarning(nodeType, deprecatedKey, "Visitor ");
74
70
  aliases = [deprecatedKey];
71
+ } else if (nodeType in DEPRECATED_ALIASES) {
72
+ const deprecatedAlias = DEPRECATED_ALIASES[nodeType];
73
+ deprecationWarning(nodeType, deprecatedAlias, "Visitor ");
74
+ aliases = FLIPPED_ALIAS_KEYS[deprecatedAlias];
75
75
  }
76
-
77
76
  if (!aliases) continue;
77
+ const fns = visitor[nodeType];
78
78
  delete visitor[nodeType];
79
-
80
79
  for (const alias of aliases) {
81
80
  const existing = visitor[alias];
82
-
83
81
  if (existing) {
84
82
  mergePair(existing, fns);
85
83
  } else {
@@ -87,35 +85,26 @@ function explode(visitor) {
87
85
  }
88
86
  }
89
87
  }
90
-
91
88
  for (const nodeType of Object.keys(visitor)) {
92
89
  if (shouldIgnoreKey(nodeType)) continue;
93
90
  ensureCallbackArrays(visitor[nodeType]);
94
91
  }
95
-
96
92
  return visitor;
97
93
  }
98
-
99
94
  function verify(visitor) {
100
95
  if (visitor._verified) return;
101
-
102
96
  if (typeof visitor === "function") {
103
97
  throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
104
98
  }
105
-
106
99
  for (const nodeType of Object.keys(visitor)) {
107
100
  if (nodeType === "enter" || nodeType === "exit") {
108
101
  validateVisitorMethods(nodeType, visitor[nodeType]);
109
102
  }
110
-
111
103
  if (shouldIgnoreKey(nodeType)) continue;
112
-
113
104
  if (TYPES.indexOf(nodeType) < 0) {
114
105
  throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
115
106
  }
116
-
117
107
  const visitors = visitor[nodeType];
118
-
119
108
  if (typeof visitors === "object") {
120
109
  for (const visitorKey of Object.keys(visitors)) {
121
110
  if (visitorKey === "enter" || visitorKey === "exit") {
@@ -126,79 +115,67 @@ function verify(visitor) {
126
115
  }
127
116
  }
128
117
  }
129
-
130
118
  visitor._verified = true;
131
119
  }
132
-
133
120
  function validateVisitorMethods(path, val) {
134
121
  const fns = [].concat(val);
135
-
136
122
  for (const fn of fns) {
137
123
  if (typeof fn !== "function") {
138
124
  throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`);
139
125
  }
140
126
  }
141
127
  }
142
-
143
128
  function merge(visitors, states = [], wrapper) {
144
- const rootVisitor = {};
145
-
129
+ const mergedVisitor = {};
146
130
  for (let i = 0; i < visitors.length; i++) {
147
- const visitor = visitors[i];
131
+ const visitor = explode(visitors[i]);
148
132
  const state = states[i];
149
- explode(visitor);
150
-
151
- for (const type of Object.keys(visitor)) {
152
- let visitorType = visitor[type];
153
-
133
+ let topVisitor = visitor;
134
+ if (state || wrapper) {
135
+ topVisitor = wrapWithStateOrWrapper(topVisitor, state, wrapper);
136
+ }
137
+ mergePair(mergedVisitor, topVisitor);
138
+ for (const key of Object.keys(visitor)) {
139
+ if (shouldIgnoreKey(key)) continue;
140
+ let typeVisitor = visitor[key];
154
141
  if (state || wrapper) {
155
- visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
142
+ typeVisitor = wrapWithStateOrWrapper(typeVisitor, state, wrapper);
156
143
  }
157
-
158
- const nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
159
- mergePair(nodeVisitor, visitorType);
144
+ const nodeVisitor = mergedVisitor[key] || (mergedVisitor[key] = {});
145
+ mergePair(nodeVisitor, typeVisitor);
160
146
  }
161
147
  }
162
-
163
- return rootVisitor;
148
+ ;
149
+ return mergedVisitor;
164
150
  }
165
-
166
151
  function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
167
152
  const newVisitor = {};
168
-
169
- for (const key of Object.keys(oldVisitor)) {
170
- let fns = oldVisitor[key];
153
+ for (const phase of ["enter", "exit"]) {
154
+ let fns = oldVisitor[phase];
171
155
  if (!Array.isArray(fns)) continue;
172
156
  fns = fns.map(function (fn) {
173
157
  let newFn = fn;
174
-
175
158
  if (state) {
176
159
  newFn = function (path) {
177
- return fn.call(state, path, state);
160
+ fn.call(state, path, state);
178
161
  };
179
162
  }
180
-
181
163
  if (wrapper) {
182
- newFn = wrapper(state.key, key, newFn);
164
+ newFn = wrapper(state == null ? void 0 : state.key, phase, newFn);
183
165
  }
184
-
185
166
  if (newFn !== fn) {
186
167
  newFn.toString = () => fn.toString();
187
168
  }
188
-
189
169
  return newFn;
190
170
  });
191
- newVisitor[key] = fns;
171
+ newVisitor[phase] = fns;
192
172
  }
193
-
194
173
  return newVisitor;
195
174
  }
196
-
197
175
  function ensureEntranceObjects(obj) {
198
176
  for (const key of Object.keys(obj)) {
199
177
  if (shouldIgnoreKey(key)) continue;
200
178
  const fns = obj[key];
201
-
202
179
  if (typeof fns === "function") {
203
180
  obj[key] = {
204
181
  enter: fns
@@ -206,37 +183,39 @@ function ensureEntranceObjects(obj) {
206
183
  }
207
184
  }
208
185
  }
209
-
210
186
  function ensureCallbackArrays(obj) {
211
187
  if (obj.enter && !Array.isArray(obj.enter)) obj.enter = [obj.enter];
212
188
  if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
213
189
  }
214
-
215
- function wrapCheck(wrapper, fn) {
190
+ function wrapCheck(nodeType, fn) {
191
+ const fnKey = `is${nodeType}`;
192
+ const validator = virtualTypesValidators[fnKey];
216
193
  const newFn = function (path) {
217
- if (wrapper.checkPath(path)) {
194
+ if (validator.call(path)) {
218
195
  return fn.apply(this, arguments);
219
196
  }
220
197
  };
221
-
222
198
  newFn.toString = () => fn.toString();
223
-
224
199
  return newFn;
225
200
  }
226
-
227
201
  function shouldIgnoreKey(key) {
228
202
  if (key[0] === "_") return true;
229
203
  if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
230
-
231
- if (key === "denylist" || key === "noScope" || key === "skipKeys" || key === "blacklist") {
204
+ if (key === "denylist" || key === "noScope" || key === "skipKeys") {
232
205
  return true;
233
206
  }
234
-
207
+ {
208
+ if (key === "blacklist") {
209
+ return true;
210
+ }
211
+ }
235
212
  return false;
236
213
  }
237
-
238
214
  function mergePair(dest, src) {
239
- for (const key of Object.keys(src)) {
240
- dest[key] = [].concat(dest[key] || [], src[key]);
215
+ for (const phase of ["enter", "exit"]) {
216
+ if (!src[phase]) continue;
217
+ dest[phase] = [].concat(dest[phase] || [], src[phase]);
241
218
  }
242
- }
219
+ }
220
+
221
+ //# sourceMappingURL=visitors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["virtualTypes","require","virtualTypesValidators","_t","DEPRECATED_KEYS","DEPRECATED_ALIASES","FLIPPED_ALIAS_KEYS","TYPES","__internal__deprecationWarning","deprecationWarning","isVirtualType","type","isExplodedVisitor","visitor","_exploded","explode","nodeType","Object","keys","shouldIgnoreKey","parts","split","length","fns","part","verify","__esModule","ensureEntranceObjects","ensureCallbackArrays","wrapCheck","types","mergePair","aliases","deprecatedKey","deprecatedAlias","alias","existing","assign","_verified","Error","validateVisitorMethods","indexOf","visitors","visitorKey","path","val","concat","fn","TypeError","merge","states","wrapper","mergedVisitor","i","state","topVisitor","wrapWithStateOrWrapper","key","typeVisitor","nodeVisitor","oldVisitor","newVisitor","phase","Array","isArray","map","newFn","call","toString","obj","enter","exit","fnKey","validator","apply","arguments","dest","src"],"sources":["../src/visitors.ts"],"sourcesContent":["import * as virtualTypes from \"./path/lib/virtual-types.ts\";\nimport * as virtualTypesValidators from \"./path/lib/virtual-types-validator.ts\";\nimport type { Node } from \"@babel/types\";\nimport {\n DEPRECATED_KEYS,\n DEPRECATED_ALIASES,\n FLIPPED_ALIAS_KEYS,\n TYPES,\n __internal__deprecationWarning as deprecationWarning,\n} from \"@babel/types\";\nimport type { ExplodedVisitor, NodePath, Visitor } from \"./index.ts\";\nimport type { ExplVisitNode, VisitNodeFunction, VisitPhase } from \"./types.ts\";\n\ntype VIRTUAL_TYPES = keyof typeof virtualTypes;\nfunction isVirtualType(type: string): type is VIRTUAL_TYPES {\n return type in virtualTypes;\n}\nexport type VisitWrapper<S = any> = (\n stateName: string | undefined,\n visitorType: VisitPhase,\n callback: VisitNodeFunction<S, Node>,\n) => VisitNodeFunction<S, Node>;\n\nexport function isExplodedVisitor(\n visitor: Visitor,\n): visitor is ExplodedVisitor {\n // @ts-expect-error _exploded is not defined on non-exploded Visitor\n return visitor?._exploded;\n}\n\n/**\n * explode() will take a visitor object with all of the various shorthands\n * that we support, and validates & normalizes it into a common format, ready\n * to be used in traversal\n *\n * The various shorthands are:\n * * `Identifier() { ... }` -> `Identifier: { enter() { ... } }`\n * * `\"Identifier|NumericLiteral\": { ... }` -> `Identifier: { ... }, NumericLiteral: { ... }`\n * * Aliases in `@babel/types`: e.g. `Property: { ... }` -> `ObjectProperty: { ... }, ClassProperty: { ... }`\n * Other normalizations are:\n * * Visitors of virtual types are wrapped, so that they are only visited when\n * their dynamic check passes\n * * `enter` and `exit` functions are wrapped in arrays, to ease merging of\n * visitors\n */\nexport function explode<S>(visitor: Visitor<S>): ExplodedVisitor<S> {\n if (isExplodedVisitor(visitor)) return visitor;\n // @ts-expect-error `visitor` will be cast to ExplodedVisitor by this function\n visitor._exploded = true;\n\n // normalise pipes\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n const parts: Array<string> = nodeType.split(\"|\");\n if (parts.length === 1) continue;\n\n const fns = visitor[nodeType];\n delete visitor[nodeType];\n\n for (const part of parts) {\n // @ts-expect-error part will be verified by `verify` later\n visitor[part] = fns;\n }\n }\n\n // verify data structure\n verify(visitor);\n\n // make sure there's no __esModule type since this is because we're using loose mode\n // and it sets __esModule to be enumerable on all modules :(\n // @ts-expect-error ESModule interop\n delete visitor.__esModule;\n\n // ensure visitors are objects\n ensureEntranceObjects(visitor);\n\n // ensure enter/exit callbacks are arrays\n ensureCallbackArrays(visitor);\n\n // add type wrappers\n for (const nodeType of Object.keys(visitor)) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n if (!isVirtualType(nodeType)) continue;\n\n // wrap all the functions\n const fns = visitor[nodeType];\n for (const type of Object.keys(fns)) {\n // @ts-expect-error normalised as VisitNodeObject\n fns[type] = wrapCheck(nodeType, fns[type]);\n }\n\n // clear it from the visitor\n delete visitor[nodeType];\n\n const types = virtualTypes[nodeType];\n if (types !== null) {\n for (const type of types) {\n // merge the visitor if necessary or just put it back in\n if (visitor[type]) {\n mergePair(visitor[type], fns);\n } else {\n // @ts-expect-error Expression produces too complex union\n visitor[type] = fns;\n }\n }\n } else {\n mergePair(visitor, fns);\n }\n }\n\n // add aliases\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n let aliases = FLIPPED_ALIAS_KEYS[nodeType];\n\n if (nodeType in DEPRECATED_KEYS) {\n const deprecatedKey = DEPRECATED_KEYS[nodeType];\n deprecationWarning(nodeType, deprecatedKey, \"Visitor \");\n aliases = [deprecatedKey];\n } else if (nodeType in DEPRECATED_ALIASES) {\n const deprecatedAlias =\n DEPRECATED_ALIASES[nodeType as keyof typeof DEPRECATED_ALIASES];\n deprecationWarning(nodeType, deprecatedAlias, \"Visitor \");\n aliases = FLIPPED_ALIAS_KEYS[deprecatedAlias];\n }\n\n if (!aliases) continue;\n\n const fns = visitor[nodeType];\n // clear it from the visitor\n delete visitor[nodeType];\n\n for (const alias of aliases) {\n const existing = visitor[alias];\n if (existing) {\n mergePair(existing, fns);\n } else {\n // @ts-expect-error Expression produces a union type that is too complex to represent.\n visitor[alias] = { ...fns };\n }\n }\n }\n\n for (const nodeType of Object.keys(visitor)) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n ensureCallbackArrays(\n // @ts-expect-error nodeType must present in visitor after previous validations\n visitor[nodeType],\n );\n }\n\n // @ts-expect-error explosion has been performed\n return visitor as ExplodedVisitor;\n}\n\nexport function verify(visitor: Visitor) {\n // @ts-expect-error _verified is not defined on non-verified Visitor.\n // TODO: unify _verified and _exploded.\n if (visitor._verified) return;\n\n if (typeof visitor === \"function\") {\n throw new Error(\n \"You passed `traverse()` a function when it expected a visitor object, \" +\n \"are you sure you didn't mean `{ enter: Function }`?\",\n );\n }\n\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (nodeType === \"enter\" || nodeType === \"exit\") {\n validateVisitorMethods(nodeType, visitor[nodeType]);\n }\n\n if (shouldIgnoreKey(nodeType)) continue;\n\n if (TYPES.indexOf(nodeType) < 0) {\n throw new Error(\n `You gave us a visitor for the node type ${nodeType} but it's not a valid type`,\n );\n }\n\n const visitors = visitor[nodeType];\n if (typeof visitors === \"object\") {\n for (const visitorKey of Object.keys(visitors)) {\n if (visitorKey === \"enter\" || visitorKey === \"exit\") {\n // verify that it just contains functions\n validateVisitorMethods(\n `${nodeType}.${visitorKey}`,\n visitors[visitorKey],\n );\n } else {\n throw new Error(\n \"You passed `traverse()` a visitor object with the property \" +\n `${nodeType} that has the invalid property ${visitorKey}`,\n );\n }\n }\n }\n }\n\n // @ts-expect-error _verified is not defined on non-verified Visitor.\n // TODO: unify _verified and _exploded.\n visitor._verified = true;\n}\n\nfunction validateVisitorMethods(\n path: string,\n val: any,\n): asserts val is Function | Function[] {\n const fns = [].concat(val);\n for (const fn of fns) {\n if (typeof fn !== \"function\") {\n throw new TypeError(\n `Non-function found defined in ${path} with type ${typeof fn}`,\n );\n }\n }\n}\n\nexport function merge<State>(\n visitors: Visitor<State>[],\n): ExplodedVisitor<State>;\nexport function merge(\n visitors: Visitor<unknown>[],\n states?: any[],\n wrapper?: Function | null,\n): ExplodedVisitor<unknown>;\nexport function merge(\n visitors: any[],\n states: any[] = [],\n wrapper?: VisitWrapper | null,\n): ExplodedVisitor {\n // @ts-expect-error don't bother with internal flags so it can work with earlier @babel/core validations\n const mergedVisitor: ExplodedVisitor = {};\n\n for (let i = 0; i < visitors.length; i++) {\n const visitor = explode(visitors[i]);\n const state = states[i];\n\n let topVisitor: ExplVisitNode<unknown, Node> = visitor;\n if (state || wrapper) {\n topVisitor = wrapWithStateOrWrapper(topVisitor, state, wrapper);\n }\n mergePair(mergedVisitor, topVisitor);\n\n for (const key of Object.keys(visitor) as (keyof ExplodedVisitor)[]) {\n if (shouldIgnoreKey(key)) continue;\n\n let typeVisitor = visitor[key];\n\n // if we have state or wrapper then overload the callbacks to take it\n if (state || wrapper) {\n typeVisitor = wrapWithStateOrWrapper(typeVisitor, state, wrapper);\n }\n\n const nodeVisitor = (mergedVisitor[key] ||= {});\n mergePair(nodeVisitor, typeVisitor);\n }\n }\n\n if (process.env.BABEL_8_BREAKING) {\n return {\n ...mergedVisitor,\n _exploded: true,\n _verified: true,\n };\n }\n\n return mergedVisitor;\n}\n\nfunction wrapWithStateOrWrapper<State>(\n oldVisitor: ExplVisitNode<State, Node>,\n state: State | null,\n wrapper?: VisitWrapper<State> | null,\n): ExplVisitNode<State, Node> {\n const newVisitor: ExplVisitNode<State, Node> = {};\n\n for (const phase of [\"enter\", \"exit\"] as VisitPhase[]) {\n let fns = oldVisitor[phase];\n\n // not an enter/exit array of callbacks\n if (!Array.isArray(fns)) continue;\n\n fns = fns.map(function (fn) {\n let newFn = fn;\n\n if (state) {\n newFn = function (path: NodePath) {\n fn.call(state, path, state);\n };\n }\n\n if (wrapper) {\n // @ts-expect-error Fixme: actually PluginPass.key (aka pluginAlias)?\n newFn = wrapper(state?.key, phase, newFn);\n }\n\n // Override toString in case this function is printed, we want to print the wrapped function, same as we do in `wrapCheck`\n if (newFn !== fn) {\n newFn.toString = () => fn.toString();\n }\n\n return newFn;\n });\n\n newVisitor[phase] = fns;\n }\n\n return newVisitor;\n}\n\nfunction ensureEntranceObjects(obj: Visitor) {\n for (const key of Object.keys(obj) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(key)) continue;\n\n const fns = obj[key];\n if (typeof fns === \"function\") {\n // @ts-expect-error: Expression produces a union type that is too complex to represent.\n obj[key] = { enter: fns };\n }\n }\n}\n\nfunction ensureCallbackArrays(obj: Visitor) {\n if (obj.enter && !Array.isArray(obj.enter)) obj.enter = [obj.enter];\n if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];\n}\n\nfunction wrapCheck(nodeType: VIRTUAL_TYPES, fn: Function) {\n const fnKey = `is${nodeType}`;\n // @ts-expect-error we know virtualTypesValidators will contain `fnKey`, but TS doesn't\n const validator = virtualTypesValidators[fnKey];\n const newFn = function (this: unknown, path: NodePath) {\n if (validator.call(path)) {\n return fn.apply(this, arguments);\n }\n };\n newFn.toString = () => fn.toString();\n return newFn;\n}\n\nfunction shouldIgnoreKey(\n key: string,\n): key is\n | `_${string}`\n | \"enter\"\n | \"exit\"\n | \"shouldSkip\"\n | \"denylist\"\n | \"noScope\"\n | \"skipKeys\"\n | \"blacklist\" {\n // internal/hidden key\n if (key[0] === \"_\") return true;\n\n // ignore function keys\n if (key === \"enter\" || key === \"exit\" || key === \"shouldSkip\") return true;\n\n // ignore other options\n if (key === \"denylist\" || key === \"noScope\" || key === \"skipKeys\") {\n return true;\n }\n\n if (!process.env.BABEL_8_BREAKING) {\n if (key === \"blacklist\") {\n return true;\n }\n }\n\n return false;\n}\n\n/*\nfunction mergePair(\n dest: ExplVisitNode<unknown, Node>,\n src: ExplVisitNode<unknown, Node>,\n);\n*/\nfunction mergePair(dest: any, src: any) {\n for (const phase of [\"enter\", \"exit\"] as VisitPhase[]) {\n if (!src[phase]) continue;\n dest[phase] = [].concat(dest[phase] || [], src[phase]);\n }\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AAEA,IAAAE,EAAA,GAAAF,OAAA;AAMsB;EALpBG,eAAe;EACfC,kBAAkB;EAClBC,kBAAkB;EAClBC,KAAK;EACLC,8BAA8B,EAAIC;AAAkB,IAAAN,EAAA;AAMtD,SAASO,aAAaA,CAACC,IAAY,EAAyB;EAC1D,OAAOA,IAAI,IAAIX,YAAY;AAC7B;AAOO,SAASY,iBAAiBA,CAC/BC,OAAgB,EACY;EAE5B,OAAOA,OAAO,oBAAPA,OAAO,CAAEC,SAAS;AAC3B;AAiBO,SAASC,OAAOA,CAAIF,OAAmB,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,IAAIA,GAAG,KAAK,OAAO,IAAIA,GAAG,KAAK,MAAM,IAAIA,GAAG,KAAK,YAAY,EAAE,OAAO,IAAI;EAG1E,IAAIA,GAAG,KAAK,UAAU,IAAIA,GAAG,KAAK,SAAS,IAAIA,GAAG,KAAK,UAAU,EAAE;IACjE,OAAO,IAAI;EACb;EAEmC;IACjC,IAAIA,GAAG,KAAK,WAAW,EAAE;MACvB,OAAO,IAAI;IACb;EACF;EAEA,OAAO,KAAK;AACd;AAQA,SAAS1B,SAASA,CAAC6C,IAAS,EAAEC,GAAQ,EAAE;EACtC,KAAK,MAAMf,KAAK,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAkB;IACrD,IAAI,CAACe,GAAG,CAACf,KAAK,CAAC,EAAE;IACjBc,IAAI,CAACd,KAAK,CAAC,GAAG,EAAE,CAAChB,MAAM,CAAC8B,IAAI,CAACd,KAAK,CAAC,IAAI,EAAE,EAAEe,GAAG,CAACf,KAAK,CAAC,CAAC;EACxD;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.17.9",
3
+ "version": "7.23.3",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "The Babel Team (https://babel.dev/team)",
6
6
  "homepage": "https://babel.dev/docs/en/next/babel-traverse",
@@ -16,21 +16,23 @@
16
16
  },
17
17
  "main": "./lib/index.js",
18
18
  "dependencies": {
19
- "@babel/code-frame": "^7.16.7",
20
- "@babel/generator": "^7.17.9",
21
- "@babel/helper-environment-visitor": "^7.16.7",
22
- "@babel/helper-function-name": "^7.17.9",
23
- "@babel/helper-hoist-variables": "^7.16.7",
24
- "@babel/helper-split-export-declaration": "^7.16.7",
25
- "@babel/parser": "^7.17.9",
26
- "@babel/types": "^7.17.0",
19
+ "@babel/code-frame": "^7.22.13",
20
+ "@babel/generator": "^7.23.3",
21
+ "@babel/helper-environment-visitor": "^7.22.20",
22
+ "@babel/helper-function-name": "^7.23.0",
23
+ "@babel/helper-hoist-variables": "^7.22.5",
24
+ "@babel/helper-split-export-declaration": "^7.22.6",
25
+ "@babel/parser": "^7.23.3",
26
+ "@babel/types": "^7.23.3",
27
27
  "debug": "^4.1.0",
28
28
  "globals": "^11.1.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@babel/helper-plugin-test-runner": "^7.16.7"
31
+ "@babel/core": "^7.23.3",
32
+ "@babel/helper-plugin-test-runner": "^7.22.5"
32
33
  },
33
34
  "engines": {
34
35
  "node": ">=6.9.0"
35
- }
36
+ },
37
+ "type": "commonjs"
36
38
  }
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- var t = require("@babel/types");
4
-
5
- var _index = require("../index");
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- var t = require("@babel/types");
4
-
5
- var _index = require("../index");
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- var t = require("@babel/types");
@@ -1,25 +0,0 @@
1
- import t from "@babel/types";
2
-
3
- export default function generateAsserts() {
4
- let output = `/*
5
- * This file is auto-generated! Do not modify it directly.
6
- * To re-generate run 'make build'
7
- */
8
- import * as t from "@babel/types";
9
- import NodePath from "../index";
10
-
11
-
12
- export interface NodePathAssetions {`;
13
-
14
- for (const type of [...t.TYPES].sort()) {
15
- output += `
16
- assert${type}(
17
- opts?: object,
18
- ): asserts this is NodePath<t.${type}>;`;
19
- }
20
-
21
- output += `
22
- }`;
23
-
24
- return output;
25
- }
@@ -1,42 +0,0 @@
1
- import t from "@babel/types";
2
- import virtualTypes from "../../lib/path/lib/virtual-types.js";
3
-
4
- export default function generateValidators() {
5
- let output = `/*
6
- * This file is auto-generated! Do not modify it directly.
7
- * To re-generate run 'make build'
8
- */
9
- import * as t from "@babel/types";
10
- import NodePath from "../index";
11
- import type { VirtualTypeAliases } from "./virtual-types";
12
-
13
- export interface NodePathValidators {
14
- `;
15
-
16
- for (const type of [...t.TYPES].sort()) {
17
- output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
18
- }
19
-
20
- for (const type of Object.keys(virtualTypes)) {
21
- const { types } = virtualTypes[type];
22
- if (type[0] === "_") continue;
23
- if (t.NODE_FIELDS[type] || t.FLIPPED_ALIAS_KEYS[type]) {
24
- output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
25
- } else if (types /* in VirtualTypeAliases */) {
26
- output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`;
27
- } else {
28
- // if it don't have types, then VirtualTypeAliases[type] is t.Node
29
- // which TS marked as always true
30
- // eg. if (path.isBlockScope()) return;
31
- // path resolved to `never` here
32
- // so we have to return boolean instead of this is NodePath<t.Node> here
33
- output += `is${type}(opts?: object): boolean;`;
34
- }
35
- }
36
-
37
- output += `
38
- }
39
- `;
40
-
41
- return output;
42
- }
@@ -1,24 +0,0 @@
1
- import virtualTypes from "../../lib/path/lib/virtual-types.js";
2
-
3
- export default function generateValidators() {
4
- let output = `/*
5
- * This file is auto-generated! Do not modify it directly.
6
- * To re-generate run 'make build'
7
- */
8
- import * as t from "@babel/types";
9
-
10
- export interface VirtualTypeAliases {
11
- `;
12
-
13
- for (const type of Object.keys(virtualTypes)) {
14
- output += ` ${type}: ${(virtualTypes[type].types || ["Node"])
15
- .map(t => `t.${t}`)
16
- .join(" | ")};`;
17
- }
18
-
19
- output += `
20
- }
21
- `;
22
-
23
- return output;
24
- }
@@ -1 +0,0 @@
1
- { "type": "module" }