@babel/traverse 7.0.0-beta.31

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.

@@ -0,0 +1,269 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.call = call;
5
+ exports._call = _call;
6
+ exports.isBlacklisted = isBlacklisted;
7
+ exports.visit = visit;
8
+ exports.skip = skip;
9
+ exports.skipKey = skipKey;
10
+ exports.stop = stop;
11
+ exports.setScope = setScope;
12
+ exports.setContext = setContext;
13
+ exports.resync = resync;
14
+ exports._resyncParent = _resyncParent;
15
+ exports._resyncKey = _resyncKey;
16
+ exports._resyncList = _resyncList;
17
+ exports._resyncRemoved = _resyncRemoved;
18
+ exports.popContext = popContext;
19
+ exports.pushContext = pushContext;
20
+ exports.setup = setup;
21
+ exports.setKey = setKey;
22
+ exports.requeue = requeue;
23
+ exports._getQueueContexts = _getQueueContexts;
24
+
25
+ var _index = _interopRequireDefault(require("../index"));
26
+
27
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
+
29
+ function call(key) {
30
+ var opts = this.opts;
31
+ this.debug(key);
32
+
33
+ if (this.node) {
34
+ if (this._call(opts[key])) return true;
35
+ }
36
+
37
+ if (this.node) {
38
+ return this._call(opts[this.node.type] && opts[this.node.type][key]);
39
+ }
40
+
41
+ return false;
42
+ }
43
+
44
+ function _call(fns) {
45
+ if (!fns) return false;
46
+
47
+ for (var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
48
+ var _ref;
49
+
50
+ if (_isArray) {
51
+ if (_i >= _iterator.length) break;
52
+ _ref = _iterator[_i++];
53
+ } else {
54
+ _i = _iterator.next();
55
+ if (_i.done) break;
56
+ _ref = _i.value;
57
+ }
58
+
59
+ var _fn = _ref;
60
+ if (!_fn) continue;
61
+ var node = this.node;
62
+ if (!node) return true;
63
+
64
+ var ret = _fn.call(this.state, this, this.state);
65
+
66
+ if (ret) {
67
+ throw new Error("Unexpected return value from visitor method " + _fn);
68
+ }
69
+
70
+ if (this.node !== node) return true;
71
+ if (this.shouldStop || this.shouldSkip || this.removed) return true;
72
+ }
73
+
74
+ return false;
75
+ }
76
+
77
+ function isBlacklisted() {
78
+ var blacklist = this.opts.blacklist;
79
+ return blacklist && blacklist.indexOf(this.node.type) > -1;
80
+ }
81
+
82
+ function visit() {
83
+ if (!this.node) {
84
+ return false;
85
+ }
86
+
87
+ if (this.isBlacklisted()) {
88
+ return false;
89
+ }
90
+
91
+ if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {
92
+ return false;
93
+ }
94
+
95
+ if (this.call("enter") || this.shouldSkip) {
96
+ this.debug("Skip...");
97
+ return this.shouldStop;
98
+ }
99
+
100
+ this.debug("Recursing into...");
101
+
102
+ _index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
103
+
104
+ this.call("exit");
105
+ return this.shouldStop;
106
+ }
107
+
108
+ function skip() {
109
+ this.shouldSkip = true;
110
+ }
111
+
112
+ function skipKey(key) {
113
+ this.skipKeys[key] = true;
114
+ }
115
+
116
+ function stop() {
117
+ this.shouldStop = true;
118
+ this.shouldSkip = true;
119
+ }
120
+
121
+ function setScope() {
122
+ if (this.opts && this.opts.noScope) return;
123
+ var path = this.parentPath;
124
+ var target;
125
+
126
+ while (path && !target) {
127
+ if (path.opts && path.opts.noScope) return;
128
+ target = path.scope;
129
+ path = path.parentPath;
130
+ }
131
+
132
+ this.scope = this.getScope(target);
133
+ if (this.scope) this.scope.init();
134
+ }
135
+
136
+ function setContext(context) {
137
+ this.shouldSkip = false;
138
+ this.shouldStop = false;
139
+ this.removed = false;
140
+ this.skipKeys = {};
141
+
142
+ if (context) {
143
+ this.context = context;
144
+ this.state = context.state;
145
+ this.opts = context.opts;
146
+ }
147
+
148
+ this.setScope();
149
+ return this;
150
+ }
151
+
152
+ function resync() {
153
+ if (this.removed) return;
154
+
155
+ this._resyncParent();
156
+
157
+ this._resyncList();
158
+
159
+ this._resyncKey();
160
+ }
161
+
162
+ function _resyncParent() {
163
+ if (this.parentPath) {
164
+ this.parent = this.parentPath.node;
165
+ }
166
+ }
167
+
168
+ function _resyncKey() {
169
+ if (!this.container) return;
170
+ if (this.node === this.container[this.key]) return;
171
+
172
+ if (Array.isArray(this.container)) {
173
+ for (var i = 0; i < this.container.length; i++) {
174
+ if (this.container[i] === this.node) {
175
+ return this.setKey(i);
176
+ }
177
+ }
178
+ } else {
179
+ for (var key in this.container) {
180
+ if (this.container[key] === this.node) {
181
+ return this.setKey(key);
182
+ }
183
+ }
184
+ }
185
+
186
+ this.key = null;
187
+ }
188
+
189
+ function _resyncList() {
190
+ if (!this.parent || !this.inList) return;
191
+ var newContainer = this.parent[this.listKey];
192
+ if (this.container === newContainer) return;
193
+ this.container = newContainer || null;
194
+ }
195
+
196
+ function _resyncRemoved() {
197
+ if (this.key == null || !this.container || this.container[this.key] !== this.node) {
198
+ this._markRemoved();
199
+ }
200
+ }
201
+
202
+ function popContext() {
203
+ this.contexts.pop();
204
+
205
+ if (this.contexts.length > 0) {
206
+ this.setContext(this.contexts[this.contexts.length - 1]);
207
+ } else {
208
+ this.setContext(undefined);
209
+ }
210
+ }
211
+
212
+ function pushContext(context) {
213
+ this.contexts.push(context);
214
+ this.setContext(context);
215
+ }
216
+
217
+ function setup(parentPath, container, listKey, key) {
218
+ this.inList = !!listKey;
219
+ this.listKey = listKey;
220
+ this.parentKey = listKey || key;
221
+ this.container = container;
222
+ this.parentPath = parentPath || this.parentPath;
223
+ this.setKey(key);
224
+ }
225
+
226
+ function setKey(key) {
227
+ this.key = key;
228
+ this.node = this.container[this.key];
229
+ this.type = this.node && this.node.type;
230
+ }
231
+
232
+ function requeue(pathToQueue) {
233
+ if (pathToQueue === void 0) {
234
+ pathToQueue = this;
235
+ }
236
+
237
+ if (pathToQueue.removed) return;
238
+ var contexts = this.contexts;
239
+
240
+ for (var _iterator2 = contexts, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
241
+ var _ref2;
242
+
243
+ if (_isArray2) {
244
+ if (_i2 >= _iterator2.length) break;
245
+ _ref2 = _iterator2[_i2++];
246
+ } else {
247
+ _i2 = _iterator2.next();
248
+ if (_i2.done) break;
249
+ _ref2 = _i2.value;
250
+ }
251
+
252
+ var _context = _ref2;
253
+
254
+ _context.maybeQueue(pathToQueue);
255
+ }
256
+ }
257
+
258
+ function _getQueueContexts() {
259
+ var path = this;
260
+ var contexts = this.contexts;
261
+
262
+ while (!contexts.length) {
263
+ path = path.parentPath;
264
+ if (!path) break;
265
+ contexts = path.contexts;
266
+ }
267
+
268
+ return contexts;
269
+ }
@@ -0,0 +1,446 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.toComputedKey = toComputedKey;
5
+ exports.ensureBlock = ensureBlock;
6
+ exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
7
+ exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
8
+ exports.arrowFunctionToExpression = arrowFunctionToExpression;
9
+
10
+ var t = _interopRequireWildcard(require("@babel/types"));
11
+
12
+ var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
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; } }
17
+
18
+ function toComputedKey() {
19
+ var node = this.node;
20
+ var key;
21
+
22
+ if (this.isMemberExpression()) {
23
+ key = node.property;
24
+ } else if (this.isProperty() || this.isMethod()) {
25
+ key = node.key;
26
+ } else {
27
+ throw new ReferenceError("todo");
28
+ }
29
+
30
+ if (!node.computed) {
31
+ if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
32
+ }
33
+
34
+ return key;
35
+ }
36
+
37
+ function ensureBlock() {
38
+ var body = this.get("body");
39
+ var bodyNode = body.node;
40
+
41
+ if (Array.isArray(body)) {
42
+ throw new Error("Can't convert array path to a block statement");
43
+ }
44
+
45
+ if (!bodyNode) {
46
+ throw new Error("Can't convert node without a body");
47
+ }
48
+
49
+ if (body.isBlockStatement()) {
50
+ return bodyNode;
51
+ }
52
+
53
+ var statements = [];
54
+ var stringPath = "body";
55
+ var key;
56
+ var listKey;
57
+
58
+ if (body.isStatement()) {
59
+ listKey = "body";
60
+ key = 0;
61
+ statements.push(body.node);
62
+ } else {
63
+ stringPath += ".body.0";
64
+
65
+ if (this.isFunction()) {
66
+ key = "argument";
67
+ statements.push(t.returnStatement(body.node));
68
+ } else {
69
+ key = "expression";
70
+ statements.push(t.expressionStatement(body.node));
71
+ }
72
+ }
73
+
74
+ this.node.body = t.blockStatement(statements);
75
+ var parentPath = this.get(stringPath);
76
+ body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
77
+ return this.node;
78
+ }
79
+
80
+ function arrowFunctionToShadowed() {
81
+ if (!this.isArrowFunctionExpression()) return;
82
+ this.arrowFunctionToExpression();
83
+ }
84
+
85
+ function unwrapFunctionEnvironment() {
86
+ if (!this.isArrowFunctionExpression() && !this.isFunctionExpression() && !this.isFunctionDeclaration()) {
87
+ throw this.buildCodeFrameError("Can only unwrap the environment of a function.");
88
+ }
89
+
90
+ hoistFunctionEnvironment(this);
91
+ }
92
+
93
+ function arrowFunctionToExpression(_temp) {
94
+ var _ref = _temp === void 0 ? {} : _temp,
95
+ _ref$allowInsertArrow = _ref.allowInsertArrow,
96
+ allowInsertArrow = _ref$allowInsertArrow === void 0 ? true : _ref$allowInsertArrow,
97
+ _ref$specCompliant = _ref.specCompliant,
98
+ specCompliant = _ref$specCompliant === void 0 ? false : _ref$specCompliant;
99
+
100
+ if (!this.isArrowFunctionExpression()) {
101
+ throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
102
+ }
103
+
104
+ var thisBinding = hoistFunctionEnvironment(this, specCompliant, allowInsertArrow);
105
+ this.ensureBlock();
106
+ this.node.type = "FunctionExpression";
107
+
108
+ if (specCompliant) {
109
+ var checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId");
110
+
111
+ if (checkBinding) {
112
+ this.parentPath.scope.push({
113
+ id: checkBinding,
114
+ init: t.objectExpression([])
115
+ });
116
+ }
117
+
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()]));
120
+ }
121
+ }
122
+
123
+ function hoistFunctionEnvironment(fnPath, specCompliant, allowInsertArrow) {
124
+ if (specCompliant === void 0) {
125
+ specCompliant = false;
126
+ }
127
+
128
+ if (allowInsertArrow === void 0) {
129
+ allowInsertArrow = true;
130
+ }
131
+
132
+ var thisEnvFn = fnPath.findParent(function (p) {
133
+ return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
134
+ static: false
135
+ });
136
+ });
137
+ var inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor";
138
+
139
+ if (thisEnvFn.isClassProperty()) {
140
+ throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
141
+ }
142
+
143
+ var _getScopeInformation = getScopeInformation(fnPath),
144
+ thisPaths = _getScopeInformation.thisPaths,
145
+ argumentsPaths = _getScopeInformation.argumentsPaths,
146
+ newTargetPaths = _getScopeInformation.newTargetPaths,
147
+ superProps = _getScopeInformation.superProps,
148
+ superCalls = _getScopeInformation.superCalls;
149
+
150
+ if (inConstructor && superCalls.length > 0) {
151
+ if (!allowInsertArrow) {
152
+ throw superCalls[0].buildCodeFrameError("Unable to handle nested super() usage in arrow");
153
+ }
154
+
155
+ var allSuperCalls = [];
156
+ thisEnvFn.traverse({
157
+ Function: function Function(child) {
158
+ if (child.isArrowFunctionExpression()) return;
159
+ child.skip();
160
+ },
161
+ ClassProperty: function ClassProperty(child) {
162
+ if (child.node.static) return;
163
+ child.skip();
164
+ },
165
+ CallExpression: function CallExpression(child) {
166
+ if (!child.get("callee").isSuper()) return;
167
+ allSuperCalls.push(child);
168
+ }
169
+ });
170
+ var superBinding = getSuperBinding(thisEnvFn);
171
+ allSuperCalls.forEach(function (superCall) {
172
+ return superCall.get("callee").replaceWith(t.identifier(superBinding));
173
+ });
174
+ }
175
+
176
+ var thisBinding;
177
+
178
+ if (thisPaths.length > 0 || specCompliant) {
179
+ thisBinding = getThisBinding(thisEnvFn, inConstructor);
180
+
181
+ if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) {
182
+ thisPaths.forEach(function (thisChild) {
183
+ thisChild.replaceWith(thisChild.isJSX() ? t.jSXIdentifier(thisBinding) : t.identifier(thisBinding));
184
+ });
185
+ if (specCompliant) thisBinding = null;
186
+ }
187
+ }
188
+
189
+ if (argumentsPaths.length > 0) {
190
+ var argumentsBinding = getBinding(thisEnvFn, "arguments", function () {
191
+ return t.identifier("arguments");
192
+ });
193
+ argumentsPaths.forEach(function (argumentsChild) {
194
+ argumentsChild.replaceWith(t.identifier(argumentsBinding));
195
+ });
196
+ }
197
+
198
+ if (newTargetPaths.length > 0) {
199
+ var newTargetBinding = getBinding(thisEnvFn, "newtarget", function () {
200
+ return t.metaProperty(t.identifier("new"), t.identifier("target"));
201
+ });
202
+ newTargetPaths.forEach(function (argumentsChild) {
203
+ argumentsChild.replaceWith(t.identifier(newTargetBinding));
204
+ });
205
+ }
206
+
207
+ if (superProps.length > 0) {
208
+ if (!allowInsertArrow) {
209
+ throw superProps[0].buildCodeFrameError("Unable to handle nested super.prop usage");
210
+ }
211
+
212
+ var flatSuperProps = superProps.reduce(function (acc, superProp) {
213
+ return acc.concat(standardizeSuperProperty(superProp));
214
+ }, []);
215
+ flatSuperProps.forEach(function (superProp) {
216
+ var key = superProp.node.computed ? "" : superProp.get("property").node.name;
217
+
218
+ if (superProp.parentPath.isCallExpression({
219
+ callee: superProp.node
220
+ })) {
221
+ var _superBinding = getSuperPropCallBinding(thisEnvFn, key);
222
+
223
+ if (superProp.node.computed) {
224
+ var prop = superProp.get("property").node;
225
+ superProp.replaceWith(t.identifier(_superBinding));
226
+ superProp.parentPath.node.arguments.unshift(prop);
227
+ } else {
228
+ superProp.replaceWith(t.identifier(_superBinding));
229
+ }
230
+ } else {
231
+ var isAssignment = superProp.parentPath.isAssignmentExpression({
232
+ left: superProp.node
233
+ });
234
+
235
+ var _superBinding2 = getSuperPropBinding(thisEnvFn, isAssignment, key);
236
+
237
+ var args = [];
238
+
239
+ if (superProp.node.computed) {
240
+ args.push(superProp.get("property").node);
241
+ }
242
+
243
+ if (isAssignment) {
244
+ var value = superProp.parentPath.node.right;
245
+ args.push(value);
246
+ superProp.parentPath.replaceWith(t.callExpression(t.identifier(_superBinding2), args));
247
+ } else {
248
+ superProp.replaceWith(t.callExpression(t.identifier(_superBinding2), args));
249
+ }
250
+ }
251
+ });
252
+ }
253
+
254
+ return thisBinding;
255
+ }
256
+
257
+ function standardizeSuperProperty(superProp) {
258
+ if (superProp.parentPath.isAssignmentExpression() && superProp.parentPath.node.operator !== "=") {
259
+ var assignmentPath = superProp.parentPath;
260
+ var op = assignmentPath.node.operator.slice(0, -1);
261
+ var value = assignmentPath.node.right;
262
+ assignmentPath.node.operator = "=";
263
+
264
+ if (superProp.node.computed) {
265
+ var tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
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));
268
+ } 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));
271
+ }
272
+
273
+ return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
274
+ } else if (superProp.parentPath.isUpdateExpression()) {
275
+ var updateExpr = superProp.parentPath;
276
+
277
+ var _tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
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)))];
281
+
282
+ if (!superProp.parentPath.node.prefix) {
283
+ parts.push(t.identifier(_tmp.name));
284
+ }
285
+
286
+ updateExpr.replaceWith(t.sequenceExpression(parts));
287
+ var left = updateExpr.get("expressions.0.right");
288
+ var right = updateExpr.get("expressions.1.left");
289
+ return [left, right];
290
+ }
291
+
292
+ return [superProp];
293
+ }
294
+
295
+ function hasSuperClass(thisEnvFn) {
296
+ return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
297
+ }
298
+
299
+ function getThisBinding(thisEnvFn, inConstructor) {
300
+ return getBinding(thisEnvFn, "this", function (thisBinding) {
301
+ if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression();
302
+ var supers = new WeakSet();
303
+ thisEnvFn.traverse({
304
+ Function: function Function(child) {
305
+ if (child.isArrowFunctionExpression()) return;
306
+ child.skip();
307
+ },
308
+ ClassProperty: function ClassProperty(child) {
309
+ if (child.node.static) return;
310
+ child.skip();
311
+ },
312
+ CallExpression: function CallExpression(child) {
313
+ if (!child.get("callee").isSuper()) return;
314
+ if (supers.has(child.node)) return;
315
+ supers.add(child.node);
316
+ child.replaceWith(t.assignmentExpression("=", t.identifier(thisBinding), child.node));
317
+ }
318
+ });
319
+ });
320
+ }
321
+
322
+ function getSuperBinding(thisEnvFn) {
323
+ return getBinding(thisEnvFn, "supercall", function () {
324
+ var argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
325
+ return t.arrowFunctionExpression([t.restElement(argsBinding)], t.callExpression(t.super(), [t.spreadElement(t.identifier(argsBinding.name))]));
326
+ });
327
+ }
328
+
329
+ function getSuperPropCallBinding(thisEnvFn, propName) {
330
+ return getBinding(thisEnvFn, "superprop_call:" + (propName || ""), function () {
331
+ var argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
332
+ var argsList = [t.restElement(argsBinding)];
333
+ var fnBody;
334
+
335
+ if (propName) {
336
+ fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(propName)), [t.spreadElement(t.identifier(argsBinding.name))]);
337
+ } else {
338
+ var method = thisEnvFn.scope.generateUidIdentifier("prop");
339
+ argsList.unshift(method);
340
+ fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(method.name), true), [t.spreadElement(t.identifier(argsBinding.name))]);
341
+ }
342
+
343
+ return t.arrowFunctionExpression(argsList, fnBody);
344
+ });
345
+ }
346
+
347
+ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
348
+ var op = isAssignment ? "set" : "get";
349
+ return getBinding(thisEnvFn, "superprop_" + op + ":" + (propName || ""), function () {
350
+ var argsList = [];
351
+ var fnBody;
352
+
353
+ if (propName) {
354
+ fnBody = t.memberExpression(t.super(), t.identifier(propName));
355
+ } else {
356
+ var method = thisEnvFn.scope.generateUidIdentifier("prop");
357
+ argsList.unshift(method);
358
+ fnBody = t.memberExpression(t.super(), t.identifier(method.name), true);
359
+ }
360
+
361
+ if (isAssignment) {
362
+ var valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
363
+ argsList.push(valueIdent);
364
+ fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name));
365
+ }
366
+
367
+ return t.arrowFunctionExpression(argsList, fnBody);
368
+ });
369
+ }
370
+
371
+ function getBinding(thisEnvFn, key, init) {
372
+ var cacheKey = "binding:" + key;
373
+ var data = thisEnvFn.getData(cacheKey);
374
+
375
+ if (!data) {
376
+ var id = thisEnvFn.scope.generateUidIdentifier(key);
377
+ data = id.name;
378
+ thisEnvFn.setData(cacheKey, data);
379
+ thisEnvFn.scope.push({
380
+ id: id,
381
+ init: init(data)
382
+ });
383
+ }
384
+
385
+ return data;
386
+ }
387
+
388
+ function getScopeInformation(fnPath) {
389
+ var thisPaths = [];
390
+ var argumentsPaths = [];
391
+ var newTargetPaths = [];
392
+ var superProps = [];
393
+ var superCalls = [];
394
+ fnPath.traverse({
395
+ ClassProperty: function ClassProperty(child) {
396
+ if (child.node.static) return;
397
+ child.skip();
398
+ },
399
+ Function: function Function(child) {
400
+ if (child.isArrowFunctionExpression()) return;
401
+ child.skip();
402
+ },
403
+ ThisExpression: function ThisExpression(child) {
404
+ thisPaths.push(child);
405
+ },
406
+ JSXIdentifier: function JSXIdentifier(child) {
407
+ if (child.node.name !== "this") return;
408
+
409
+ if (!child.parentPath.isJSXMemberExpression({
410
+ object: child.node
411
+ }) && !child.parentPath.isJSXOpeningElement({
412
+ name: child.node
413
+ })) {
414
+ return;
415
+ }
416
+
417
+ thisPaths.push(child);
418
+ },
419
+ CallExpression: function CallExpression(child) {
420
+ if (child.get("callee").isSuper()) superCalls.push(child);
421
+ },
422
+ MemberExpression: function MemberExpression(child) {
423
+ if (child.get("object").isSuper()) superProps.push(child);
424
+ },
425
+ ReferencedIdentifier: function ReferencedIdentifier(child) {
426
+ if (child.node.name !== "arguments") return;
427
+ argumentsPaths.push(child);
428
+ },
429
+ MetaProperty: function MetaProperty(child) {
430
+ if (!child.get("meta").isIdentifier({
431
+ name: "new"
432
+ })) return;
433
+ if (!child.get("property").isIdentifier({
434
+ name: "target"
435
+ })) return;
436
+ newTargetPaths.push(child);
437
+ }
438
+ });
439
+ return {
440
+ thisPaths: thisPaths,
441
+ argumentsPaths: argumentsPaths,
442
+ newTargetPaths: newTargetPaths,
443
+ superProps: superProps,
444
+ superCalls: superCalls
445
+ };
446
+ }