@babel/traverse 7.17.9 → 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 (67) hide show
  1. package/README.md +1 -1
  2. package/lib/cache.js +27 -7
  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 +17 -33
  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 +26 -90
  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 +54 -105
  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 -4
  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 -206
  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 +17 -72
  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 +115 -245
  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 +59 -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
@@ -4,227 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Var = exports.User = exports.Statement = exports.SpreadProperty = exports.Scope = exports.RestProperty = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = exports.Referenced = exports.Pure = exports.NumericLiteralTypeAnnotation = exports.Generated = exports.ForAwaitStatement = exports.Flow = exports.Expression = exports.ExistentialTypeParam = exports.BlockScoped = exports.BindingIdentifier = void 0;
7
-
8
- var _t = require("@babel/types");
9
-
10
- const {
11
- isBinding,
12
- isBlockScoped,
13
- isExportDeclaration,
14
- isExpression,
15
- isFlow,
16
- isForStatement,
17
- isForXStatement,
18
- isIdentifier,
19
- isImportDeclaration,
20
- isImportSpecifier,
21
- isJSXIdentifier,
22
- isJSXMemberExpression,
23
- isMemberExpression,
24
- isReferenced,
25
- isScope,
26
- isStatement,
27
- isVar,
28
- isVariableDeclaration,
29
- react
30
- } = _t;
31
- const {
32
- isCompatTag
33
- } = react;
34
- const ReferencedIdentifier = {
35
- types: ["Identifier", "JSXIdentifier"],
36
-
37
- checkPath(path, opts) {
38
- const {
39
- node,
40
- parent
41
- } = path;
42
-
43
- if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
44
- if (isJSXIdentifier(node, opts)) {
45
- if (isCompatTag(node.name)) return false;
46
- } else {
47
- return false;
48
- }
49
- }
50
-
51
- return isReferenced(node, parent, path.parentPath.parent);
52
- }
53
-
54
- };
7
+ const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
55
8
  exports.ReferencedIdentifier = ReferencedIdentifier;
56
- const ReferencedMemberExpression = {
57
- types: ["MemberExpression"],
58
-
59
- checkPath({
60
- node,
61
- parent
62
- }) {
63
- return isMemberExpression(node) && isReferenced(node, parent);
64
- }
65
-
66
- };
9
+ const ReferencedMemberExpression = ["MemberExpression"];
67
10
  exports.ReferencedMemberExpression = ReferencedMemberExpression;
68
- const BindingIdentifier = {
69
- types: ["Identifier"],
70
-
71
- checkPath(path) {
72
- const {
73
- node,
74
- parent
75
- } = path;
76
- const grandparent = path.parentPath.parent;
77
- return isIdentifier(node) && isBinding(node, parent, grandparent);
78
- }
79
-
80
- };
11
+ const BindingIdentifier = ["Identifier"];
81
12
  exports.BindingIdentifier = BindingIdentifier;
82
- const Statement = {
83
- types: ["Statement"],
84
-
85
- checkPath({
86
- node,
87
- parent
88
- }) {
89
- if (isStatement(node)) {
90
- if (isVariableDeclaration(node)) {
91
- if (isForXStatement(parent, {
92
- left: node
93
- })) return false;
94
- if (isForStatement(parent, {
95
- init: node
96
- })) return false;
97
- }
98
-
99
- return true;
100
- } else {
101
- return false;
102
- }
103
- }
104
-
105
- };
13
+ const Statement = ["Statement"];
106
14
  exports.Statement = Statement;
107
- const Expression = {
108
- types: ["Expression"],
109
-
110
- checkPath(path) {
111
- if (path.isIdentifier()) {
112
- return path.isReferencedIdentifier();
113
- } else {
114
- return isExpression(path.node);
115
- }
116
- }
117
-
118
- };
15
+ const Expression = ["Expression"];
119
16
  exports.Expression = Expression;
120
- const Scope = {
121
- types: ["Scopable", "Pattern"],
122
-
123
- checkPath(path) {
124
- return isScope(path.node, path.parent);
125
- }
126
-
127
- };
17
+ const Scope = ["Scopable", "Pattern"];
128
18
  exports.Scope = Scope;
129
- const Referenced = {
130
- checkPath(path) {
131
- return isReferenced(path.node, path.parent);
132
- }
133
-
134
- };
19
+ const Referenced = null;
135
20
  exports.Referenced = Referenced;
136
- const BlockScoped = {
137
- checkPath(path) {
138
- return isBlockScoped(path.node);
139
- }
140
-
141
- };
21
+ const BlockScoped = null;
142
22
  exports.BlockScoped = BlockScoped;
143
- const Var = {
144
- types: ["VariableDeclaration"],
145
-
146
- checkPath(path) {
147
- return isVar(path.node);
148
- }
149
-
150
- };
23
+ const Var = ["VariableDeclaration"];
151
24
  exports.Var = Var;
152
- const User = {
153
- checkPath(path) {
154
- return path.node && !!path.node.loc;
155
- }
156
-
157
- };
25
+ const User = null;
158
26
  exports.User = User;
159
- const Generated = {
160
- checkPath(path) {
161
- return !path.isUser();
162
- }
163
-
164
- };
27
+ const Generated = null;
165
28
  exports.Generated = Generated;
166
- const Pure = {
167
- checkPath(path, opts) {
168
- return path.scope.isPure(path.node, opts);
169
- }
170
-
171
- };
29
+ const Pure = null;
172
30
  exports.Pure = Pure;
173
- const Flow = {
174
- types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
175
-
176
- checkPath({
177
- node
178
- }) {
179
- if (isFlow(node)) {
180
- return true;
181
- } else if (isImportDeclaration(node)) {
182
- return node.importKind === "type" || node.importKind === "typeof";
183
- } else if (isExportDeclaration(node)) {
184
- return node.exportKind === "type";
185
- } else if (isImportSpecifier(node)) {
186
- return node.importKind === "type" || node.importKind === "typeof";
187
- } else {
188
- return false;
189
- }
190
- }
191
-
192
- };
31
+ const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
193
32
  exports.Flow = Flow;
194
- const RestProperty = {
195
- types: ["RestElement"],
196
-
197
- checkPath(path) {
198
- return path.parentPath && path.parentPath.isObjectPattern();
199
- }
200
-
201
- };
33
+ const RestProperty = ["RestElement"];
202
34
  exports.RestProperty = RestProperty;
203
- const SpreadProperty = {
204
- types: ["RestElement"],
205
-
206
- checkPath(path) {
207
- return path.parentPath && path.parentPath.isObjectExpression();
208
- }
209
-
210
- };
35
+ const SpreadProperty = ["RestElement"];
211
36
  exports.SpreadProperty = SpreadProperty;
212
- const ExistentialTypeParam = {
213
- types: ["ExistsTypeAnnotation"]
214
- };
37
+ const ExistentialTypeParam = ["ExistsTypeAnnotation"];
215
38
  exports.ExistentialTypeParam = ExistentialTypeParam;
216
- const NumericLiteralTypeAnnotation = {
217
- types: ["NumberLiteralTypeAnnotation"]
218
- };
39
+ const NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
219
40
  exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
220
- const ForAwaitStatement = {
221
- types: ["ForOfStatement"],
222
-
223
- checkPath({
224
- node
225
- }) {
226
- return node.await === true;
227
- }
41
+ const ForAwaitStatement = ["ForOfStatement"];
42
+ exports.ForAwaitStatement = ForAwaitStatement;
228
43
 
229
- };
230
- exports.ForAwaitStatement = ForAwaitStatement;
44
+ //# sourceMappingURL=virtual-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ReferencedIdentifier","exports","ReferencedMemberExpression","BindingIdentifier","Statement","Expression","Scope","Referenced","BlockScoped","Var","User","Generated","Pure","Flow","RestProperty","SpreadProperty","ExistentialTypeParam","NumericLiteralTypeAnnotation","ForAwaitStatement"],"sources":["../../../src/path/lib/virtual-types.ts"],"sourcesContent":["import type * as t from \"@babel/types\";\n\nexport interface VirtualTypeAliases {\n BindingIdentifier: t.Identifier;\n BlockScoped: t.Node;\n ExistentialTypeParam: t.ExistsTypeAnnotation;\n Expression: t.Expression;\n Flow: t.Flow | t.ImportDeclaration | t.ExportDeclaration | t.ImportSpecifier;\n ForAwaitStatement: t.ForOfStatement;\n Generated: t.Node;\n NumericLiteralTypeAnnotation: t.NumberLiteralTypeAnnotation;\n Pure: t.Node;\n Referenced: t.Node;\n ReferencedIdentifier: t.Identifier | t.JSXIdentifier;\n ReferencedMemberExpression: t.MemberExpression;\n RestProperty: t.RestElement;\n Scope: t.Scopable | t.Pattern;\n SpreadProperty: t.RestElement;\n Statement: t.Statement;\n User: t.Node;\n Var: t.VariableDeclaration;\n}\n\ntype VirtualTypeMapping = readonly (t.Node[\"type\"] | keyof t.Aliases)[] | null;\n\nexport const ReferencedIdentifier: VirtualTypeMapping = [\n \"Identifier\",\n \"JSXIdentifier\",\n] as const;\n\nexport const ReferencedMemberExpression: VirtualTypeMapping = [\n \"MemberExpression\",\n] as const;\n\nexport const BindingIdentifier: VirtualTypeMapping = [\"Identifier\"] as const;\n\nexport const Statement: VirtualTypeMapping = [\"Statement\"] as const;\n\nexport const Expression: VirtualTypeMapping = [\"Expression\"] as const;\n\nexport const Scope: VirtualTypeMapping = [\"Scopable\", \"Pattern\"] as const;\n\nexport const Referenced: VirtualTypeMapping = null;\n\nexport const BlockScoped: VirtualTypeMapping = null;\n\nexport const Var: VirtualTypeMapping = [\"VariableDeclaration\"];\n\nexport const User: VirtualTypeMapping = null;\n\nexport const Generated: VirtualTypeMapping = null;\n\nexport const Pure: VirtualTypeMapping = null;\n\nexport const Flow: VirtualTypeMapping = [\n \"Flow\",\n \"ImportDeclaration\",\n \"ExportDeclaration\",\n \"ImportSpecifier\",\n] as const;\n\n// TODO: 7.0 Backwards Compat\nexport const RestProperty: VirtualTypeMapping = [\"RestElement\"] as const;\n\nexport const SpreadProperty: VirtualTypeMapping = [\"RestElement\"] as const;\n\nexport const ExistentialTypeParam: VirtualTypeMapping = [\n \"ExistsTypeAnnotation\",\n] as const;\n\nexport const NumericLiteralTypeAnnotation: VirtualTypeMapping = [\n \"NumberLiteralTypeAnnotation\",\n] as const;\n\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;AAACb,OAAA,CAAAa,YAAA,GAAAA,YAAA;AAElE,MAAMC,cAAkC,GAAG,CAAC,aAAa,CAAU;AAACd,OAAA,CAAAc,cAAA,GAAAA,cAAA;AAEpE,MAAMC,oBAAwC,GAAG,CACtD,sBAAsB,CACd;AAACf,OAAA,CAAAe,oBAAA,GAAAA,oBAAA;AAEJ,MAAMC,4BAAgD,GAAG,CAC9D,6BAA6B,CACrB;AAAChB,OAAA,CAAAgB,4BAAA,GAAAA,4BAAA;AAEJ,MAAMC,iBAAqC,GAAG,CACnD,gBAAgB,CACR;AAACjB,OAAA,CAAAiB,iBAAA,GAAAA,iBAAA"}
@@ -13,15 +13,10 @@ exports.insertBefore = insertBefore;
13
13
  exports.pushContainer = pushContainer;
14
14
  exports.unshiftContainer = unshiftContainer;
15
15
  exports.updateSiblingKeys = updateSiblingKeys;
16
-
17
- var _cache = require("../cache");
18
-
19
- var _hoister = require("./lib/hoister");
20
-
21
- var _index = require("./index");
22
-
16
+ var _cache = require("../cache.js");
17
+ var _hoister = require("./lib/hoister.js");
18
+ var _index = require("./index.js");
23
19
  var _t = require("@babel/types");
24
-
25
20
  const {
26
21
  arrowFunctionExpression,
27
22
  assertExpression,
@@ -32,23 +27,21 @@ const {
32
27
  expressionStatement,
33
28
  isAssignmentExpression,
34
29
  isCallExpression,
30
+ isExportNamedDeclaration,
35
31
  isExpression,
36
32
  isIdentifier,
37
33
  isSequenceExpression,
38
34
  isSuper,
39
35
  thisExpression
40
36
  } = _t;
41
-
42
37
  function insertBefore(nodes_) {
43
38
  this._assertUnremoved();
44
-
45
39
  const nodes = this._verifyNodeList(nodes_);
46
-
47
40
  const {
48
- parentPath
41
+ parentPath,
42
+ parent
49
43
  } = this;
50
-
51
- if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
44
+ if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
52
45
  return parentPath.insertBefore(nodes);
53
46
  } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
54
47
  if (this.node) nodes.push(this.node);
@@ -64,73 +57,57 @@ function insertBefore(nodes_) {
64
57
  throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
65
58
  }
66
59
  }
67
-
68
60
  function _containerInsert(from, nodes) {
69
61
  this.updateSiblingKeys(from, nodes.length);
70
62
  const paths = [];
71
63
  this.container.splice(from, 0, ...nodes);
72
-
73
64
  for (let i = 0; i < nodes.length; i++) {
65
+ var _this$context;
74
66
  const to = from + i;
75
67
  const path = this.getSibling(to);
76
68
  paths.push(path);
77
-
78
- if (this.context && this.context.queue) {
69
+ if ((_this$context = this.context) != null && _this$context.queue) {
79
70
  path.pushContext(this.context);
80
71
  }
81
72
  }
82
-
83
73
  const contexts = this._getQueueContexts();
84
-
85
74
  for (const path of paths) {
86
75
  path.setScope();
87
76
  path.debug("Inserted.");
88
-
89
77
  for (const context of contexts) {
90
78
  context.maybeQueue(path, true);
91
79
  }
92
80
  }
93
-
94
81
  return paths;
95
82
  }
96
-
97
83
  function _containerInsertBefore(nodes) {
98
84
  return this._containerInsert(this.key, nodes);
99
85
  }
100
-
101
86
  function _containerInsertAfter(nodes) {
102
87
  return this._containerInsert(this.key + 1, nodes);
103
88
  }
104
-
105
89
  const last = arr => arr[arr.length - 1];
106
-
107
90
  function isHiddenInSequenceExpression(path) {
108
91
  return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
109
92
  }
110
-
111
93
  function isAlmostConstantAssignment(node, scope) {
112
94
  if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
113
95
  return false;
114
96
  }
115
-
116
97
  const blockScope = scope.getBlockParent();
117
98
  return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
118
99
  }
119
-
120
100
  function insertAfter(nodes_) {
121
101
  this._assertUnremoved();
122
-
123
102
  if (this.isSequenceExpression()) {
124
103
  return last(this.get("expressions")).insertAfter(nodes_);
125
104
  }
126
-
127
105
  const nodes = this._verifyNodeList(nodes_);
128
-
129
106
  const {
130
- parentPath
107
+ parentPath,
108
+ parent
131
109
  } = this;
132
-
133
- if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
110
+ if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
134
111
  return parentPath.insertAfter(nodes.map(node => {
135
112
  return isExpression(node) ? expressionStatement(node) : node;
136
113
  }));
@@ -140,14 +117,12 @@ function insertAfter(nodes_) {
140
117
  let {
141
118
  scope
142
119
  } = this;
143
-
144
120
  if (scope.path.isPattern()) {
145
121
  assertExpression(node);
146
122
  this.replaceWith(callExpression(arrowFunctionExpression([], node), []));
147
123
  this.get("callee.body").insertAfter(nodes);
148
124
  return [this];
149
125
  }
150
-
151
126
  if (isHiddenInSequenceExpression(this)) {
152
127
  nodes.unshift(node);
153
128
  } else if (isCallExpression(node) && isSuper(node.callee)) {
@@ -165,13 +140,11 @@ function insertAfter(nodes_) {
165
140
  })) {
166
141
  scope = scope.parent;
167
142
  }
168
-
169
143
  const temp = scope.generateDeclaredUidIdentifier();
170
144
  nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
171
145
  nodes.push(expressionStatement(cloneNode(temp)));
172
146
  }
173
147
  }
174
-
175
148
  return this.replaceExpressionWithStatements(nodes);
176
149
  } else if (Array.isArray(this.container)) {
177
150
  return this._containerInsertAfter(nodes);
@@ -184,32 +157,25 @@ function insertAfter(nodes_) {
184
157
  throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
185
158
  }
186
159
  }
187
-
188
160
  function updateSiblingKeys(fromIndex, incrementBy) {
189
161
  if (!this.parent) return;
190
-
191
- const paths = _cache.path.get(this.parent);
192
-
162
+ const paths = (0, _cache.getCachedPaths)(this.hub, this.parent) || [];
193
163
  for (const [, path] of paths) {
194
- if (path.key >= fromIndex) {
164
+ if (typeof path.key === "number" && path.key >= fromIndex) {
195
165
  path.key += incrementBy;
196
166
  }
197
167
  }
198
168
  }
199
-
200
169
  function _verifyNodeList(nodes) {
201
170
  if (!nodes) {
202
171
  return [];
203
172
  }
204
-
205
173
  if (!Array.isArray(nodes)) {
206
174
  nodes = [nodes];
207
175
  }
208
-
209
176
  for (let i = 0; i < nodes.length; i++) {
210
177
  const node = nodes[i];
211
178
  let msg;
212
-
213
179
  if (!node) {
214
180
  msg = "has falsy node";
215
181
  } else if (typeof node !== "object") {
@@ -219,21 +185,16 @@ function _verifyNodeList(nodes) {
219
185
  } else if (node instanceof _index.default) {
220
186
  msg = "has a NodePath when it expected a raw object";
221
187
  }
222
-
223
188
  if (msg) {
224
189
  const type = Array.isArray(node) ? "array" : typeof node;
225
190
  throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
226
191
  }
227
192
  }
228
-
229
193
  return nodes;
230
194
  }
231
-
232
195
  function unshiftContainer(listKey, nodes) {
233
196
  this._assertUnremoved();
234
-
235
197
  nodes = this._verifyNodeList(nodes);
236
-
237
198
  const path = _index.default.get({
238
199
  parentPath: this,
239
200
  parent: this.node,
@@ -241,17 +202,12 @@ function unshiftContainer(listKey, nodes) {
241
202
  listKey,
242
203
  key: 0
243
204
  }).setContext(this.context);
244
-
245
205
  return path._containerInsertBefore(nodes);
246
206
  }
247
-
248
207
  function pushContainer(listKey, nodes) {
249
208
  this._assertUnremoved();
250
-
251
209
  const verifiedNodes = this._verifyNodeList(nodes);
252
-
253
210
  const container = this.node[listKey];
254
-
255
211
  const path = _index.default.get({
256
212
  parentPath: this,
257
213
  parent: this.node,
@@ -259,11 +215,11 @@ function pushContainer(listKey, nodes) {
259
215
  listKey,
260
216
  key: container.length
261
217
  }).setContext(this.context);
262
-
263
218
  return path.replaceWithMultiple(verifiedNodes);
264
219
  }
265
-
266
220
  function hoist(scope = this.scope) {
267
221
  const hoister = new _hoister.default(this, scope);
268
222
  return hoister.run();
269
- }
223
+ }
224
+
225
+ //# sourceMappingURL=modification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_cache","require","_hoister","_index","_t","arrowFunctionExpression","assertExpression","assignmentExpression","blockStatement","callExpression","cloneNode","expressionStatement","isAssignmentExpression","isCallExpression","isExportNamedDeclaration","isExpression","isIdentifier","isSequenceExpression","isSuper","thisExpression","insertBefore","nodes_","_assertUnremoved","nodes","_verifyNodeList","parentPath","parent","isExpressionStatement","isLabeledStatement","isExportDefaultDeclaration","isDeclaration","isNodeType","isJSXElement","isForStatement","key","node","push","replaceExpressionWithStatements","Array","isArray","container","_containerInsertBefore","isStatementOrBlock","shouldInsertCurrentNode","expression","replaceWith","unshiftContainer","Error","_containerInsert","from","updateSiblingKeys","length","paths","splice","i","_this$context","to","path","getSibling","context","queue","pushContext","contexts","_getQueueContexts","setScope","debug","maybeQueue","_containerInsertAfter","last","arr","isHiddenInSequenceExpression","expressions","isAlmostConstantAssignment","scope","left","blockScope","getBlockParent","hasOwnBinding","name","getOwnBinding","constantViolations","insertAfter","get","map","isPattern","unshift","callee","isPure","isMethod","computed","temp","generateDeclaredUidIdentifier","pushContainer","fromIndex","incrementBy","getCachedPaths","hub","msg","type","NodePath","listKey","setContext","verifiedNodes","replaceWithMultiple","hoist","hoister","PathHoister","run"],"sources":["../../src/path/modification.ts"],"sourcesContent":["// This file contains methods that modify the path/node in some ways.\n\nimport { getCachedPaths } from \"../cache.ts\";\nimport PathHoister from \"./lib/hoister.ts\";\nimport NodePath from \"./index.ts\";\nimport {\n arrowFunctionExpression,\n assertExpression,\n assignmentExpression,\n blockStatement,\n callExpression,\n cloneNode,\n expressionStatement,\n isAssignmentExpression,\n isCallExpression,\n isExportNamedDeclaration,\n isExpression,\n isIdentifier,\n isSequenceExpression,\n isSuper,\n thisExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"../scope/index.ts\";\n\n/**\n * Insert the provided nodes before the current one.\n */\n\nexport function insertBefore(\n this: NodePath,\n nodes_: t.Node | t.Node[],\n): NodePath[] {\n this._assertUnremoved();\n\n const nodes = this._verifyNodeList(nodes_);\n\n const { parentPath, parent } = this;\n\n if (\n parentPath.isExpressionStatement() ||\n parentPath.isLabeledStatement() ||\n // https://github.com/babel/babel/issues/15293\n // When Babel transforms `export class String { field }`, the class properties plugin will inject the defineProperty\n // helper, which depends on the builtins e.g. String, Number, Symbol, etc. To prevent them from being shadowed by local\n // exports, the helper injector replaces the named export into `class _String { field }; export { _String as String }`,\n // with `parentPath` here changed to the moved ClassDeclaration, causing rare inconsistency between `parent` and `parentPath`.\n // Here we retrieve the parent type from the `parent` property. This is a temporary fix and we should revisit when\n // helpers should get injected.\n isExportNamedDeclaration(parent) ||\n (parentPath.isExportDefaultDeclaration() && this.isDeclaration())\n ) {\n return parentPath.insertBefore(nodes);\n } else if (\n (this.isNodeType(\"Expression\") && !this.isJSXElement()) ||\n (parentPath.isForStatement() && this.key === \"init\")\n ) {\n if (this.node) nodes.push(this.node);\n // @ts-expect-error todo(flow->ts): check that nodes is an array of statements\n return this.replaceExpressionWithStatements(nodes);\n } else if (Array.isArray(this.container)) {\n return this._containerInsertBefore(nodes);\n } else if (this.isStatementOrBlock()) {\n const node = this.node as t.Statement;\n const shouldInsertCurrentNode =\n node &&\n (!this.isExpressionStatement() ||\n (node as t.ExpressionStatement).expression != null);\n\n this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));\n return (this as NodePath<t.BlockStatement>).unshiftContainer(\n \"body\",\n // @ts-expect-error Fixme: refine nodes to t.BlockStatement[\"body\"] when this is a BlockStatement path\n nodes,\n );\n } else {\n throw new Error(\n \"We don't know what to do with this node type. \" +\n \"We were previously a Statement but we can't fit in here?\",\n );\n }\n}\n\nexport function _containerInsert<N extends t.Node>(\n this: NodePath,\n from: number,\n nodes: N[],\n): NodePath<N>[] {\n this.updateSiblingKeys(from, nodes.length);\n\n const paths: NodePath<N>[] = [];\n\n // @ts-expect-error todo(flow->ts): this.container could be a NodePath\n this.container.splice(from, 0, ...nodes);\n for (let i = 0; i < nodes.length; i++) {\n const to = from + i;\n const path = this.getSibling(to) as NodePath<N>;\n paths.push(path);\n\n if (this.context?.queue) {\n path.pushContext(this.context);\n }\n }\n\n const contexts = this._getQueueContexts();\n\n for (const path of paths) {\n path.setScope();\n path.debug(\"Inserted.\");\n\n for (const context of contexts) {\n context.maybeQueue(path, true);\n }\n }\n\n return paths;\n}\n\nexport function _containerInsertBefore<N extends t.Node>(\n this: NodePath,\n nodes: N[],\n) {\n return this._containerInsert(this.key as number, nodes);\n}\n\nexport function _containerInsertAfter<N extends t.Node>(\n this: NodePath,\n nodes: N[],\n) {\n return this._containerInsert((this.key as number) + 1, nodes);\n}\n\nconst last = <T>(arr: T[]) => arr[arr.length - 1];\n\nfunction isHiddenInSequenceExpression(path: NodePath): boolean {\n return (\n isSequenceExpression(path.parent) &&\n (last(path.parent.expressions) !== path.node ||\n isHiddenInSequenceExpression(path.parentPath))\n );\n}\n\nfunction isAlmostConstantAssignment(\n node: t.Node,\n scope: Scope,\n): node is t.AssignmentExpression & { left: t.Identifier } {\n if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {\n return false;\n }\n\n // Not every scope can contain variables. For example, we might be in\n // a ClassScope either in the ClassHeritage or in a computed key.\n const blockScope = scope.getBlockParent();\n\n // If the variable is defined in the current scope and only assigned here,\n // we can be sure that its value won't change.\n return (\n blockScope.hasOwnBinding(node.left.name) &&\n blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1\n );\n}\n\n/**\n * Insert the provided nodes after the current one. When inserting nodes after an\n * expression, ensure that the completion record is correct by pushing the current node.\n */\n\nexport function insertAfter(\n this: NodePath,\n nodes_: t.Node | t.Node[],\n): NodePath[] {\n this._assertUnremoved();\n\n if (this.isSequenceExpression()) {\n return last(this.get(\"expressions\")).insertAfter(nodes_);\n }\n\n const nodes = this._verifyNodeList(nodes_);\n\n const { parentPath, parent } = this;\n if (\n parentPath.isExpressionStatement() ||\n parentPath.isLabeledStatement() ||\n // see insertBefore\n isExportNamedDeclaration(parent) ||\n (parentPath.isExportDefaultDeclaration() && this.isDeclaration())\n ) {\n return parentPath.insertAfter(\n nodes.map(node => {\n // Usually after an expression we can safely insert another expression:\n // A.insertAfter(B)\n // foo = A; -> foo = (A, B);\n // If A is an expression statement, it isn't safe anymore so we need to\n // convert B to an expression statement\n // A; -> A; B // No semicolon! It could break if followed by [!\n return isExpression(node) ? expressionStatement(node) : node;\n }),\n );\n } else if (\n (this.isNodeType(\"Expression\") &&\n !this.isJSXElement() &&\n !parentPath.isJSXElement()) ||\n (parentPath.isForStatement() && this.key === \"init\")\n ) {\n if (this.node) {\n const node = this.node as t.Expression | t.VariableDeclaration;\n let { scope } = this;\n\n if (scope.path.isPattern()) {\n assertExpression(node);\n\n this.replaceWith(callExpression(arrowFunctionExpression([], node), []));\n (this.get(\"callee.body\") as NodePath<t.Expression>).insertAfter(nodes);\n return [this];\n }\n\n if (isHiddenInSequenceExpression(this)) {\n nodes.unshift(node);\n }\n // We need to preserve the value of this expression.\n else if (isCallExpression(node) && isSuper(node.callee)) {\n nodes.unshift(node);\n // `super(...)` always evaluates to `this`.\n nodes.push(thisExpression());\n } else if (isAlmostConstantAssignment(node, scope)) {\n nodes.unshift(node);\n nodes.push(cloneNode(node.left));\n } else if (scope.isPure(node, true)) {\n // Insert the nodes before rather than after; it's not observable.\n nodes.push(node);\n } else {\n // Inserting after the computed key of a method should insert the\n // temporary binding in the method's parent's scope.\n if (parentPath.isMethod({ computed: true, key: node })) {\n scope = scope.parent;\n }\n const temp = scope.generateDeclaredUidIdentifier();\n nodes.unshift(\n expressionStatement(\n // @ts-expect-error todo(flow->ts): This can be a variable\n // declaration in the \"init\" of a for statement, but that's\n // invalid here.\n assignmentExpression(\"=\", cloneNode(temp), node),\n ),\n );\n nodes.push(expressionStatement(cloneNode(temp)));\n }\n }\n // @ts-expect-error todo(flow->ts): check that nodes is an array of statements\n return this.replaceExpressionWithStatements(nodes);\n } else if (Array.isArray(this.container)) {\n return this._containerInsertAfter(nodes);\n } else if (this.isStatementOrBlock()) {\n const node = this.node as t.Statement;\n const shouldInsertCurrentNode =\n node &&\n (!this.isExpressionStatement() ||\n (node as t.ExpressionStatement).expression != null);\n\n this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));\n // @ts-expect-error Fixme: refine nodes to t.BlockStatement[\"body\"] when this is a BlockStatement path\n return this.pushContainer(\"body\", nodes);\n } else {\n throw new Error(\n \"We don't know what to do with this node type. \" +\n \"We were previously a Statement but we can't fit in here?\",\n );\n }\n}\n\n/**\n * Update all sibling node paths after `fromIndex` by `incrementBy`.\n */\n\nexport function updateSiblingKeys(\n this: NodePath,\n fromIndex: number,\n incrementBy: number,\n) {\n if (!this.parent) return;\n\n const paths = getCachedPaths(this.hub, this.parent) || ([] as never[]);\n\n for (const [, path] of paths) {\n if (typeof path.key === \"number\" && path.key >= fromIndex) {\n path.key += incrementBy;\n }\n }\n}\n\nexport function _verifyNodeList<N extends t.Node>(\n this: NodePath,\n nodes: N | N[],\n): N[] {\n if (!nodes) {\n return [];\n }\n\n if (!Array.isArray(nodes)) {\n nodes = [nodes];\n }\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n let msg;\n\n if (!node) {\n msg = \"has falsy node\";\n } else if (typeof node !== \"object\") {\n msg = \"contains a non-object node\";\n } else if (!node.type) {\n msg = \"without a type\";\n } else if (node instanceof NodePath) {\n msg = \"has a NodePath when it expected a raw object\";\n }\n\n if (msg) {\n const type = Array.isArray(node) ? \"array\" : typeof node;\n throw new Error(\n `Node list ${msg} with the index of ${i} and type of ${type}`,\n );\n }\n }\n\n return nodes;\n}\n\nexport function unshiftContainer<N extends t.Node, K extends keyof N & string>(\n this: NodePath<N>,\n listKey: K,\n nodes: N[K] extends (infer E)[]\n ? E | E[]\n : // todo: refine to t.Node[]\n // ? E extends t.Node\n // ? E | E[]\n // : never\n never,\n) {\n // todo: NodePaths<Nodes>\n this._assertUnremoved();\n\n // @ts-expect-error fixme\n nodes = this._verifyNodeList(nodes);\n\n // get the first path and insert our nodes before it, if it doesn't exist then it\n // doesn't matter, our nodes will be inserted anyway\n const path = NodePath.get({\n parentPath: this,\n parent: this.node,\n container: this.node[listKey] as unknown as t.Node | t.Node[],\n listKey,\n key: 0,\n }).setContext(this.context);\n\n return path._containerInsertBefore(\n // @ts-expect-error typings needed to narrow down nodes as t.Node[]\n nodes,\n );\n}\n\nexport function pushContainer<N extends t.Node, K extends keyof N & string>(\n this: NodePath<N>,\n listKey: K,\n nodes: N[K] extends (infer E)[]\n ? E | E[]\n : // todo: refine to t.Node[]\n // ? E extends t.Node\n // ? E | E[]\n // : never\n never,\n) {\n this._assertUnremoved();\n\n const verifiedNodes = this._verifyNodeList(\n // @ts-expect-error refine typings\n nodes,\n );\n\n // get an invisible path that represents the last node + 1 and replace it with our\n // nodes, effectively inlining it\n\n const container = this.node[listKey];\n const path = NodePath.get({\n parentPath: this,\n parent: this.node,\n container: container as unknown as t.Node | t.Node[],\n listKey,\n // @ts-expect-error TS cannot infer that container is t.Node[]\n key: container.length,\n }).setContext(this.context);\n\n return path.replaceWithMultiple(verifiedNodes);\n}\n\n/**\n * Hoist the current node to the highest scope possible and return a UID\n * referencing it.\n */\nexport function hoist<T extends t.Node>(\n this: NodePath<T>,\n scope: Scope = this.scope,\n) {\n const hoister = new PathHoister<T>(this, scope);\n return hoister.run();\n}\n"],"mappings":";;;;;;;;;;;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,EAAA,GAAAH,OAAA;AAgBsB;EAfpBI,uBAAuB;EACvBC,gBAAgB;E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AU,CAAC,IAAI,CAAC1C,OAAO,CAAC;EAE3B,OAAOF,IAAI,CAAChB,sBAAsB,CAEhClB,KACF,CAAC;AACH;AAEO,SAASqE,aAAaA,CAE3BQ,OAAU,EACV7E,KAMS,EACT;EACA,IAAI,CAACD,gBAAgB,CAAC,CAAC;EAEvB,MAAMgF,aAAa,GAAG,IAAI,CAAC9E,eAAe,CAExCD,KACF,CAAC;EAKD,MAAMiB,SAAS,GAAG,IAAI,CAACL,IAAI,CAACiE,OAAO,CAAC;EACpC,MAAM3C,IAAI,GAAG0C,cAAQ,CAACjB,GAAG,CAAC;IACxBzD,UAAU,EAAE,IAAI;IAChBC,MAAM,EAAE,IAAI,CAACS,IAAI;IACjBK,SAAS,EAAEA,SAAyC;IACpD4D,OAAO;IAEPlE,GAAG,EAAEM,SAAS,CAACW;EACjB,CAAC,CAAC,CAACkD,UAAU,CAAC,IAAI,CAAC1C,OAAO,CAAC;EAE3B,OAAOF,IAAI,CAAC8C,mBAAmB,CAACD,aAAa,CAAC;AAChD;AAMO,SAASE,KAAKA,CAEnB/B,KAAY,GAAG,IAAI,CAACA,KAAK,EACzB;EACA,MAAMgC,OAAO,GAAG,IAAIC,gBAAW,CAAI,IAAI,EAAEjC,KAAK,CAAC;EAC/C,OAAOgC,OAAO,CAACE,GAAG,CAAC,CAAC;AACtB"}
@@ -9,48 +9,33 @@ exports._markRemoved = _markRemoved;
9
9
  exports._remove = _remove;
10
10
  exports._removeFromScope = _removeFromScope;
11
11
  exports.remove = remove;
12
-
13
- var _removalHooks = require("./lib/removal-hooks");
14
-
15
- var _cache = require("../cache");
16
-
17
- var _index = require("./index");
18
-
12
+ var _removalHooks = require("./lib/removal-hooks.js");
13
+ var _cache = require("../cache.js");
14
+ var _index = require("./index.js");
19
15
  function remove() {
20
16
  var _this$opts;
21
-
22
17
  this._assertUnremoved();
23
-
24
18
  this.resync();
25
-
26
19
  if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
27
20
  this._removeFromScope();
28
21
  }
29
-
30
22
  if (this._callRemovalHooks()) {
31
23
  this._markRemoved();
32
-
33
24
  return;
34
25
  }
35
-
36
26
  this.shareCommentsWithSiblings();
37
-
38
27
  this._remove();
39
-
40
28
  this._markRemoved();
41
29
  }
42
-
43
30
  function _removeFromScope() {
44
31
  const bindings = this.getBindingIdentifiers();
45
32
  Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
46
33
  }
47
-
48
34
  function _callRemovalHooks() {
49
35
  for (const fn of _removalHooks.hooks) {
50
36
  if (fn(this, this.parentPath)) return true;
51
37
  }
52
38
  }
53
-
54
39
  function _remove() {
55
40
  if (Array.isArray(this.container)) {
56
41
  this.container.splice(this.key, 1);
@@ -59,15 +44,17 @@ function _remove() {
59
44
  this._replaceWith(null);
60
45
  }
61
46
  }
62
-
63
47
  function _markRemoved() {
64
48
  this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
65
- if (this.parent) _cache.path.get(this.parent).delete(this.node);
49
+ if (this.parent) {
50
+ (0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node);
51
+ }
66
52
  this.node = null;
67
53
  }
68
-
69
54
  function _assertUnremoved() {
70
55
  if (this.removed) {
71
56
  throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
72
57
  }
73
- }
58
+ }
59
+
60
+ //# sourceMappingURL=removal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_removalHooks","require","_cache","_index","remove","_this$opts","_assertUnremoved","resync","opts","noScope","_removeFromScope","_callRemovalHooks","_markRemoved","shareCommentsWithSiblings","_remove","bindings","getBindingIdentifiers","Object","keys","forEach","name","scope","removeBinding","fn","hooks","parentPath","Array","isArray","container","splice","key","updateSiblingKeys","_replaceWith","_traverseFlags","SHOULD_SKIP","REMOVED","parent","getCachedPaths","hub","delete","node","removed","buildCodeFrameError"],"sources":["../../src/path/removal.ts"],"sourcesContent":["// This file contains methods responsible for removing a node.\n\nimport { hooks } from \"./lib/removal-hooks.ts\";\nimport { getCachedPaths } from \"../cache.ts\";\nimport type NodePath from \"./index.ts\";\nimport { REMOVED, SHOULD_SKIP } from \"./index.ts\";\n\nexport function remove(this: NodePath) {\n this._assertUnremoved();\n\n this.resync();\n if (!this.opts?.noScope) {\n this._removeFromScope();\n }\n\n if (this._callRemovalHooks()) {\n this._markRemoved();\n return;\n }\n\n this.shareCommentsWithSiblings();\n this._remove();\n this._markRemoved();\n}\n\nexport function _removeFromScope(this: NodePath) {\n const bindings = this.getBindingIdentifiers();\n Object.keys(bindings).forEach(name => this.scope.removeBinding(name));\n}\n\nexport function _callRemovalHooks(this: NodePath) {\n for (const fn of hooks) {\n if (fn(this, this.parentPath)) return true;\n }\n}\n\nexport function _remove(this: NodePath) {\n if (Array.isArray(this.container)) {\n this.container.splice(this.key as number, 1);\n this.updateSiblingKeys(this.key as number, -1);\n } else {\n this._replaceWith(null);\n }\n}\n\nexport function _markRemoved(this: NodePath) {\n // this.shouldSkip = true; this.removed = true;\n this._traverseFlags |= SHOULD_SKIP | REMOVED;\n if (this.parent) {\n getCachedPaths(this.hub, this.parent).delete(this.node);\n }\n this.node = null;\n}\n\nexport function _assertUnremoved(this: NodePath) {\n if (this.removed) {\n throw this.buildCodeFrameError(\n \"NodePath has been removed so is read-only.\",\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAEO,SAASG,MAAMA,CAAA,EAAiB;EAAA,IAAAC,UAAA;EACrC,IAAI,CAACC,gBAAgB,CAAC,CAAC;EAEvB,IAAI,CAACC,MAAM,CAAC,CAAC;EACb,IAAI,GAAAF,UAAA,GAAC,IAAI,CAACG,IAAI,aAATH,UAAA,CAAWI,OAAO,GAAE;IACvB,IAAI,CAACC,gBAAgB,CAAC,CAAC;EACzB;EAEA,IAAI,IAAI,CAACC,iBAAiB,CAAC,CAAC,EAAE;IAC5B,IAAI,CAACC,YAAY,CAAC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