@babel/traverse 7.1.0 → 7.23.2

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 (61) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/lib/cache.js +27 -7
  4. package/lib/cache.js.map +1 -0
  5. package/lib/context.js +22 -59
  6. package/lib/context.js.map +1 -0
  7. package/lib/hub.js +2 -6
  8. package/lib/hub.js.map +1 -0
  9. package/lib/index.js +42 -77
  10. package/lib/index.js.map +1 -0
  11. package/lib/path/ancestry.js +15 -62
  12. package/lib/path/ancestry.js.map +1 -0
  13. package/lib/path/comments.js +31 -24
  14. package/lib/path/comments.js.map +1 -0
  15. package/lib/path/context.js +68 -91
  16. package/lib/path/context.js.map +1 -0
  17. package/lib/path/conversion.js +275 -273
  18. package/lib/path/conversion.js.map +1 -0
  19. package/lib/path/evaluation.js +84 -149
  20. package/lib/path/evaluation.js.map +1 -0
  21. package/lib/path/family.js +189 -94
  22. package/lib/path/family.js.map +1 -0
  23. package/lib/path/index.js +106 -132
  24. package/lib/path/index.js.map +1 -0
  25. package/lib/path/inference/index.js +81 -64
  26. package/lib/path/inference/index.js.map +1 -0
  27. package/lib/path/inference/inferer-reference.js +22 -52
  28. package/lib/path/inference/inferer-reference.js.map +1 -0
  29. package/lib/path/inference/inferers.js +110 -125
  30. package/lib/path/inference/inferers.js.map +1 -0
  31. package/lib/path/inference/util.js +30 -0
  32. package/lib/path/inference/util.js.map +1 -0
  33. package/lib/path/introspection.js +182 -168
  34. package/lib/path/introspection.js.map +1 -0
  35. package/lib/path/lib/hoister.js +37 -54
  36. package/lib/path/lib/hoister.js.map +1 -0
  37. package/lib/path/lib/removal-hooks.js +4 -4
  38. package/lib/path/lib/removal-hooks.js.map +1 -0
  39. package/lib/path/lib/virtual-types-validator.js +161 -0
  40. package/lib/path/lib/virtual-types-validator.js.map +1 -0
  41. package/lib/path/lib/virtual-types.js +21 -189
  42. package/lib/path/lib/virtual-types.js.map +1 -0
  43. package/lib/path/modification.js +103 -98
  44. package/lib/path/modification.js.map +1 -0
  45. package/lib/path/removal.js +18 -23
  46. package/lib/path/removal.js.map +1 -0
  47. package/lib/path/replacement.js +91 -144
  48. package/lib/path/replacement.js.map +1 -0
  49. package/lib/scope/binding.js +28 -16
  50. package/lib/scope/binding.js.map +1 -0
  51. package/lib/scope/index.js +407 -414
  52. package/lib/scope/index.js.map +1 -0
  53. package/lib/scope/lib/renamer.js +45 -70
  54. package/lib/scope/lib/renamer.js.map +1 -0
  55. package/lib/traverse-node.js +29 -0
  56. package/lib/traverse-node.js.map +1 -0
  57. package/lib/types.js +3 -0
  58. package/lib/types.js.map +1 -0
  59. package/lib/visitors.js +77 -113
  60. package/lib/visitors.js.map +1 -0
  61. package/package.json +28 -17
@@ -3,60 +3,39 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.findParent = findParent;
7
6
  exports.find = find;
7
+ exports.findParent = findParent;
8
+ exports.getAncestry = getAncestry;
9
+ exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
10
+ exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
8
11
  exports.getFunctionParent = getFunctionParent;
9
12
  exports.getStatementParent = getStatementParent;
10
- exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
11
- exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
12
- exports.getAncestry = getAncestry;
13
+ exports.inType = inType;
13
14
  exports.isAncestor = isAncestor;
14
15
  exports.isDescendant = isDescendant;
15
- exports.inType = inType;
16
-
17
- function t() {
18
- const data = _interopRequireWildcard(require("@babel/types"));
19
-
20
- t = function () {
21
- return data;
22
- };
23
-
24
- return data;
25
- }
26
-
27
- var _index = _interopRequireDefault(require("./index"));
28
-
29
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
32
-
16
+ var _t = require("@babel/types");
17
+ const {
18
+ VISITOR_KEYS
19
+ } = _t;
33
20
  function findParent(callback) {
34
21
  let path = this;
35
-
36
22
  while (path = path.parentPath) {
37
23
  if (callback(path)) return path;
38
24
  }
39
-
40
25
  return null;
41
26
  }
42
-
43
27
  function find(callback) {
44
28
  let path = this;
45
-
46
29
  do {
47
30
  if (callback(path)) return path;
48
31
  } while (path = path.parentPath);
49
-
50
32
  return null;
51
33
  }
52
-
53
34
  function getFunctionParent() {
54
35
  return this.findParent(p => p.isFunction());
55
36
  }
56
-
57
37
  function getStatementParent() {
58
38
  let path = this;
59
-
60
39
  do {
61
40
  if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
62
41
  break;
@@ -64,85 +43,66 @@ function getStatementParent() {
64
43
  path = path.parentPath;
65
44
  }
66
45
  } while (path);
67
-
68
46
  if (path && (path.isProgram() || path.isFile())) {
69
47
  throw new Error("File/Program node, we can't possibly find a statement parent to this");
70
48
  }
71
-
72
49
  return path;
73
50
  }
74
-
75
51
  function getEarliestCommonAncestorFrom(paths) {
76
52
  return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
77
53
  let earliest;
78
- const keys = t().VISITOR_KEYS[deepest.type];
79
-
54
+ const keys = VISITOR_KEYS[deepest.type];
80
55
  for (const ancestry of ancestries) {
81
56
  const path = ancestry[i + 1];
82
-
83
57
  if (!earliest) {
84
58
  earliest = path;
85
59
  continue;
86
60
  }
87
-
88
61
  if (path.listKey && earliest.listKey === path.listKey) {
89
62
  if (path.key < earliest.key) {
90
63
  earliest = path;
91
64
  continue;
92
65
  }
93
66
  }
94
-
95
67
  const earliestKeyIndex = keys.indexOf(earliest.parentKey);
96
68
  const currentKeyIndex = keys.indexOf(path.parentKey);
97
-
98
69
  if (earliestKeyIndex > currentKeyIndex) {
99
70
  earliest = path;
100
71
  }
101
72
  }
102
-
103
73
  return earliest;
104
74
  });
105
75
  }
106
-
107
76
  function getDeepestCommonAncestorFrom(paths, filter) {
108
77
  if (!paths.length) {
109
78
  return this;
110
79
  }
111
-
112
80
  if (paths.length === 1) {
113
81
  return paths[0];
114
82
  }
115
-
116
83
  let minDepth = Infinity;
117
84
  let lastCommonIndex, lastCommon;
118
85
  const ancestries = paths.map(path => {
119
86
  const ancestry = [];
120
-
121
87
  do {
122
88
  ancestry.unshift(path);
123
89
  } while ((path = path.parentPath) && path !== this);
124
-
125
90
  if (ancestry.length < minDepth) {
126
91
  minDepth = ancestry.length;
127
92
  }
128
-
129
93
  return ancestry;
130
94
  });
131
95
  const first = ancestries[0];
132
-
133
96
  depthLoop: for (let i = 0; i < minDepth; i++) {
134
97
  const shouldMatch = first[i];
135
-
136
98
  for (const ancestry of ancestries) {
137
99
  if (ancestry[i] !== shouldMatch) {
138
100
  break depthLoop;
139
101
  }
140
102
  }
141
-
142
103
  lastCommonIndex = i;
143
104
  lastCommon = shouldMatch;
144
105
  }
145
-
146
106
  if (lastCommon) {
147
107
  if (filter) {
148
108
  return filter(lastCommon, lastCommonIndex, ancestries);
@@ -153,36 +113,29 @@ function getDeepestCommonAncestorFrom(paths, filter) {
153
113
  throw new Error("Couldn't find intersection");
154
114
  }
155
115
  }
156
-
157
116
  function getAncestry() {
158
117
  let path = this;
159
118
  const paths = [];
160
-
161
119
  do {
162
120
  paths.push(path);
163
121
  } while (path = path.parentPath);
164
-
165
122
  return paths;
166
123
  }
167
-
168
124
  function isAncestor(maybeDescendant) {
169
125
  return maybeDescendant.isDescendant(this);
170
126
  }
171
-
172
127
  function isDescendant(maybeAncestor) {
173
128
  return !!this.findParent(parent => parent === maybeAncestor);
174
129
  }
175
-
176
- function inType() {
130
+ function inType(...candidateTypes) {
177
131
  let path = this;
178
-
179
132
  while (path) {
180
- for (const type of arguments) {
133
+ for (const type of candidateTypes) {
181
134
  if (path.node.type === type) return true;
182
135
  }
183
-
184
136
  path = path.parentPath;
185
137
  }
186
-
187
138
  return false;
188
- }
139
+ }
140
+
141
+ //# sourceMappingURL=ancestry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_t","require","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.ts\";\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);\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,IAAAA,EAAA,GAAAC,OAAA;AAA4C;EAAnCC;AAAY,IAAAF,EAAA;AAWd,SAASG,UAAUA,CAExBC,QAAq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AAiB,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"}
@@ -3,22 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
7
6
  exports.addComment = addComment;
8
7
  exports.addComments = addComments;
9
-
10
- function t() {
11
- const data = _interopRequireWildcard(require("@babel/types"));
12
-
13
- t = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
19
-
20
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
21
-
8
+ exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
9
+ var _t = require("@babel/types");
10
+ const {
11
+ addComment: _addComment,
12
+ addComments: _addComments
13
+ } = _t;
22
14
  function shareCommentsWithSiblings() {
23
15
  if (typeof this.key === "string") return;
24
16
  const node = this.node;
@@ -30,18 +22,33 @@ function shareCommentsWithSiblings() {
30
22
  const next = this.getSibling(this.key + 1);
31
23
  const hasPrev = Boolean(prev.node);
32
24
  const hasNext = Boolean(next.node);
33
-
34
- if (hasPrev && hasNext) {} else if (hasPrev) {
35
- prev.addComments("trailing", trailing);
36
- } else if (hasNext) {
37
- next.addComments("leading", leading);
25
+ if (hasPrev) {
26
+ if (leading) {
27
+ prev.addComments("trailing", removeIfExisting(leading, prev.node.trailingComments));
28
+ }
29
+ if (trailing && !hasNext) prev.addComments("trailing", trailing);
30
+ }
31
+ if (hasNext) {
32
+ if (trailing) {
33
+ next.addComments("leading", removeIfExisting(trailing, next.node.leadingComments));
34
+ }
35
+ if (leading && !hasPrev) next.addComments("leading", leading);
38
36
  }
39
37
  }
40
-
38
+ function removeIfExisting(list, toRemove) {
39
+ if (!toRemove) return list;
40
+ let lastFoundIndex = -1;
41
+ return list.filter(el => {
42
+ const i = toRemove.indexOf(el, lastFoundIndex);
43
+ if (i === -1) return true;
44
+ lastFoundIndex = i;
45
+ });
46
+ }
41
47
  function addComment(type, content, line) {
42
- t().addComment(this.node, type, content, line);
48
+ _addComment(this.node, type, content, line);
43
49
  }
44
-
45
50
  function addComments(type, comments) {
46
- t().addComments(this.node, type, comments);
47
- }
51
+ _addComments(this.node, type, comments);
52
+ }
53
+
54
+ //# sourceMappingURL=comments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_t","require","addComment","_addComment","addComments","_addComments","shareCommentsWithSiblings","key","node","trailing","trailingComments","leading","leadingComments","prev","getSibling","next","hasPrev","Boolean","hasNext","removeIfExisting","list","toRemove","lastFoundIndex","filter","el","i","indexOf","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.ts\";\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\n if (hasPrev) {\n if (leading) {\n prev.addComments(\n \"trailing\",\n removeIfExisting(leading, prev.node.trailingComments),\n );\n }\n if (trailing && !hasNext) prev.addComments(\"trailing\", trailing);\n }\n if (hasNext) {\n if (trailing) {\n next.addComments(\n \"leading\",\n removeIfExisting(trailing, next.node.leadingComments),\n );\n }\n if (leading && !hasPrev) next.addComments(\"leading\", leading);\n }\n}\n\nfunction removeIfExisting<T>(list: T[], toRemove?: T[]): T[] {\n if (!toRemove) return list;\n let lastFoundIndex = -1;\n return list.filter(el => {\n const i = toRemove.indexOf(el, lastFoundIndex);\n if (i === -1) return true;\n lastFoundIndex = i;\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,IAAAA,EAAA,GAAAC,OAAA;AAGsB;EAFpBC,UAAU,EAAIC,WAAW;EACzBC,WAAW,EAAIC;AAAY,IAAAL,EAAA;AAOtB,SAASM,yBAAyBA,CAAA,EAAiB;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,O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,YAAY,CAAC,IAAI,CAACG,IAAI,EAAEmB,IAAI,EAAEG,QAAQ,CAAC;AACzC"}
@@ -3,243 +3,220 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.call = call;
7
6
  exports._call = _call;
8
- exports.isBlacklisted = isBlacklisted;
9
- exports.visit = visit;
10
- exports.skip = skip;
11
- exports.skipKey = skipKey;
12
- exports.stop = stop;
13
- exports.setScope = setScope;
14
- exports.setContext = setContext;
15
- exports.resync = resync;
16
- exports._resyncParent = _resyncParent;
7
+ exports._getQueueContexts = _getQueueContexts;
17
8
  exports._resyncKey = _resyncKey;
18
9
  exports._resyncList = _resyncList;
10
+ exports._resyncParent = _resyncParent;
19
11
  exports._resyncRemoved = _resyncRemoved;
12
+ exports.call = call;
13
+ exports.isBlacklisted = exports.isDenylisted = isDenylisted;
20
14
  exports.popContext = popContext;
21
15
  exports.pushContext = pushContext;
22
- exports.setup = setup;
23
- exports.setKey = setKey;
24
16
  exports.requeue = requeue;
25
- exports._getQueueContexts = _getQueueContexts;
26
-
27
- var _index = _interopRequireDefault(require("../index"));
28
-
29
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
17
+ exports.resync = resync;
18
+ exports.setContext = setContext;
19
+ exports.setKey = setKey;
20
+ exports.setScope = setScope;
21
+ exports.setup = setup;
22
+ exports.skip = skip;
23
+ exports.skipKey = skipKey;
24
+ exports.stop = stop;
25
+ exports.visit = visit;
26
+ var _traverseNode = require("../traverse-node.js");
27
+ var _index = require("./index.js");
31
28
  function call(key) {
32
29
  const opts = this.opts;
33
30
  this.debug(key);
34
-
35
31
  if (this.node) {
36
32
  if (this._call(opts[key])) return true;
37
33
  }
38
-
39
34
  if (this.node) {
40
- return this._call(opts[this.node.type] && opts[this.node.type][key]);
35
+ var _opts$this$node$type;
36
+ return this._call((_opts$this$node$type = opts[this.node.type]) == null ? void 0 : _opts$this$node$type[key]);
41
37
  }
42
-
43
38
  return false;
44
39
  }
45
-
46
40
  function _call(fns) {
47
41
  if (!fns) return false;
48
-
49
42
  for (const fn of fns) {
50
43
  if (!fn) continue;
51
44
  const node = this.node;
52
45
  if (!node) return true;
53
46
  const ret = fn.call(this.state, this, this.state);
54
-
55
47
  if (ret && typeof ret === "object" && typeof ret.then === "function") {
56
- throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support.` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
48
+ throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
57
49
  }
58
-
59
50
  if (ret) {
60
51
  throw new Error(`Unexpected return value from visitor method ${fn}`);
61
52
  }
62
-
63
53
  if (this.node !== node) return true;
64
- if (this.shouldStop || this.shouldSkip || this.removed) return true;
54
+ if (this._traverseFlags > 0) return true;
65
55
  }
66
-
67
56
  return false;
68
57
  }
69
-
70
- function isBlacklisted() {
71
- const blacklist = this.opts.blacklist;
72
- return blacklist && blacklist.indexOf(this.node.type) > -1;
58
+ function isDenylisted() {
59
+ var _this$opts$denylist;
60
+ const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
61
+ return denylist && denylist.indexOf(this.node.type) > -1;
62
+ }
63
+ function restoreContext(path, context) {
64
+ if (path.context !== context) {
65
+ path.context = context;
66
+ path.state = context.state;
67
+ path.opts = context.opts;
68
+ }
73
69
  }
74
-
75
70
  function visit() {
71
+ var _this$opts$shouldSkip, _this$opts;
76
72
  if (!this.node) {
77
73
  return false;
78
74
  }
79
-
80
- if (this.isBlacklisted()) {
75
+ if (this.isDenylisted()) {
81
76
  return false;
82
77
  }
83
-
84
- if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {
78
+ if ((_this$opts$shouldSkip = (_this$opts = this.opts).shouldSkip) != null && _this$opts$shouldSkip.call(_this$opts, this)) {
85
79
  return false;
86
80
  }
87
-
88
- if (this.call("enter") || this.shouldSkip) {
81
+ const currentContext = this.context;
82
+ if (this.shouldSkip || this.call("enter")) {
89
83
  this.debug("Skip...");
90
84
  return this.shouldStop;
91
85
  }
92
-
86
+ restoreContext(this, currentContext);
93
87
  this.debug("Recursing into...");
94
-
95
- _index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
96
-
88
+ this.shouldStop = (0, _traverseNode.traverseNode)(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
89
+ restoreContext(this, currentContext);
97
90
  this.call("exit");
98
91
  return this.shouldStop;
99
92
  }
100
-
101
93
  function skip() {
102
94
  this.shouldSkip = true;
103
95
  }
104
-
105
96
  function skipKey(key) {
97
+ if (this.skipKeys == null) {
98
+ this.skipKeys = {};
99
+ }
106
100
  this.skipKeys[key] = true;
107
101
  }
108
-
109
102
  function stop() {
110
- this.shouldStop = true;
111
- this.shouldSkip = true;
103
+ this._traverseFlags |= _index.SHOULD_SKIP | _index.SHOULD_STOP;
112
104
  }
113
-
114
105
  function setScope() {
115
- if (this.opts && this.opts.noScope) return;
106
+ var _this$opts2, _this$scope;
107
+ if ((_this$opts2 = this.opts) != null && _this$opts2.noScope) return;
116
108
  let path = this.parentPath;
109
+ if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
110
+ path = path.parentPath;
111
+ }
117
112
  let target;
118
-
119
113
  while (path && !target) {
120
- if (path.opts && path.opts.noScope) return;
114
+ var _path$opts;
115
+ if ((_path$opts = path.opts) != null && _path$opts.noScope) return;
121
116
  target = path.scope;
122
117
  path = path.parentPath;
123
118
  }
124
-
125
119
  this.scope = this.getScope(target);
126
- if (this.scope) this.scope.init();
120
+ (_this$scope = this.scope) == null ? void 0 : _this$scope.init();
127
121
  }
128
-
129
122
  function setContext(context) {
130
- this.shouldSkip = false;
131
- this.shouldStop = false;
132
- this.removed = false;
133
- this.skipKeys = {};
134
-
123
+ if (this.skipKeys != null) {
124
+ this.skipKeys = {};
125
+ }
126
+ this._traverseFlags = 0;
135
127
  if (context) {
136
128
  this.context = context;
137
129
  this.state = context.state;
138
130
  this.opts = context.opts;
139
131
  }
140
-
141
132
  this.setScope();
142
133
  return this;
143
134
  }
144
-
145
135
  function resync() {
146
136
  if (this.removed) return;
147
-
148
137
  this._resyncParent();
149
-
150
138
  this._resyncList();
151
-
152
139
  this._resyncKey();
153
140
  }
154
-
155
141
  function _resyncParent() {
156
142
  if (this.parentPath) {
157
143
  this.parent = this.parentPath.node;
158
144
  }
159
145
  }
160
-
161
146
  function _resyncKey() {
162
147
  if (!this.container) return;
163
- if (this.node === this.container[this.key]) return;
164
-
148
+ if (this.node === this.container[this.key]) {
149
+ return;
150
+ }
165
151
  if (Array.isArray(this.container)) {
166
152
  for (let i = 0; i < this.container.length; i++) {
167
153
  if (this.container[i] === this.node) {
168
- return this.setKey(i);
154
+ this.setKey(i);
155
+ return;
169
156
  }
170
157
  }
171
158
  } else {
172
- for (const key in this.container) {
159
+ for (const key of Object.keys(this.container)) {
173
160
  if (this.container[key] === this.node) {
174
- return this.setKey(key);
161
+ this.setKey(key);
162
+ return;
175
163
  }
176
164
  }
177
165
  }
178
-
179
166
  this.key = null;
180
167
  }
181
-
182
168
  function _resyncList() {
183
169
  if (!this.parent || !this.inList) return;
184
170
  const newContainer = this.parent[this.listKey];
185
171
  if (this.container === newContainer) return;
186
172
  this.container = newContainer || null;
187
173
  }
188
-
189
174
  function _resyncRemoved() {
190
175
  if (this.key == null || !this.container || this.container[this.key] !== this.node) {
191
176
  this._markRemoved();
192
177
  }
193
178
  }
194
-
195
179
  function popContext() {
196
180
  this.contexts.pop();
197
-
198
181
  if (this.contexts.length > 0) {
199
182
  this.setContext(this.contexts[this.contexts.length - 1]);
200
183
  } else {
201
184
  this.setContext(undefined);
202
185
  }
203
186
  }
204
-
205
187
  function pushContext(context) {
206
188
  this.contexts.push(context);
207
189
  this.setContext(context);
208
190
  }
209
-
210
191
  function setup(parentPath, container, listKey, key) {
211
- this.inList = !!listKey;
212
192
  this.listKey = listKey;
213
- this.parentKey = listKey || key;
214
193
  this.container = container;
215
194
  this.parentPath = parentPath || this.parentPath;
216
195
  this.setKey(key);
217
196
  }
218
-
219
197
  function setKey(key) {
198
+ var _this$node;
220
199
  this.key = key;
221
200
  this.node = this.container[this.key];
222
- this.type = this.node && this.node.type;
201
+ this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
223
202
  }
224
-
225
203
  function requeue(pathToQueue = this) {
226
204
  if (pathToQueue.removed) return;
205
+ ;
227
206
  const contexts = this.contexts;
228
-
229
207
  for (const context of contexts) {
230
208
  context.maybeQueue(pathToQueue);
231
209
  }
232
210
  }
233
-
234
211
  function _getQueueContexts() {
235
212
  let path = this;
236
213
  let contexts = this.contexts;
237
-
238
214
  while (!contexts.length) {
239
215
  path = path.parentPath;
240
216
  if (!path) break;
241
217
  contexts = path.contexts;
242
218
  }
243
-
244
219
  return contexts;
245
- }
220
+ }
221
+
222
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_traverseNode","require","_index","call","key","opts","debug","node","_call","_opts$this$node$type","type","fns","fn","ret","state","then","Error","_traverseFlags","isDenylisted","_this$opts$denylist","denylist","blacklist","indexOf","restoreContext","path","context","visit","_this$opts$shouldSkip","_this$opts","shouldSkip","currentContext","shouldStop","traverseNode","scope","skipKeys","skip","skipKey","stop","SHOULD_SKIP","SHOULD_STOP","setScope","_this$opts2","_this$scope","noScope","parentPath","listKey","isMethod","isSwitchStatement","target","_path$opts","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","_this$node","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.ts\";\nimport { SHOULD_SKIP, SHOULD_STOP } from \"./index.ts\";\nimport type TraversalContext from \"../context.ts\";\nimport type { VisitPhase } from \"../types.ts\";\nimport type NodePath from \"./index.ts\";\nimport type * as t from \"@babel/types\";\n\nexport function call(this: NodePath, key: VisitPhase): 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]?.[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 // @ts-expect-error TODO(Babel 8): Remove blacklist\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)) {\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?.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?.noScope) return;\n\n target = path.scope;\n path = path.parentPath;\n }\n\n this.scope = this.getScope(target);\n 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 // Discard the S type parameter from context.opts\n this.opts = context.opts as typeof this.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 this.setKey(i);\n return;\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 this.setKey(key);\n return;\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 | 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,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMO,SAASE,IAAIA,CAAiBC,GAAe,EAAW;EAC7D,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;IAAA,IAAAE,oBAAA;IACb,OAAO,IAAI,CAACD,KAAK,EAAAC,oBAAA,GAACJ,IAAI,CAAC,IAAI,CAACE,IAAI,CAACG,IAAI,CAAC,qBAApBD,oBAAA,CAAuBL,GAAG,CAAC,CAAC;EAChD;EAEA,OAAO,KAAK;AACd;AAEO,SAASI,KAAKA,CAAiBG,GAAqB,EAAW;EACpE,IAAI,CAACA,GAAG,EAAE,OAAO,KAAK;EAEtB,KAAK,MAAMC,EAAE,IAAID,GAAG,EAAE;IACpB,IAAI,CAACC,EAAE,EAAE;IAET,MAAML,IAAI,GAAG,IAAI,CAACA,IAAI;IACtB,IAAI,CAACA,IAAI,EAAE,OAAO,IAAI;IAEtB,MAAMM,GA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