@babel/traverse 7.17.9 → 7.23.4

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
@@ -4,19 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.arrowFunctionToExpression = arrowFunctionToExpression;
7
- exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
8
7
  exports.ensureBlock = ensureBlock;
9
8
  exports.toComputedKey = toComputedKey;
10
9
  exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
11
-
12
10
  var _t = require("@babel/types");
13
-
14
11
  var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
15
-
16
12
  var _helperFunctionName = require("@babel/helper-function-name");
17
-
18
- var _visitors = require("../visitors");
19
-
13
+ var _visitors = require("../visitors.js");
20
14
  const {
21
15
  arrowFunctionExpression,
22
16
  assignmentExpression,
@@ -44,10 +38,8 @@ const {
44
38
  toExpression,
45
39
  unaryExpression
46
40
  } = _t;
47
-
48
41
  function toComputedKey() {
49
42
  let key;
50
-
51
43
  if (this.isMemberExpression()) {
52
44
  key = this.node.property;
53
45
  } else if (this.isProperty() || this.isMethod()) {
@@ -55,42 +47,33 @@ function toComputedKey() {
55
47
  } else {
56
48
  throw new ReferenceError("todo");
57
49
  }
58
-
59
50
  if (!this.node.computed) {
60
51
  if (isIdentifier(key)) key = stringLiteral(key.name);
61
52
  }
62
-
63
53
  return key;
64
54
  }
65
-
66
55
  function ensureBlock() {
67
56
  const body = this.get("body");
68
57
  const bodyNode = body.node;
69
-
70
58
  if (Array.isArray(body)) {
71
59
  throw new Error("Can't convert array path to a block statement");
72
60
  }
73
-
74
61
  if (!bodyNode) {
75
62
  throw new Error("Can't convert node without a body");
76
63
  }
77
-
78
64
  if (body.isBlockStatement()) {
79
65
  return bodyNode;
80
66
  }
81
-
82
67
  const statements = [];
83
68
  let stringPath = "body";
84
69
  let key;
85
70
  let listKey;
86
-
87
71
  if (body.isStatement()) {
88
72
  listKey = "body";
89
73
  key = 0;
90
74
  statements.push(body.node);
91
75
  } else {
92
76
  stringPath += ".body.0";
93
-
94
77
  if (this.isFunction()) {
95
78
  key = "argument";
96
79
  statements.push(returnStatement(body.node));
@@ -99,57 +82,54 @@ function ensureBlock() {
99
82
  statements.push(expressionStatement(body.node));
100
83
  }
101
84
  }
102
-
103
85
  this.node.body = blockStatement(statements);
104
86
  const parentPath = this.get(stringPath);
105
87
  body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
106
88
  return this.node;
107
89
  }
108
-
109
- function arrowFunctionToShadowed() {
110
- if (!this.isArrowFunctionExpression()) return;
111
- this.arrowFunctionToExpression();
90
+ {
91
+ exports.arrowFunctionToShadowed = function () {
92
+ if (!this.isArrowFunctionExpression()) return;
93
+ this.arrowFunctionToExpression();
94
+ };
112
95
  }
113
-
114
96
  function unwrapFunctionEnvironment() {
115
97
  if (!this.isArrowFunctionExpression() && !this.isFunctionExpression() && !this.isFunctionDeclaration()) {
116
98
  throw this.buildCodeFrameError("Can only unwrap the environment of a function.");
117
99
  }
118
-
119
100
  hoistFunctionEnvironment(this);
120
101
  }
121
-
102
+ function setType(path, type) {
103
+ path.node.type = type;
104
+ }
122
105
  function arrowFunctionToExpression({
123
106
  allowInsertArrow = true,
124
- specCompliant = false,
125
- noNewArrows = !specCompliant
107
+ allowInsertArrowWithRest = allowInsertArrow,
108
+ noNewArrows = !(_arguments$ => (_arguments$ = arguments[0]) == null ? void 0 : _arguments$.specCompliant)()
126
109
  } = {}) {
127
110
  if (!this.isArrowFunctionExpression()) {
128
111
  throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
129
112
  }
130
-
131
113
  const {
132
114
  thisBinding,
133
115
  fnPath: fn
134
- } = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
116
+ } = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow, allowInsertArrowWithRest);
135
117
  fn.ensureBlock();
136
- fn.node.type = "FunctionExpression";
137
-
118
+ setType(fn, "FunctionExpression");
138
119
  if (!noNewArrows) {
139
120
  const checkBinding = thisBinding ? null : fn.scope.generateUidIdentifier("arrowCheckId");
140
-
141
121
  if (checkBinding) {
142
122
  fn.parentPath.scope.push({
143
123
  id: checkBinding,
144
124
  init: objectExpression([])
145
125
  });
146
126
  }
147
-
148
127
  fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
149
128
  fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
129
+ return fn.get("callee.object");
150
130
  }
131
+ return fn;
151
132
  }
152
-
153
133
  const getSuperCallsVisitor = (0, _visitors.merge)([{
154
134
  CallExpression(child, {
155
135
  allSuperCalls
@@ -157,19 +137,15 @@ const getSuperCallsVisitor = (0, _visitors.merge)([{
157
137
  if (!child.get("callee").isSuper()) return;
158
138
  allSuperCalls.push(child);
159
139
  }
160
-
161
140
  }, _helperEnvironmentVisitor.default]);
162
-
163
- function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true) {
141
+ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true, allowInsertArrowWithRest = true) {
164
142
  let arrowParent;
165
143
  let thisEnvFn = fnPath.findParent(p => {
166
144
  if (p.isArrowFunctionExpression()) {
167
145
  var _arrowParent;
168
-
169
146
  (_arrowParent = arrowParent) != null ? _arrowParent : arrowParent = p;
170
147
  return false;
171
148
  }
172
-
173
149
  return p.isFunction() || p.isProgram() || p.isClassProperty({
174
150
  static: false
175
151
  }) || p.isClassPrivateProperty({
@@ -179,7 +155,6 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
179
155
  const inConstructor = thisEnvFn.isClassMethod({
180
156
  kind: "constructor"
181
157
  });
182
-
183
158
  if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) {
184
159
  if (arrowParent) {
185
160
  thisEnvFn = arrowParent;
@@ -191,7 +166,6 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
191
166
  throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
192
167
  }
193
168
  }
194
-
195
169
  const {
196
170
  thisPaths,
197
171
  argumentsPaths,
@@ -199,12 +173,13 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
199
173
  superProps,
200
174
  superCalls
201
175
  } = getScopeInformation(fnPath);
202
-
203
176
  if (inConstructor && superCalls.length > 0) {
204
177
  if (!allowInsertArrow) {
205
- throw superCalls[0].buildCodeFrameError("Unable to handle nested super() usage in arrow");
178
+ throw superCalls[0].buildCodeFrameError("When using '@babel/plugin-transform-arrow-functions', " + "it's not possible to compile `super()` in an arrow function without compiling classes.\n" + "Please add '@babel/plugin-transform-classes' to your Babel configuration.");
179
+ }
180
+ if (!allowInsertArrowWithRest) {
181
+ throw superCalls[0].buildCodeFrameError("When using '@babel/plugin-transform-parameters', " + "it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.\n" + "Please add '@babel/plugin-transform-classes' to your Babel configuration.");
206
182
  }
207
-
208
183
  const allSuperCalls = [];
209
184
  thisEnvFn.traverse(getSuperCallsVisitor, {
210
185
  allSuperCalls
@@ -216,11 +191,9 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
216
191
  superCall.get("callee").replaceWith(callee);
217
192
  });
218
193
  }
219
-
220
194
  if (argumentsPaths.length > 0) {
221
195
  const argumentsBinding = getBinding(thisEnvFn, "arguments", () => {
222
196
  const args = () => identifier("arguments");
223
-
224
197
  if (thisEnvFn.scope.path.isProgram()) {
225
198
  return conditionalExpression(binaryExpression("===", unaryExpression("typeof", args()), stringLiteral("undefined")), thisEnvFn.scope.buildUndefinedNode(), args());
226
199
  } else {
@@ -233,7 +206,6 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
233
206
  argumentsChild.replaceWith(argsRef);
234
207
  });
235
208
  }
236
-
237
209
  if (newTargetPaths.length > 0) {
238
210
  const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => metaProperty(identifier("new"), identifier("target")));
239
211
  newTargetPaths.forEach(targetChild => {
@@ -242,52 +214,50 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
242
214
  targetChild.replaceWith(targetRef);
243
215
  });
244
216
  }
245
-
246
217
  if (superProps.length > 0) {
247
218
  if (!allowInsertArrow) {
248
- throw superProps[0].buildCodeFrameError("Unable to handle nested super.prop usage");
219
+ throw superProps[0].buildCodeFrameError("When using '@babel/plugin-transform-arrow-functions', " + "it's not possible to compile `super.prop` in an arrow function without compiling classes.\n" + "Please add '@babel/plugin-transform-classes' to your Babel configuration.");
249
220
  }
250
-
251
221
  const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []);
252
222
  flatSuperProps.forEach(superProp => {
253
223
  const key = superProp.node.computed ? "" : superProp.get("property").node.name;
254
- const isAssignment = superProp.parentPath.isAssignmentExpression({
224
+ const superParentPath = superProp.parentPath;
225
+ const isAssignment = superParentPath.isAssignmentExpression({
255
226
  left: superProp.node
256
227
  });
257
- const isCall = superProp.parentPath.isCallExpression({
228
+ const isCall = superParentPath.isCallExpression({
258
229
  callee: superProp.node
259
230
  });
231
+ const isTaggedTemplate = superParentPath.isTaggedTemplateExpression({
232
+ tag: superProp.node
233
+ });
260
234
  const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
261
235
  const args = [];
262
-
263
236
  if (superProp.node.computed) {
264
237
  args.push(superProp.get("property").node);
265
238
  }
266
-
267
239
  if (isAssignment) {
268
- const value = superProp.parentPath.node.right;
240
+ const value = superParentPath.node.right;
269
241
  args.push(value);
270
242
  }
271
-
272
243
  const call = callExpression(identifier(superBinding), args);
273
-
274
244
  if (isCall) {
275
- superProp.parentPath.unshiftContainer("arguments", thisExpression());
245
+ superParentPath.unshiftContainer("arguments", thisExpression());
276
246
  superProp.replaceWith(memberExpression(call, identifier("call")));
277
- thisPaths.push(superProp.parentPath.get("arguments.0"));
247
+ thisPaths.push(superParentPath.get("arguments.0"));
278
248
  } else if (isAssignment) {
279
- superProp.parentPath.replaceWith(call);
249
+ superParentPath.replaceWith(call);
250
+ } else if (isTaggedTemplate) {
251
+ superProp.replaceWith(callExpression(memberExpression(call, identifier("bind"), false), [thisExpression()]));
252
+ thisPaths.push(superProp.get("arguments.0"));
280
253
  } else {
281
254
  superProp.replaceWith(call);
282
255
  }
283
256
  });
284
257
  }
285
-
286
258
  let thisBinding;
287
-
288
259
  if (thisPaths.length > 0 || !noNewArrows) {
289
260
  thisBinding = getThisBinding(thisEnvFn, inConstructor);
290
-
291
261
  if (noNewArrows || inConstructor && hasSuperClass(thisEnvFn)) {
292
262
  thisPaths.forEach(thisChild => {
293
263
  const thisRef = thisChild.isJSX() ? jsxIdentifier(thisBinding) : identifier(thisBinding);
@@ -297,24 +267,20 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
297
267
  if (!noNewArrows) thisBinding = null;
298
268
  }
299
269
  }
300
-
301
270
  return {
302
271
  thisBinding,
303
272
  fnPath
304
273
  };
305
274
  }
306
-
307
275
  function isLogicalOp(op) {
308
276
  return LOGICAL_OPERATORS.includes(op);
309
277
  }
310
-
311
278
  function standardizeSuperProperty(superProp) {
312
279
  if (superProp.parentPath.isAssignmentExpression() && superProp.parentPath.node.operator !== "=") {
313
280
  const assignmentPath = superProp.parentPath;
314
281
  const op = assignmentPath.node.operator.slice(0, -1);
315
282
  const value = assignmentPath.node.right;
316
283
  const isLogicalAssignment = isLogicalOp(op);
317
-
318
284
  if (superProp.node.computed) {
319
285
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
320
286
  const object = superProp.node.object;
@@ -327,32 +293,26 @@ function standardizeSuperProperty(superProp) {
327
293
  assignmentPath.get("left").replaceWith(memberExpression(object, property));
328
294
  assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(property.name)), value));
329
295
  }
330
-
331
296
  if (isLogicalAssignment) {
332
297
  assignmentPath.replaceWith(logicalExpression(op, assignmentPath.node.left, assignmentPath.node.right));
333
298
  } else {
334
299
  assignmentPath.node.operator = "=";
335
300
  }
336
-
337
301
  return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
338
302
  } else if (superProp.parentPath.isUpdateExpression()) {
339
303
  const updateExpr = superProp.parentPath;
340
304
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
341
305
  const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
342
306
  const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral(1)))];
343
-
344
307
  if (!superProp.parentPath.node.prefix) {
345
308
  parts.push(identifier(tmp.name));
346
309
  }
347
-
348
310
  updateExpr.replaceWith(sequenceExpression(parts));
349
311
  const left = updateExpr.get("expressions.0.right");
350
312
  const right = updateExpr.get("expressions.1.left");
351
313
  return [left, right];
352
314
  }
353
-
354
315
  return [superProp];
355
-
356
316
  function rightExpression(op, left, right) {
357
317
  if (op === "=") {
358
318
  return assignmentExpression("=", left, right);
@@ -361,11 +321,9 @@ function standardizeSuperProperty(superProp) {
361
321
  }
362
322
  }
363
323
  }
364
-
365
324
  function hasSuperClass(thisEnvFn) {
366
325
  return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
367
326
  }
368
-
369
327
  const assignSuperThisVisitor = (0, _visitors.merge)([{
370
328
  CallExpression(child, {
371
329
  supers,
@@ -376,9 +334,7 @@ const assignSuperThisVisitor = (0, _visitors.merge)([{
376
334
  supers.add(child.node);
377
335
  child.replaceWithMultiple([child.node, assignmentExpression("=", identifier(thisBinding), identifier("this"))]);
378
336
  }
379
-
380
337
  }, _helperEnvironmentVisitor.default]);
381
-
382
338
  function getThisBinding(thisEnvFn, inConstructor) {
383
339
  return getBinding(thisEnvFn, "this", thisBinding => {
384
340
  if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression();
@@ -388,20 +344,17 @@ function getThisBinding(thisEnvFn, inConstructor) {
388
344
  });
389
345
  });
390
346
  }
391
-
392
347
  function getSuperBinding(thisEnvFn) {
393
348
  return getBinding(thisEnvFn, "supercall", () => {
394
349
  const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
395
350
  return arrowFunctionExpression([restElement(argsBinding)], callExpression(_super(), [spreadElement(identifier(argsBinding.name))]));
396
351
  });
397
352
  }
398
-
399
353
  function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
400
354
  const op = isAssignment ? "set" : "get";
401
355
  return getBinding(thisEnvFn, `superprop_${op}:${propName || ""}`, () => {
402
356
  const argsList = [];
403
357
  let fnBody;
404
-
405
358
  if (propName) {
406
359
  fnBody = memberExpression(_super(), identifier(propName));
407
360
  } else {
@@ -409,21 +362,17 @@ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
409
362
  argsList.unshift(method);
410
363
  fnBody = memberExpression(_super(), identifier(method.name), true);
411
364
  }
412
-
413
365
  if (isAssignment) {
414
366
  const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
415
367
  argsList.push(valueIdent);
416
368
  fnBody = assignmentExpression("=", fnBody, identifier(valueIdent.name));
417
369
  }
418
-
419
370
  return arrowFunctionExpression(argsList, fnBody);
420
371
  });
421
372
  }
422
-
423
373
  function getBinding(thisEnvFn, key, init) {
424
374
  const cacheKey = "binding:" + key;
425
375
  let data = thisEnvFn.getData(cacheKey);
426
-
427
376
  if (!data) {
428
377
  const id = thisEnvFn.scope.generateUidIdentifier(key);
429
378
  data = id.name;
@@ -433,22 +382,18 @@ function getBinding(thisEnvFn, key, init) {
433
382
  init: init(data)
434
383
  });
435
384
  }
436
-
437
385
  return data;
438
386
  }
439
-
440
387
  const getScopeInformationVisitor = (0, _visitors.merge)([{
441
388
  ThisExpression(child, {
442
389
  thisPaths
443
390
  }) {
444
391
  thisPaths.push(child);
445
392
  },
446
-
447
393
  JSXIdentifier(child, {
448
394
  thisPaths
449
395
  }) {
450
396
  if (child.node.name !== "this") return;
451
-
452
397
  if (!child.parentPath.isJSXMemberExpression({
453
398
  object: child.node
454
399
  }) && !child.parentPath.isJSXOpeningElement({
@@ -456,22 +401,18 @@ const getScopeInformationVisitor = (0, _visitors.merge)([{
456
401
  })) {
457
402
  return;
458
403
  }
459
-
460
404
  thisPaths.push(child);
461
405
  },
462
-
463
406
  CallExpression(child, {
464
407
  superCalls
465
408
  }) {
466
409
  if (child.get("callee").isSuper()) superCalls.push(child);
467
410
  },
468
-
469
411
  MemberExpression(child, {
470
412
  superProps
471
413
  }) {
472
414
  if (child.get("object").isSuper()) superProps.push(child);
473
415
  },
474
-
475
416
  Identifier(child, {
476
417
  argumentsPaths
477
418
  }) {
@@ -479,21 +420,17 @@ const getScopeInformationVisitor = (0, _visitors.merge)([{
479
420
  name: "arguments"
480
421
  })) return;
481
422
  let curr = child.scope;
482
-
483
423
  do {
484
424
  if (curr.hasOwnBinding("arguments")) {
485
425
  curr.rename("arguments");
486
426
  return;
487
427
  }
488
-
489
428
  if (curr.path.isFunction() && !curr.path.isArrowFunctionExpression()) {
490
429
  break;
491
430
  }
492
431
  } while (curr = curr.parent);
493
-
494
432
  argumentsPaths.push(child);
495
433
  },
496
-
497
434
  MetaProperty(child, {
498
435
  newTargetPaths
499
436
  }) {
@@ -505,9 +442,7 @@ const getScopeInformationVisitor = (0, _visitors.merge)([{
505
442
  })) return;
506
443
  newTargetPaths.push(child);
507
444
  }
508
-
509
445
  }, _helperEnvironmentVisitor.default]);
510
-
511
446
  function getScopeInformation(fnPath) {
512
447
  const thisPaths = [];
513
448
  const argumentsPaths = [];
@@ -528,4 +463,6 @@ function getScopeInformation(fnPath) {
528
463
  superProps,
529
464
  superCalls
530
465
  };
531
- }
466
+ }
467
+
468
+ //# sourceMappingURL=conversion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_t","require","_helperEnvironmentVisitor","_helperFunctionName","_visitors","arrowFunctionExpression","assignmentExpression","binaryExpression","blockStatement","callExpression","conditionalExpression","expressionStatement","identifier","isIdentifier","jsxIdentifier","logicalExpression","LOGICAL_OPERATORS","memberExpression","metaProperty","numericLiteral","objectExpression","restElement","returnStatement","sequenceExpression","spreadElement","stringLiteral","super","_super","thisExpression","toExpression","unaryExpression","toComputedKey","key","isMemberExpression","node","property","isProperty","isMethod","ReferenceError","computed","name","ensureBlock","body","get","bodyNode","Array","isArray","Error","isBlockStatement","statements","stringPath","listKey","isStatement","push","isFunction","parentPath","setup","exports","arrowFunctionToShadowed","isArrowFunctionExpression","arrowFunctionToExpression","unwrapFunctionEnvironment","isFunctionExpression","isFunctionDeclaration","buildCodeFrameError","hoistFunctionEnvironment","setType","path","type","allowInsertArrow","allowInsertArrowWithRest","noNewArrows","_arguments$","arguments","specCompliant","thisBinding","fnPath","fn","checkBinding","scope","generateUidIdentifier","id","init","unshiftContainer","hub","addHelper","replaceWith","nameFunction","getSuperCallsVisitor","mergeVisitors","CallExpression","child","allSuperCalls","isSuper","environmentVisitor","arrowParent","thisEnvFn","findParent","p","_arrowParent","isProgram","isClassProperty","static","isClassPrivateProperty","inConstructor","isClassMethod","kind","thisPaths","argumentsPaths","newTargetPaths","superProps","superCalls","getScopeInformation","length","traverse","superBinding","getSuperBinding","forEach","superCall","callee","loc","argumentsBinding","getBinding","args","buildUndefinedNode","argumentsChild","argsRef","newTargetBinding","targetChild","targetRef","flatSuperProps","reduce","acc","superProp","concat","standardizeSuperProperty","superParentPath","isAssignment","isAssignmentExpression","left","isCall","isCallExpression","isTaggedTemplate","isTaggedTemplateExpression","tag","getSuperPropBinding","value","right","call","getThisBinding","hasSuperClass","thisChild","thisRef","isJSX","isLogicalOp","op","includes","operator","assignmentPath","slice","isLogicalAssignment","tmp","generateDeclaredUidIdentifier","object","rightExpression","isUpdateExpression","updateExpr","computedKey","parts","prefix","superClass","assignSuperThisVisitor","supers","has","add","replaceWithMultiple","WeakSet","argsBinding","propName","argsList","fnBody","method","unshift","valueIdent","cacheKey","data","getData","setData","getScopeInformationVisitor","ThisExpression","JSXIdentifier","isJSXMemberExpression","isJSXOpeningElement","MemberExpression","Identifier","isReferencedIdentifier","curr","hasOwnBinding","rename","parent","MetaProperty"],"sources":["../../src/path/conversion.ts"],"sourcesContent":["// This file contains methods that convert the path node into another node or some other type of data.\n\nimport {\n arrowFunctionExpression,\n assignmentExpression,\n binaryExpression,\n blockStatement,\n callExpression,\n conditionalExpression,\n expressionStatement,\n identifier,\n isIdentifier,\n jsxIdentifier,\n logicalExpression,\n LOGICAL_OPERATORS,\n memberExpression,\n metaProperty,\n numericLiteral,\n objectExpression,\n restElement,\n returnStatement,\n sequenceExpression,\n spreadElement,\n stringLiteral,\n super as _super,\n thisExpression,\n toExpression,\n unaryExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport environmentVisitor from \"@babel/helper-environment-visitor\";\nimport nameFunction from \"@babel/helper-function-name\";\nimport { merge as mergeVisitors } from \"../visitors.ts\";\nimport type NodePath from \"./index.ts\";\n\nexport function toComputedKey(this: NodePath) {\n let key;\n if (this.isMemberExpression()) {\n key = this.node.property;\n } else if (this.isProperty() || this.isMethod()) {\n key = this.node.key;\n } else {\n throw new ReferenceError(\"todo\");\n }\n\n // @ts-expect-error todo(flow->ts) computed does not exist in ClassPrivateProperty\n if (!this.node.computed) {\n if (isIdentifier(key)) key = stringLiteral(key.name);\n }\n\n return key;\n}\n\nexport function ensureBlock(\n this: NodePath<\n t.Loop | t.WithStatement | t.Function | t.LabeledStatement | t.CatchClause\n >,\n) {\n const body = this.get(\"body\");\n const bodyNode = body.node;\n\n if (Array.isArray(body)) {\n throw new Error(\"Can't convert array path to a block statement\");\n }\n if (!bodyNode) {\n throw new Error(\"Can't convert node without a body\");\n }\n\n if (body.isBlockStatement()) {\n return bodyNode;\n }\n\n const statements: Array<t.Statement> = [];\n\n let stringPath = \"body\";\n let key;\n let listKey;\n if (body.isStatement()) {\n listKey = \"body\";\n key = 0;\n statements.push(body.node);\n } else {\n stringPath += \".body.0\";\n if (this.isFunction()) {\n key = \"argument\";\n statements.push(returnStatement(body.node as t.Expression));\n } else {\n key = \"expression\";\n statements.push(expressionStatement(body.node as t.Expression));\n }\n }\n\n this.node.body = blockStatement(statements);\n const parentPath = this.get(stringPath) as NodePath;\n body.setup(\n parentPath,\n listKey\n ? // @ts-expect-error listKey must present in parent path\n parentPath.node[listKey]\n : parentPath.node,\n listKey,\n key,\n );\n\n return this.node;\n}\n\nif (!process.env.BABEL_8_BREAKING && !USE_ESM) {\n /**\n * Keeping this for backward-compatibility. You should use arrowFunctionToExpression() for >=7.x.\n */\n // eslint-disable-next-line no-restricted-globals\n exports.arrowFunctionToShadowed = function (this: NodePath) {\n if (!this.isArrowFunctionExpression()) return;\n\n this.arrowFunctionToExpression();\n };\n}\n\n/**\n * Given an arbitrary function, process its content as if it were an arrow function, moving references\n * to \"this\", \"arguments\", \"super\", and such into the function's parent scope. This method is useful if\n * you have wrapped some set of items in an IIFE or other function, but want \"this\", \"arguments\", and super\"\n * to continue behaving as expected.\n */\nexport function unwrapFunctionEnvironment(this: NodePath) {\n if (\n !this.isArrowFunctionExpression() &&\n !this.isFunctionExpression() &&\n !this.isFunctionDeclaration()\n ) {\n throw this.buildCodeFrameError(\n \"Can only unwrap the environment of a function.\",\n );\n }\n\n hoistFunctionEnvironment(this);\n}\n\nfunction setType<N extends t.Node, T extends N[\"type\"]>(\n path: NodePath<N>,\n type: T,\n): asserts path is NodePath<Extract<N, { type: T }>> {\n path.node.type = type;\n}\n\n/**\n * Convert a given arrow function into a normal ES5 function expression.\n */\nexport function arrowFunctionToExpression(\n this: NodePath<t.ArrowFunctionExpression>,\n {\n allowInsertArrow = true,\n allowInsertArrowWithRest = allowInsertArrow,\n noNewArrows = process.env.BABEL_8_BREAKING\n ? // TODO(Babel 8): Consider defaulting to `false` for spec compliance\n true\n : !arguments[0]?.specCompliant,\n }: {\n allowInsertArrow?: boolean | void;\n allowInsertArrowWithRest?: boolean | void;\n noNewArrows?: boolean;\n } = {},\n): NodePath<\n Exclude<t.Function, t.Method | t.ArrowFunctionExpression> | t.CallExpression\n> {\n if (!this.isArrowFunctionExpression()) {\n throw (this as NodePath).buildCodeFrameError(\n \"Cannot convert non-arrow function to a function expression.\",\n );\n }\n\n const { thisBinding, fnPath: fn } = hoistFunctionEnvironment(\n this,\n noNewArrows,\n allowInsertArrow,\n allowInsertArrowWithRest,\n );\n\n // @ts-expect-error TS requires explicit fn type annotation\n fn.ensureBlock();\n setType(fn, \"FunctionExpression\");\n\n if (!noNewArrows) {\n const checkBinding = thisBinding\n ? null\n : fn.scope.generateUidIdentifier(\"arrowCheckId\");\n if (checkBinding) {\n fn.parentPath.scope.push({\n id: checkBinding,\n init: objectExpression([]),\n });\n }\n\n fn.get(\"body\").unshiftContainer(\n \"body\",\n expressionStatement(\n callExpression(this.hub.addHelper(\"newArrowCheck\"), [\n thisExpression(),\n checkBinding\n ? identifier(checkBinding.name)\n : identifier(thisBinding),\n ]),\n ),\n );\n\n fn.replaceWith(\n callExpression(\n memberExpression(\n // @ts-expect-error TS can't infer nameFunction returns CallExpression | ArrowFunctionExpression here\n nameFunction(this, true) || fn.node,\n identifier(\"bind\"),\n ),\n [checkBinding ? identifier(checkBinding.name) : thisExpression()],\n ),\n );\n\n return fn.get(\"callee.object\");\n }\n\n return fn;\n}\n\nconst getSuperCallsVisitor = mergeVisitors<{\n allSuperCalls: NodePath<t.CallExpression>[];\n}>([\n {\n CallExpression(child, { allSuperCalls }) {\n if (!child.get(\"callee\").isSuper()) return;\n allSuperCalls.push(child);\n },\n },\n environmentVisitor,\n]);\n\n/**\n * Given a function, traverse its contents, and if there are references to \"this\", \"arguments\", \"super\",\n * or \"new.target\", ensure that these references reference the parent environment around this function.\n *\n * @returns `thisBinding`: the name of the injected reference to `this`; for example \"_this\"\n * @returns `fnPath`: the new path to the function node. This is different from the fnPath\n * parameter when the function node is wrapped in another node.\n */\nfunction hoistFunctionEnvironment(\n fnPath: NodePath<t.Function>,\n // TODO(Babel 8): Consider defaulting to `false` for spec compliance\n noNewArrows: boolean | void = true,\n allowInsertArrow: boolean | void = true,\n allowInsertArrowWithRest: boolean | void = true,\n): { thisBinding: string; fnPath: NodePath<t.Function> } {\n let arrowParent;\n let thisEnvFn: NodePath<t.Function> = fnPath.findParent(p => {\n if (p.isArrowFunctionExpression()) {\n arrowParent ??= p;\n return false;\n }\n return (\n p.isFunction() ||\n p.isProgram() ||\n p.isClassProperty({ static: false }) ||\n p.isClassPrivateProperty({ static: false })\n );\n }) as NodePath<t.Function>;\n const inConstructor = thisEnvFn.isClassMethod({ kind: \"constructor\" });\n\n if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) {\n if (arrowParent) {\n thisEnvFn = arrowParent;\n } else if (allowInsertArrow) {\n // It's safe to wrap this function in another and not hoist to the\n // top level because the 'this' binding is constant in class\n // properties (since 'super()' has already been called), so we don't\n // need to capture/reassign it at the top level.\n fnPath.replaceWith(\n callExpression(\n arrowFunctionExpression([], toExpression(fnPath.node)),\n [],\n ),\n );\n thisEnvFn = fnPath.get(\"callee\") as NodePath<t.ArrowFunctionExpression>;\n fnPath = thisEnvFn.get(\"body\") as NodePath<t.FunctionExpression>;\n } else {\n throw fnPath.buildCodeFrameError(\n \"Unable to transform arrow inside class property\",\n );\n }\n }\n\n const { thisPaths, argumentsPaths, newTargetPaths, superProps, superCalls } =\n getScopeInformation(fnPath);\n\n // Convert all super() calls in the constructor, if super is used in an arrow.\n if (inConstructor && superCalls.length > 0) {\n if (!allowInsertArrow) {\n throw superCalls[0].buildCodeFrameError(\n \"When using '@babel/plugin-transform-arrow-functions', \" +\n \"it's not possible to compile `super()` in an arrow function without compiling classes.\\n\" +\n \"Please add '@babel/plugin-transform-classes' to your Babel configuration.\",\n );\n }\n if (!allowInsertArrowWithRest) {\n // preset-env with target `since 2017` enables `transform-parameters` without `transform-classes`.\n throw superCalls[0].buildCodeFrameError(\n \"When using '@babel/plugin-transform-parameters', \" +\n \"it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.\\n\" +\n \"Please add '@babel/plugin-transform-classes' to your Babel configuration.\",\n );\n }\n const allSuperCalls: NodePath<t.CallExpression>[] = [];\n thisEnvFn.traverse(getSuperCallsVisitor, { allSuperCalls });\n const superBinding = getSuperBinding(thisEnvFn);\n allSuperCalls.forEach(superCall => {\n const callee = identifier(superBinding);\n callee.loc = superCall.node.callee.loc;\n\n superCall.get(\"callee\").replaceWith(callee);\n });\n }\n\n // Convert all \"arguments\" references in the arrow to point at the alias.\n if (argumentsPaths.length > 0) {\n const argumentsBinding = getBinding(thisEnvFn, \"arguments\", () => {\n const args = () => identifier(\"arguments\");\n if (thisEnvFn.scope.path.isProgram()) {\n return conditionalExpression(\n binaryExpression(\n \"===\",\n unaryExpression(\"typeof\", args()),\n stringLiteral(\"undefined\"),\n ),\n thisEnvFn.scope.buildUndefinedNode(),\n args(),\n );\n } else {\n return args();\n }\n });\n\n argumentsPaths.forEach(argumentsChild => {\n const argsRef = identifier(argumentsBinding);\n argsRef.loc = argumentsChild.node.loc;\n\n argumentsChild.replaceWith(argsRef);\n });\n }\n\n // Convert all \"new.target\" references in the arrow to point at the alias.\n if (newTargetPaths.length > 0) {\n const newTargetBinding = getBinding(thisEnvFn, \"newtarget\", () =>\n metaProperty(identifier(\"new\"), identifier(\"target\")),\n );\n\n newTargetPaths.forEach(targetChild => {\n const targetRef = identifier(newTargetBinding);\n targetRef.loc = targetChild.node.loc;\n\n targetChild.replaceWith(targetRef);\n });\n }\n\n // Convert all \"super.prop\" references to point at aliases.\n if (superProps.length > 0) {\n if (!allowInsertArrow) {\n throw superProps[0].buildCodeFrameError(\n \"When using '@babel/plugin-transform-arrow-functions', \" +\n \"it's not possible to compile `super.prop` in an arrow function without compiling classes.\\n\" +\n \"Please add '@babel/plugin-transform-classes' to your Babel configuration.\",\n );\n }\n\n const flatSuperProps: NodePath<t.MemberExpression>[] = superProps.reduce(\n (acc, superProp) => acc.concat(standardizeSuperProperty(superProp)),\n [],\n );\n\n flatSuperProps.forEach(superProp => {\n const key = superProp.node.computed\n ? \"\"\n : // @ts-expect-error super property must not contain private name\n superProp.get(\"property\").node.name;\n\n const superParentPath = superProp.parentPath;\n\n const isAssignment = superParentPath.isAssignmentExpression({\n left: superProp.node,\n });\n const isCall = superParentPath.isCallExpression({\n callee: superProp.node,\n });\n const isTaggedTemplate = superParentPath.isTaggedTemplateExpression({\n tag: superProp.node,\n });\n const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);\n\n const args: t.Expression[] = [];\n if (superProp.node.computed) {\n // SuperProperty must not be a private name\n args.push(superProp.get(\"property\").node as t.Expression);\n }\n\n if (isAssignment) {\n const value = superParentPath.node.right;\n args.push(value);\n }\n\n const call = callExpression(identifier(superBinding), args);\n\n if (isCall) {\n superParentPath.unshiftContainer(\"arguments\", thisExpression());\n superProp.replaceWith(memberExpression(call, identifier(\"call\")));\n\n thisPaths.push(\n superParentPath.get(\"arguments.0\") as NodePath<t.ThisExpression>,\n );\n } else if (isAssignment) {\n // Replace not only the super.prop, but the whole assignment\n superParentPath.replaceWith(call);\n } else if (isTaggedTemplate) {\n superProp.replaceWith(\n callExpression(memberExpression(call, identifier(\"bind\"), false), [\n thisExpression(),\n ]),\n );\n\n thisPaths.push(\n superProp.get(\"arguments.0\") as NodePath<t.ThisExpression>,\n );\n } else {\n superProp.replaceWith(call);\n }\n });\n }\n\n // Convert all \"this\" references in the arrow to point at the alias.\n let thisBinding: string | null;\n if (thisPaths.length > 0 || !noNewArrows) {\n thisBinding = getThisBinding(thisEnvFn, inConstructor);\n\n if (\n noNewArrows ||\n // In subclass constructors, still need to rewrite because \"this\" can't be bound in spec mode\n // because it might not have been initialized yet.\n (inConstructor && hasSuperClass(thisEnvFn))\n ) {\n thisPaths.forEach(thisChild => {\n const thisRef = thisChild.isJSX()\n ? jsxIdentifier(thisBinding)\n : identifier(thisBinding);\n\n thisRef.loc = thisChild.node.loc;\n thisChild.replaceWith(thisRef);\n });\n\n if (!noNewArrows) thisBinding = null;\n }\n }\n\n return { thisBinding, fnPath };\n}\n\ntype LogicalOp = Parameters<typeof logicalExpression>[0];\ntype BinaryOp = Parameters<typeof binaryExpression>[0];\n\nfunction isLogicalOp(op: string): op is LogicalOp {\n return LOGICAL_OPERATORS.includes(op);\n}\n\nfunction standardizeSuperProperty(\n superProp: NodePath<t.MemberExpression>,\n):\n | [NodePath<t.MemberExpression>]\n | [NodePath<t.MemberExpression>, NodePath<t.MemberExpression>] {\n if (\n superProp.parentPath.isAssignmentExpression() &&\n superProp.parentPath.node.operator !== \"=\"\n ) {\n const assignmentPath = superProp.parentPath;\n\n const op = assignmentPath.node.operator.slice(0, -1) as\n | LogicalOp\n | BinaryOp;\n\n const value = assignmentPath.node.right;\n\n const isLogicalAssignment = isLogicalOp(op);\n\n if (superProp.node.computed) {\n // from: super[foo] **= 4;\n // to: super[tmp = foo] = super[tmp] ** 4;\n\n // from: super[foo] ??= 4;\n // to: super[tmp = foo] ?? super[tmp] = 4;\n\n const tmp = superProp.scope.generateDeclaredUidIdentifier(\"tmp\");\n\n const object = superProp.node.object;\n const property = superProp.node.property as t.Expression;\n\n assignmentPath\n .get(\"left\")\n .replaceWith(\n memberExpression(\n object,\n assignmentExpression(\"=\", tmp, property),\n true /* computed */,\n ),\n );\n\n assignmentPath\n .get(\"right\")\n .replaceWith(\n rightExpression(\n isLogicalAssignment ? \"=\" : op,\n memberExpression(object, identifier(tmp.name), true /* computed */),\n value,\n ),\n );\n } else {\n // from: super.foo **= 4;\n // to: super.foo = super.foo ** 4;\n\n // from: super.foo ??= 4;\n // to: super.foo ?? super.foo = 4;\n\n const object = superProp.node.object;\n const property = superProp.node.property as t.Identifier;\n\n assignmentPath\n .get(\"left\")\n .replaceWith(memberExpression(object, property));\n\n assignmentPath\n .get(\"right\")\n .replaceWith(\n rightExpression(\n isLogicalAssignment ? \"=\" : op,\n memberExpression(object, identifier(property.name)),\n value,\n ),\n );\n }\n\n if (isLogicalAssignment) {\n assignmentPath.replaceWith(\n logicalExpression(\n op,\n assignmentPath.node.left as t.MemberExpression,\n assignmentPath.node.right,\n ),\n );\n } else {\n assignmentPath.node.operator = \"=\";\n }\n\n return [\n assignmentPath.get(\"left\") as NodePath<t.MemberExpression>,\n assignmentPath.get(\"right\").get(\"left\"),\n ];\n } else if (superProp.parentPath.isUpdateExpression()) {\n const updateExpr = superProp.parentPath;\n\n const tmp = superProp.scope.generateDeclaredUidIdentifier(\"tmp\");\n const computedKey = superProp.node.computed\n ? superProp.scope.generateDeclaredUidIdentifier(\"prop\")\n : null;\n\n const parts: t.Expression[] = [\n assignmentExpression(\n \"=\",\n tmp,\n memberExpression(\n superProp.node.object,\n computedKey\n ? assignmentExpression(\n \"=\",\n computedKey,\n superProp.node.property as t.Expression,\n )\n : superProp.node.property,\n superProp.node.computed,\n ),\n ),\n assignmentExpression(\n \"=\",\n memberExpression(\n superProp.node.object,\n computedKey ? identifier(computedKey.name) : superProp.node.property,\n superProp.node.computed,\n ),\n binaryExpression(\n // map `++` to `+`, and `--` to `-`\n superProp.parentPath.node.operator[0] as \"+\" | \"-\",\n identifier(tmp.name),\n numericLiteral(1),\n ),\n ),\n ];\n\n if (!superProp.parentPath.node.prefix) {\n parts.push(identifier(tmp.name));\n }\n\n updateExpr.replaceWith(sequenceExpression(parts));\n\n const left = updateExpr.get(\n \"expressions.0.right\",\n ) as NodePath<t.MemberExpression>;\n const right = updateExpr.get(\n \"expressions.1.left\",\n ) as NodePath<t.MemberExpression>;\n return [left, right];\n }\n\n return [superProp];\n\n function rightExpression(\n op: BinaryOp | \"=\",\n left: t.MemberExpression,\n right: t.Expression,\n ) {\n if (op === \"=\") {\n return assignmentExpression(\"=\", left, right);\n } else {\n return binaryExpression(op, left, right);\n }\n }\n}\n\nfunction hasSuperClass(thisEnvFn: NodePath<t.Function>) {\n return (\n thisEnvFn.isClassMethod() &&\n !!(thisEnvFn.parentPath.parentPath.node as t.Class).superClass\n );\n}\n\nconst assignSuperThisVisitor = mergeVisitors<{\n supers: WeakSet<t.CallExpression>;\n thisBinding: string;\n}>([\n {\n CallExpression(child, { supers, thisBinding }) {\n if (!child.get(\"callee\").isSuper()) return;\n if (supers.has(child.node)) return;\n supers.add(child.node);\n\n child.replaceWithMultiple([\n child.node,\n assignmentExpression(\"=\", identifier(thisBinding), identifier(\"this\")),\n ]);\n },\n },\n environmentVisitor,\n]);\n\n// Create a binding that evaluates to the \"this\" of the given function.\nfunction getThisBinding(\n thisEnvFn: NodePath<t.Function>,\n inConstructor: boolean,\n) {\n return getBinding(thisEnvFn, \"this\", thisBinding => {\n if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression();\n\n thisEnvFn.traverse(assignSuperThisVisitor, {\n supers: new WeakSet(),\n thisBinding,\n });\n });\n}\n\n// Create a binding for a function that will call \"super()\" with arguments passed through.\nfunction getSuperBinding(thisEnvFn: NodePath<t.Function>) {\n return getBinding(thisEnvFn, \"supercall\", () => {\n const argsBinding = thisEnvFn.scope.generateUidIdentifier(\"args\");\n return arrowFunctionExpression(\n [restElement(argsBinding)],\n callExpression(_super(), [spreadElement(identifier(argsBinding.name))]),\n );\n });\n}\n\n// Create a binding for a function that will call \"super.foo\" or \"super[foo]\".\nfunction getSuperPropBinding(\n thisEnvFn: NodePath<t.Function>,\n isAssignment: boolean,\n propName: string,\n) {\n const op = isAssignment ? \"set\" : \"get\";\n\n return getBinding(thisEnvFn, `superprop_${op}:${propName || \"\"}`, () => {\n const argsList = [];\n\n let fnBody;\n if (propName) {\n // () => super.foo\n fnBody = memberExpression(_super(), identifier(propName));\n } else {\n const method = thisEnvFn.scope.generateUidIdentifier(\"prop\");\n // (method) => super[method]\n argsList.unshift(method);\n fnBody = memberExpression(\n _super(),\n identifier(method.name),\n true /* computed */,\n );\n }\n\n if (isAssignment) {\n const valueIdent = thisEnvFn.scope.generateUidIdentifier(\"value\");\n argsList.push(valueIdent);\n\n fnBody = assignmentExpression(\"=\", fnBody, identifier(valueIdent.name));\n }\n\n return arrowFunctionExpression(argsList, fnBody);\n });\n}\n\nfunction getBinding(\n thisEnvFn: NodePath,\n key: string,\n init: (name: string) => t.Expression,\n) {\n const cacheKey = \"binding:\" + key;\n let data: string | undefined = thisEnvFn.getData(cacheKey);\n if (!data) {\n const id = thisEnvFn.scope.generateUidIdentifier(key);\n data = id.name;\n thisEnvFn.setData(cacheKey, data);\n\n thisEnvFn.scope.push({\n id: id,\n init: init(data),\n });\n }\n\n return data;\n}\n\ntype ScopeInfo = {\n thisPaths: NodePath<t.ThisExpression | t.JSXIdentifier>[];\n superCalls: NodePath<t.CallExpression>[];\n superProps: NodePath<t.MemberExpression>[];\n argumentsPaths: NodePath<t.Identifier | t.JSXIdentifier>[];\n newTargetPaths: NodePath<t.MetaProperty>[];\n};\n\nconst getScopeInformationVisitor = mergeVisitors<ScopeInfo>([\n {\n ThisExpression(child, { thisPaths }) {\n thisPaths.push(child);\n },\n JSXIdentifier(child, { thisPaths }) {\n if (child.node.name !== \"this\") return;\n if (\n !child.parentPath.isJSXMemberExpression({ object: child.node }) &&\n !child.parentPath.isJSXOpeningElement({ name: child.node })\n ) {\n return;\n }\n\n thisPaths.push(child);\n },\n CallExpression(child, { superCalls }) {\n if (child.get(\"callee\").isSuper()) superCalls.push(child);\n },\n MemberExpression(child, { superProps }) {\n if (child.get(\"object\").isSuper()) superProps.push(child);\n },\n Identifier(child, { argumentsPaths }) {\n if (!child.isReferencedIdentifier({ name: \"arguments\" })) return;\n\n let curr = child.scope;\n do {\n if (curr.hasOwnBinding(\"arguments\")) {\n curr.rename(\"arguments\");\n return;\n }\n if (curr.path.isFunction() && !curr.path.isArrowFunctionExpression()) {\n break;\n }\n } while ((curr = curr.parent));\n\n argumentsPaths.push(child);\n },\n MetaProperty(child, { newTargetPaths }) {\n if (!child.get(\"meta\").isIdentifier({ name: \"new\" })) return;\n if (!child.get(\"property\").isIdentifier({ name: \"target\" })) return;\n\n newTargetPaths.push(child);\n },\n },\n environmentVisitor,\n]);\n\nfunction getScopeInformation(fnPath: NodePath) {\n const thisPaths: ScopeInfo[\"thisPaths\"] = [];\n const argumentsPaths: ScopeInfo[\"argumentsPaths\"] = [];\n const newTargetPaths: ScopeInfo[\"newTargetPaths\"] = [];\n const superProps: ScopeInfo[\"superProps\"] = [];\n const superCalls: ScopeInfo[\"superCalls\"] = [];\n\n fnPath.traverse(getScopeInformationVisitor, {\n thisPaths,\n argumentsPaths,\n newTargetPaths,\n superProps,\n superCalls,\n });\n\n return {\n thisPaths,\n argumentsPaths,\n newTargetPaths,\n superProps,\n superCalls,\n };\n}\n"],"mappings":";;;;;;;;;AAEA,IAAAA,EAAA,GAAAC,OAAA;AA4BA,I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