@babel/traverse 7.0.0-beta.5 → 7.0.0-beta.53
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.
Potentially problematic release.
This version of @babel/traverse might be problematic. Click here for more details.
- package/README.md +9 -23
- package/lib/cache.js +5 -3
- package/lib/context.js +55 -91
- package/lib/hub.js +9 -4
- package/lib/index.js +36 -33
- package/lib/path/ancestry.js +37 -41
- package/lib/path/comments.js +22 -12
- package/lib/path/context.js +24 -48
- package/lib/path/conversion.js +170 -150
- package/lib/path/evaluation.js +108 -150
- package/lib/path/family.js +40 -43
- package/lib/path/index.js +99 -80
- package/lib/path/inference/index.js +39 -33
- package/lib/path/inference/inferer-reference.js +55 -49
- package/lib/path/inference/inferers.js +61 -49
- package/lib/path/introspection.js +105 -96
- package/lib/path/lib/hoister.js +63 -61
- package/lib/path/lib/removal-hooks.js +5 -3
- package/lib/path/lib/virtual-types.js +106 -66
- package/lib/path/modification.js +70 -68
- package/lib/path/removal.js +12 -5
- package/lib/path/replacement.js +76 -69
- package/lib/scope/binding.js +23 -23
- package/lib/scope/index.js +389 -487
- package/lib/scope/lib/renamer.js +71 -61
- package/lib/visitors.js +84 -124
- package/package.json +11 -10
package/lib/path/conversion.js
CHANGED
@@ -1,23 +1,41 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
exports
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
4
6
|
exports.toComputedKey = toComputedKey;
|
5
7
|
exports.ensureBlock = ensureBlock;
|
6
8
|
exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
|
7
9
|
exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
|
8
10
|
exports.arrowFunctionToExpression = arrowFunctionToExpression;
|
9
11
|
|
10
|
-
|
12
|
+
function t() {
|
13
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
11
14
|
|
12
|
-
|
15
|
+
t = function () {
|
16
|
+
return data;
|
17
|
+
};
|
18
|
+
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
|
22
|
+
function _helperFunctionName() {
|
23
|
+
const data = _interopRequireDefault(require("@babel/helper-function-name"));
|
24
|
+
|
25
|
+
_helperFunctionName = function () {
|
26
|
+
return data;
|
27
|
+
};
|
28
|
+
|
29
|
+
return data;
|
30
|
+
}
|
13
31
|
|
14
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
33
|
|
16
|
-
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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
34
|
+
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; } }
|
17
35
|
|
18
36
|
function toComputedKey() {
|
19
|
-
|
20
|
-
|
37
|
+
const node = this.node;
|
38
|
+
let key;
|
21
39
|
|
22
40
|
if (this.isMemberExpression()) {
|
23
41
|
key = node.property;
|
@@ -28,15 +46,15 @@ function toComputedKey() {
|
|
28
46
|
}
|
29
47
|
|
30
48
|
if (!node.computed) {
|
31
|
-
if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
|
49
|
+
if (t().isIdentifier(key)) key = t().stringLiteral(key.name);
|
32
50
|
}
|
33
51
|
|
34
52
|
return key;
|
35
53
|
}
|
36
54
|
|
37
55
|
function ensureBlock() {
|
38
|
-
|
39
|
-
|
56
|
+
const body = this.get("body");
|
57
|
+
const bodyNode = body.node;
|
40
58
|
|
41
59
|
if (Array.isArray(body)) {
|
42
60
|
throw new Error("Can't convert array path to a block statement");
|
@@ -50,10 +68,10 @@ function ensureBlock() {
|
|
50
68
|
return bodyNode;
|
51
69
|
}
|
52
70
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
71
|
+
const statements = [];
|
72
|
+
let stringPath = "body";
|
73
|
+
let key;
|
74
|
+
let listKey;
|
57
75
|
|
58
76
|
if (body.isStatement()) {
|
59
77
|
listKey = "body";
|
@@ -64,15 +82,15 @@ function ensureBlock() {
|
|
64
82
|
|
65
83
|
if (this.isFunction()) {
|
66
84
|
key = "argument";
|
67
|
-
statements.push(t.returnStatement(body.node));
|
85
|
+
statements.push(t().returnStatement(body.node));
|
68
86
|
} else {
|
69
87
|
key = "expression";
|
70
|
-
statements.push(t.expressionStatement(body.node));
|
88
|
+
statements.push(t().expressionStatement(body.node));
|
71
89
|
}
|
72
90
|
}
|
73
91
|
|
74
|
-
this.node.body = t.blockStatement(statements);
|
75
|
-
|
92
|
+
this.node.body = t().blockStatement(statements);
|
93
|
+
const parentPath = this.get(stringPath);
|
76
94
|
body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
|
77
95
|
return this.node;
|
78
96
|
}
|
@@ -90,117 +108,114 @@ function unwrapFunctionEnvironment() {
|
|
90
108
|
hoistFunctionEnvironment(this);
|
91
109
|
}
|
92
110
|
|
93
|
-
function arrowFunctionToExpression(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
_ref$specCompliant = _ref.specCompliant,
|
98
|
-
specCompliant = _ref$specCompliant === void 0 ? false : _ref$specCompliant;
|
99
|
-
|
111
|
+
function arrowFunctionToExpression({
|
112
|
+
allowInsertArrow = true,
|
113
|
+
specCompliant = false
|
114
|
+
} = {}) {
|
100
115
|
if (!this.isArrowFunctionExpression()) {
|
101
116
|
throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
|
102
117
|
}
|
103
118
|
|
104
|
-
|
119
|
+
const thisBinding = hoistFunctionEnvironment(this, specCompliant, allowInsertArrow);
|
105
120
|
this.ensureBlock();
|
106
121
|
this.node.type = "FunctionExpression";
|
107
122
|
|
108
123
|
if (specCompliant) {
|
109
|
-
|
124
|
+
const checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId");
|
110
125
|
|
111
126
|
if (checkBinding) {
|
112
127
|
this.parentPath.scope.push({
|
113
128
|
id: checkBinding,
|
114
|
-
init: t.objectExpression([])
|
129
|
+
init: t().objectExpression([])
|
115
130
|
});
|
116
131
|
}
|
117
132
|
|
118
|
-
this.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(this.hub.file.addHelper("newArrowCheck"), [t.thisExpression(), checkBinding ? t.identifier(checkBinding.name) : t.identifier(thisBinding)])));
|
119
|
-
this.replaceWith(t.callExpression(t.memberExpression((0, _helperFunctionName.default)(this) || this.node, t.identifier("bind")), [checkBinding ? t.identifier(checkBinding.name) : t.thisExpression()]));
|
133
|
+
this.get("body").unshiftContainer("body", t().expressionStatement(t().callExpression(this.hub.file.addHelper("newArrowCheck"), [t().thisExpression(), checkBinding ? t().identifier(checkBinding.name) : t().identifier(thisBinding)])));
|
134
|
+
this.replaceWith(t().callExpression(t().memberExpression((0, _helperFunctionName().default)(this, true) || this.node, t().identifier("bind")), [checkBinding ? t().identifier(checkBinding.name) : t().thisExpression()]));
|
120
135
|
}
|
121
136
|
}
|
122
137
|
|
123
|
-
function hoistFunctionEnvironment(fnPath, specCompliant, allowInsertArrow) {
|
124
|
-
|
125
|
-
specCompliant = false;
|
126
|
-
}
|
127
|
-
|
128
|
-
if (allowInsertArrow === void 0) {
|
129
|
-
allowInsertArrow = true;
|
130
|
-
}
|
131
|
-
|
132
|
-
var thisEnvFn = fnPath.findParent(function (p) {
|
138
|
+
function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArrow = true) {
|
139
|
+
const thisEnvFn = fnPath.findParent(p => {
|
133
140
|
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
|
134
141
|
static: false
|
135
142
|
});
|
136
143
|
});
|
137
|
-
|
144
|
+
const inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor";
|
138
145
|
|
139
146
|
if (thisEnvFn.isClassProperty()) {
|
140
147
|
throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
|
141
148
|
}
|
142
149
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
150
|
+
const {
|
151
|
+
thisPaths,
|
152
|
+
argumentsPaths,
|
153
|
+
newTargetPaths,
|
154
|
+
superProps,
|
155
|
+
superCalls
|
156
|
+
} = getScopeInformation(fnPath);
|
149
157
|
|
150
158
|
if (inConstructor && superCalls.length > 0) {
|
151
159
|
if (!allowInsertArrow) {
|
152
160
|
throw superCalls[0].buildCodeFrameError("Unable to handle nested super() usage in arrow");
|
153
161
|
}
|
154
162
|
|
155
|
-
|
163
|
+
const allSuperCalls = [];
|
156
164
|
thisEnvFn.traverse({
|
157
|
-
Function
|
165
|
+
Function(child) {
|
158
166
|
if (child.isArrowFunctionExpression()) return;
|
159
167
|
child.skip();
|
160
168
|
},
|
161
|
-
|
169
|
+
|
170
|
+
ClassProperty(child) {
|
162
171
|
if (child.node.static) return;
|
163
172
|
child.skip();
|
164
173
|
},
|
165
|
-
|
174
|
+
|
175
|
+
CallExpression(child) {
|
166
176
|
if (!child.get("callee").isSuper()) return;
|
167
177
|
allSuperCalls.push(child);
|
168
178
|
}
|
179
|
+
|
169
180
|
});
|
170
|
-
|
171
|
-
allSuperCalls.forEach(
|
172
|
-
|
181
|
+
const superBinding = getSuperBinding(thisEnvFn);
|
182
|
+
allSuperCalls.forEach(superCall => {
|
183
|
+
const callee = t().identifier(superBinding);
|
184
|
+
callee.loc = superCall.node.callee.loc;
|
185
|
+
superCall.get("callee").replaceWith(callee);
|
173
186
|
});
|
174
187
|
}
|
175
188
|
|
176
|
-
|
189
|
+
let thisBinding;
|
177
190
|
|
178
191
|
if (thisPaths.length > 0 || specCompliant) {
|
179
192
|
thisBinding = getThisBinding(thisEnvFn, inConstructor);
|
180
193
|
|
181
194
|
if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) {
|
182
|
-
thisPaths.forEach(
|
183
|
-
thisChild.
|
195
|
+
thisPaths.forEach(thisChild => {
|
196
|
+
const thisRef = thisChild.isJSX() ? t().jsxIdentifier(thisBinding) : t().identifier(thisBinding);
|
197
|
+
thisRef.loc = thisChild.node.loc;
|
198
|
+
thisChild.replaceWith(thisRef);
|
184
199
|
});
|
185
200
|
if (specCompliant) thisBinding = null;
|
186
201
|
}
|
187
202
|
}
|
188
203
|
|
189
204
|
if (argumentsPaths.length > 0) {
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
argumentsChild.replaceWith(
|
205
|
+
const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t().identifier("arguments"));
|
206
|
+
argumentsPaths.forEach(argumentsChild => {
|
207
|
+
const argsRef = t().identifier(argumentsBinding);
|
208
|
+
argsRef.loc = argumentsChild.node.loc;
|
209
|
+
argumentsChild.replaceWith(argsRef);
|
195
210
|
});
|
196
211
|
}
|
197
212
|
|
198
213
|
if (newTargetPaths.length > 0) {
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
214
|
+
const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t().metaProperty(t().identifier("new"), t().identifier("target")));
|
215
|
+
newTargetPaths.forEach(targetChild => {
|
216
|
+
const targetRef = t().identifier(newTargetBinding);
|
217
|
+
targetRef.loc = targetChild.node.loc;
|
218
|
+
targetChild.replaceWith(targetRef);
|
204
219
|
});
|
205
220
|
}
|
206
221
|
|
@@ -209,43 +224,39 @@ function hoistFunctionEnvironment(fnPath, specCompliant, allowInsertArrow) {
|
|
209
224
|
throw superProps[0].buildCodeFrameError("Unable to handle nested super.prop usage");
|
210
225
|
}
|
211
226
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
flatSuperProps.forEach(function (superProp) {
|
216
|
-
var key = superProp.node.computed ? "" : superProp.get("property").node.name;
|
227
|
+
const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []);
|
228
|
+
flatSuperProps.forEach(superProp => {
|
229
|
+
const key = superProp.node.computed ? "" : superProp.get("property").node.name;
|
217
230
|
|
218
231
|
if (superProp.parentPath.isCallExpression({
|
219
232
|
callee: superProp.node
|
220
233
|
})) {
|
221
|
-
|
234
|
+
const superBinding = getSuperPropCallBinding(thisEnvFn, key);
|
222
235
|
|
223
236
|
if (superProp.node.computed) {
|
224
|
-
|
225
|
-
superProp.replaceWith(t.identifier(
|
237
|
+
const prop = superProp.get("property").node;
|
238
|
+
superProp.replaceWith(t().identifier(superBinding));
|
226
239
|
superProp.parentPath.node.arguments.unshift(prop);
|
227
240
|
} else {
|
228
|
-
superProp.replaceWith(t.identifier(
|
241
|
+
superProp.replaceWith(t().identifier(superBinding));
|
229
242
|
}
|
230
243
|
} else {
|
231
|
-
|
244
|
+
const isAssignment = superProp.parentPath.isAssignmentExpression({
|
232
245
|
left: superProp.node
|
233
246
|
});
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
var args = [];
|
247
|
+
const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
|
248
|
+
const args = [];
|
238
249
|
|
239
250
|
if (superProp.node.computed) {
|
240
251
|
args.push(superProp.get("property").node);
|
241
252
|
}
|
242
253
|
|
243
254
|
if (isAssignment) {
|
244
|
-
|
255
|
+
const value = superProp.parentPath.node.right;
|
245
256
|
args.push(value);
|
246
|
-
superProp.parentPath.replaceWith(t.callExpression(t.identifier(
|
257
|
+
superProp.parentPath.replaceWith(t().callExpression(t().identifier(superBinding), args));
|
247
258
|
} else {
|
248
|
-
superProp.replaceWith(t.callExpression(t.identifier(
|
259
|
+
superProp.replaceWith(t().callExpression(t().identifier(superBinding), args));
|
249
260
|
}
|
250
261
|
}
|
251
262
|
});
|
@@ -256,36 +267,34 @@ function hoistFunctionEnvironment(fnPath, specCompliant, allowInsertArrow) {
|
|
256
267
|
|
257
268
|
function standardizeSuperProperty(superProp) {
|
258
269
|
if (superProp.parentPath.isAssignmentExpression() && superProp.parentPath.node.operator !== "=") {
|
259
|
-
|
260
|
-
|
261
|
-
|
270
|
+
const assignmentPath = superProp.parentPath;
|
271
|
+
const op = assignmentPath.node.operator.slice(0, -1);
|
272
|
+
const value = assignmentPath.node.right;
|
262
273
|
assignmentPath.node.operator = "=";
|
263
274
|
|
264
275
|
if (superProp.node.computed) {
|
265
|
-
|
266
|
-
assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, t.assignmentExpression("=", tmp, superProp.node.property), true));
|
267
|
-
assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(tmp.name), true), value));
|
276
|
+
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
277
|
+
assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, t().assignmentExpression("=", tmp, superProp.node.property), true));
|
278
|
+
assignmentPath.get("right").replaceWith(t().binaryExpression(op, t().memberExpression(superProp.node.object, t().identifier(tmp.name), true), value));
|
268
279
|
} else {
|
269
|
-
assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, superProp.node.property));
|
270
|
-
assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(superProp.node.property.name)), value));
|
280
|
+
assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, superProp.node.property));
|
281
|
+
assignmentPath.get("right").replaceWith(t().binaryExpression(op, t().memberExpression(superProp.node.object, t().identifier(superProp.node.property.name)), value));
|
271
282
|
}
|
272
283
|
|
273
284
|
return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
|
274
285
|
} else if (superProp.parentPath.isUpdateExpression()) {
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
var computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
|
280
|
-
var parts = [t.assignmentExpression("=", _tmp, t.memberExpression(superProp.node.object, computedKey ? t.assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), t.assignmentExpression("=", t.memberExpression(superProp.node.object, computedKey ? t.identifier(computedKey.name) : superProp.node.property, superProp.node.computed), t.binaryExpression("+", t.identifier(_tmp.name), t.numericLiteral(1)))];
|
286
|
+
const updateExpr = superProp.parentPath;
|
287
|
+
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
288
|
+
const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
|
289
|
+
const parts = [t().assignmentExpression("=", tmp, t().memberExpression(superProp.node.object, computedKey ? t().assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), t().assignmentExpression("=", t().memberExpression(superProp.node.object, computedKey ? t().identifier(computedKey.name) : superProp.node.property, superProp.node.computed), t().binaryExpression("+", t().identifier(tmp.name), t().numericLiteral(1)))];
|
281
290
|
|
282
291
|
if (!superProp.parentPath.node.prefix) {
|
283
|
-
parts.push(t.identifier(
|
292
|
+
parts.push(t().identifier(tmp.name));
|
284
293
|
}
|
285
294
|
|
286
|
-
updateExpr.replaceWith(t.sequenceExpression(parts));
|
287
|
-
|
288
|
-
|
295
|
+
updateExpr.replaceWith(t().sequenceExpression(parts));
|
296
|
+
const left = updateExpr.get("expressions.0.right");
|
297
|
+
const right = updateExpr.get("expressions.1.left");
|
289
298
|
return [left, right];
|
290
299
|
}
|
291
300
|
|
@@ -297,83 +306,86 @@ function hasSuperClass(thisEnvFn) {
|
|
297
306
|
}
|
298
307
|
|
299
308
|
function getThisBinding(thisEnvFn, inConstructor) {
|
300
|
-
return getBinding(thisEnvFn, "this",
|
301
|
-
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression();
|
302
|
-
|
309
|
+
return getBinding(thisEnvFn, "this", thisBinding => {
|
310
|
+
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t().thisExpression();
|
311
|
+
const supers = new WeakSet();
|
303
312
|
thisEnvFn.traverse({
|
304
|
-
Function
|
313
|
+
Function(child) {
|
305
314
|
if (child.isArrowFunctionExpression()) return;
|
306
315
|
child.skip();
|
307
316
|
},
|
308
|
-
|
317
|
+
|
318
|
+
ClassProperty(child) {
|
309
319
|
if (child.node.static) return;
|
310
320
|
child.skip();
|
311
321
|
},
|
312
|
-
|
322
|
+
|
323
|
+
CallExpression(child) {
|
313
324
|
if (!child.get("callee").isSuper()) return;
|
314
325
|
if (supers.has(child.node)) return;
|
315
326
|
supers.add(child.node);
|
316
|
-
child.replaceWith(t.assignmentExpression("=", t.identifier(thisBinding), child.node));
|
327
|
+
child.replaceWith(t().assignmentExpression("=", t().identifier(thisBinding), child.node));
|
317
328
|
}
|
329
|
+
|
318
330
|
});
|
319
331
|
});
|
320
332
|
}
|
321
333
|
|
322
334
|
function getSuperBinding(thisEnvFn) {
|
323
|
-
return getBinding(thisEnvFn, "supercall",
|
324
|
-
|
325
|
-
return t.arrowFunctionExpression([t.restElement(argsBinding)], t.callExpression(t.super(), [t.spreadElement(t.identifier(argsBinding.name))]));
|
335
|
+
return getBinding(thisEnvFn, "supercall", () => {
|
336
|
+
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
|
337
|
+
return t().arrowFunctionExpression([t().restElement(argsBinding)], t().callExpression(t().super(), [t().spreadElement(t().identifier(argsBinding.name))]));
|
326
338
|
});
|
327
339
|
}
|
328
340
|
|
329
341
|
function getSuperPropCallBinding(thisEnvFn, propName) {
|
330
|
-
return getBinding(thisEnvFn,
|
331
|
-
|
332
|
-
|
333
|
-
|
342
|
+
return getBinding(thisEnvFn, `superprop_call:${propName || ""}`, () => {
|
343
|
+
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
|
344
|
+
const argsList = [t().restElement(argsBinding)];
|
345
|
+
let fnBody;
|
334
346
|
|
335
347
|
if (propName) {
|
336
|
-
fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(propName)), [t.spreadElement(t.identifier(argsBinding.name))]);
|
348
|
+
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(propName)), [t().spreadElement(t().identifier(argsBinding.name))]);
|
337
349
|
} else {
|
338
|
-
|
350
|
+
const method = thisEnvFn.scope.generateUidIdentifier("prop");
|
339
351
|
argsList.unshift(method);
|
340
|
-
fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(method.name), true), [t.spreadElement(t.identifier(argsBinding.name))]);
|
352
|
+
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(method.name), true), [t().spreadElement(t().identifier(argsBinding.name))]);
|
341
353
|
}
|
342
354
|
|
343
|
-
return t.arrowFunctionExpression(argsList, fnBody);
|
355
|
+
return t().arrowFunctionExpression(argsList, fnBody);
|
344
356
|
});
|
345
357
|
}
|
346
358
|
|
347
359
|
function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
|
348
|
-
|
349
|
-
return getBinding(thisEnvFn,
|
350
|
-
|
351
|
-
|
360
|
+
const op = isAssignment ? "set" : "get";
|
361
|
+
return getBinding(thisEnvFn, `superprop_${op}:${propName || ""}`, () => {
|
362
|
+
const argsList = [];
|
363
|
+
let fnBody;
|
352
364
|
|
353
365
|
if (propName) {
|
354
|
-
fnBody = t.memberExpression(t.super(), t.identifier(propName));
|
366
|
+
fnBody = t().memberExpression(t().super(), t().identifier(propName));
|
355
367
|
} else {
|
356
|
-
|
368
|
+
const method = thisEnvFn.scope.generateUidIdentifier("prop");
|
357
369
|
argsList.unshift(method);
|
358
|
-
fnBody = t.memberExpression(t.super(), t.identifier(method.name), true);
|
370
|
+
fnBody = t().memberExpression(t().super(), t().identifier(method.name), true);
|
359
371
|
}
|
360
372
|
|
361
373
|
if (isAssignment) {
|
362
|
-
|
374
|
+
const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
|
363
375
|
argsList.push(valueIdent);
|
364
|
-
fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name));
|
376
|
+
fnBody = t().assignmentExpression("=", fnBody, t().identifier(valueIdent.name));
|
365
377
|
}
|
366
378
|
|
367
|
-
return t.arrowFunctionExpression(argsList, fnBody);
|
379
|
+
return t().arrowFunctionExpression(argsList, fnBody);
|
368
380
|
});
|
369
381
|
}
|
370
382
|
|
371
383
|
function getBinding(thisEnvFn, key, init) {
|
372
|
-
|
373
|
-
|
384
|
+
const cacheKey = "binding:" + key;
|
385
|
+
let data = thisEnvFn.getData(cacheKey);
|
374
386
|
|
375
387
|
if (!data) {
|
376
|
-
|
388
|
+
const id = thisEnvFn.scope.generateUidIdentifier(key);
|
377
389
|
data = id.name;
|
378
390
|
thisEnvFn.setData(cacheKey, data);
|
379
391
|
thisEnvFn.scope.push({
|
@@ -386,24 +398,27 @@ function getBinding(thisEnvFn, key, init) {
|
|
386
398
|
}
|
387
399
|
|
388
400
|
function getScopeInformation(fnPath) {
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
401
|
+
const thisPaths = [];
|
402
|
+
const argumentsPaths = [];
|
403
|
+
const newTargetPaths = [];
|
404
|
+
const superProps = [];
|
405
|
+
const superCalls = [];
|
394
406
|
fnPath.traverse({
|
395
|
-
ClassProperty
|
407
|
+
ClassProperty(child) {
|
396
408
|
if (child.node.static) return;
|
397
409
|
child.skip();
|
398
410
|
},
|
399
|
-
|
411
|
+
|
412
|
+
Function(child) {
|
400
413
|
if (child.isArrowFunctionExpression()) return;
|
401
414
|
child.skip();
|
402
415
|
},
|
403
|
-
|
416
|
+
|
417
|
+
ThisExpression(child) {
|
404
418
|
thisPaths.push(child);
|
405
419
|
},
|
406
|
-
|
420
|
+
|
421
|
+
JSXIdentifier(child) {
|
407
422
|
if (child.node.name !== "this") return;
|
408
423
|
|
409
424
|
if (!child.parentPath.isJSXMemberExpression({
|
@@ -416,17 +431,21 @@ function getScopeInformation(fnPath) {
|
|
416
431
|
|
417
432
|
thisPaths.push(child);
|
418
433
|
},
|
419
|
-
|
434
|
+
|
435
|
+
CallExpression(child) {
|
420
436
|
if (child.get("callee").isSuper()) superCalls.push(child);
|
421
437
|
},
|
422
|
-
|
438
|
+
|
439
|
+
MemberExpression(child) {
|
423
440
|
if (child.get("object").isSuper()) superProps.push(child);
|
424
441
|
},
|
425
|
-
|
442
|
+
|
443
|
+
ReferencedIdentifier(child) {
|
426
444
|
if (child.node.name !== "arguments") return;
|
427
445
|
argumentsPaths.push(child);
|
428
446
|
},
|
429
|
-
|
447
|
+
|
448
|
+
MetaProperty(child) {
|
430
449
|
if (!child.get("meta").isIdentifier({
|
431
450
|
name: "new"
|
432
451
|
})) return;
|
@@ -435,12 +454,13 @@ function getScopeInformation(fnPath) {
|
|
435
454
|
})) return;
|
436
455
|
newTargetPaths.push(child);
|
437
456
|
}
|
457
|
+
|
438
458
|
});
|
439
459
|
return {
|
440
|
-
thisPaths
|
441
|
-
argumentsPaths
|
442
|
-
newTargetPaths
|
443
|
-
superProps
|
444
|
-
superCalls
|
460
|
+
thisPaths,
|
461
|
+
argumentsPaths,
|
462
|
+
newTargetPaths,
|
463
|
+
superProps,
|
464
|
+
superCalls
|
445
465
|
};
|
446
466
|
}
|