@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/scope/index.js
CHANGED
@@ -1,179 +1,221 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
exports
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
4
6
|
exports.default = void 0;
|
5
7
|
|
6
|
-
|
8
|
+
function _includes() {
|
9
|
+
const data = _interopRequireDefault(require("lodash/includes"));
|
7
10
|
|
8
|
-
|
11
|
+
_includes = function () {
|
12
|
+
return data;
|
13
|
+
};
|
14
|
+
|
15
|
+
return data;
|
16
|
+
}
|
17
|
+
|
18
|
+
function _repeat() {
|
19
|
+
const data = _interopRequireDefault(require("lodash/repeat"));
|
20
|
+
|
21
|
+
_repeat = function () {
|
22
|
+
return data;
|
23
|
+
};
|
24
|
+
|
25
|
+
return data;
|
26
|
+
}
|
9
27
|
|
10
28
|
var _renamer = _interopRequireDefault(require("./lib/renamer"));
|
11
29
|
|
12
30
|
var _index = _interopRequireDefault(require("../index"));
|
13
31
|
|
14
|
-
|
32
|
+
function _defaults() {
|
33
|
+
const data = _interopRequireDefault(require("lodash/defaults"));
|
15
34
|
|
16
|
-
|
35
|
+
_defaults = function () {
|
36
|
+
return data;
|
37
|
+
};
|
17
38
|
|
18
|
-
|
39
|
+
return data;
|
40
|
+
}
|
19
41
|
|
20
|
-
var
|
42
|
+
var _binding = _interopRequireDefault(require("./binding"));
|
21
43
|
|
22
|
-
|
44
|
+
function _globals() {
|
45
|
+
const data = _interopRequireDefault(require("globals"));
|
23
46
|
|
24
|
-
|
47
|
+
_globals = function () {
|
48
|
+
return data;
|
49
|
+
};
|
25
50
|
|
26
|
-
|
51
|
+
return data;
|
52
|
+
}
|
27
53
|
|
28
|
-
function
|
54
|
+
function t() {
|
55
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
56
|
+
|
57
|
+
t = function () {
|
58
|
+
return data;
|
59
|
+
};
|
29
60
|
|
30
|
-
|
61
|
+
return data;
|
62
|
+
}
|
63
|
+
|
64
|
+
var _cache = require("../cache");
|
31
65
|
|
32
|
-
function
|
66
|
+
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; } }
|
33
67
|
|
34
|
-
|
68
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35
69
|
|
36
70
|
function gatherNodeParts(node, parts) {
|
37
|
-
if (t.isModuleDeclaration(node)) {
|
71
|
+
if (t().isModuleDeclaration(node)) {
|
38
72
|
if (node.source) {
|
39
73
|
gatherNodeParts(node.source, parts);
|
40
74
|
} else if (node.specifiers && node.specifiers.length) {
|
41
|
-
|
42
|
-
|
43
|
-
for (var _i = 0; _i < _arr.length; _i++) {
|
44
|
-
var specifier = _arr[_i];
|
75
|
+
for (const specifier of node.specifiers) {
|
45
76
|
gatherNodeParts(specifier, parts);
|
46
77
|
}
|
47
78
|
} else if (node.declaration) {
|
48
79
|
gatherNodeParts(node.declaration, parts);
|
49
80
|
}
|
50
|
-
} else if (t.isModuleSpecifier(node)) {
|
81
|
+
} else if (t().isModuleSpecifier(node)) {
|
51
82
|
gatherNodeParts(node.local, parts);
|
52
|
-
} else if (t.isMemberExpression(node)) {
|
83
|
+
} else if (t().isMemberExpression(node)) {
|
53
84
|
gatherNodeParts(node.object, parts);
|
54
85
|
gatherNodeParts(node.property, parts);
|
55
|
-
} else if (t.isIdentifier(node)) {
|
86
|
+
} else if (t().isIdentifier(node)) {
|
56
87
|
parts.push(node.name);
|
57
|
-
} else if (t.isLiteral(node)) {
|
88
|
+
} else if (t().isLiteral(node)) {
|
58
89
|
parts.push(node.value);
|
59
|
-
} else if (t.isCallExpression(node)) {
|
90
|
+
} else if (t().isCallExpression(node)) {
|
60
91
|
gatherNodeParts(node.callee, parts);
|
61
|
-
} else if (t.isObjectExpression(node) || t.isObjectPattern(node)) {
|
62
|
-
|
63
|
-
|
64
|
-
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
65
|
-
var prop = _arr2[_i2];
|
92
|
+
} else if (t().isObjectExpression(node) || t().isObjectPattern(node)) {
|
93
|
+
for (const prop of node.properties) {
|
66
94
|
gatherNodeParts(prop.key || prop.argument, parts);
|
67
95
|
}
|
96
|
+
} else if (t().isPrivateName(node)) {
|
97
|
+
gatherNodeParts(node.id, parts);
|
98
|
+
} else if (t().isThisExpression(node)) {
|
99
|
+
parts.push("this");
|
100
|
+
} else if (t().isSuper(node)) {
|
101
|
+
parts.push("super");
|
68
102
|
}
|
69
103
|
}
|
70
104
|
|
71
|
-
|
72
|
-
For
|
73
|
-
|
74
|
-
|
75
|
-
for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
|
76
|
-
var key = _arr3[_i3];
|
77
|
-
var declar = path.get(key);
|
105
|
+
const collectorVisitor = {
|
106
|
+
For(path) {
|
107
|
+
for (const key of t().FOR_INIT_KEYS) {
|
108
|
+
const declar = path.get(key);
|
78
109
|
|
79
110
|
if (declar.isVar()) {
|
80
|
-
|
111
|
+
const parentScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
|
81
112
|
parentScope.registerBinding("var", declar);
|
82
113
|
}
|
83
114
|
}
|
84
115
|
},
|
85
|
-
|
116
|
+
|
117
|
+
Declaration(path) {
|
86
118
|
if (path.isBlockScoped()) return;
|
87
119
|
|
88
120
|
if (path.isExportDeclaration() && path.get("declaration").isDeclaration()) {
|
89
121
|
return;
|
90
122
|
}
|
91
123
|
|
92
|
-
|
124
|
+
const parent = path.scope.getFunctionParent() || path.scope.getProgramParent();
|
93
125
|
parent.registerDeclaration(path);
|
94
126
|
},
|
95
|
-
|
127
|
+
|
128
|
+
ReferencedIdentifier(path, state) {
|
96
129
|
state.references.push(path);
|
97
130
|
},
|
98
|
-
|
99
|
-
|
131
|
+
|
132
|
+
ForXStatement(path, state) {
|
133
|
+
const left = path.get("left");
|
100
134
|
|
101
135
|
if (left.isPattern() || left.isIdentifier()) {
|
102
136
|
state.constantViolations.push(path);
|
103
137
|
}
|
104
138
|
},
|
139
|
+
|
105
140
|
ExportDeclaration: {
|
106
|
-
exit
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
141
|
+
exit(path) {
|
142
|
+
const {
|
143
|
+
node,
|
144
|
+
scope
|
145
|
+
} = path;
|
146
|
+
const declar = node.declaration;
|
147
|
+
|
148
|
+
if (t().isClassDeclaration(declar) || t().isFunctionDeclaration(declar)) {
|
149
|
+
const id = declar.id;
|
150
|
+
if (!id) return;
|
151
|
+
const binding = scope.getBinding(id.name);
|
115
152
|
if (binding) binding.reference(path);
|
116
|
-
} else if (t.isVariableDeclaration(declar)) {
|
117
|
-
|
118
|
-
|
119
|
-
for (var _i4 = 0; _i4 < _arr4.length; _i4++) {
|
120
|
-
var decl = _arr4[_i4];
|
121
|
-
var ids = t.getBindingIdentifiers(decl);
|
153
|
+
} else if (t().isVariableDeclaration(declar)) {
|
154
|
+
for (const decl of declar.declarations) {
|
155
|
+
const ids = t().getBindingIdentifiers(decl);
|
122
156
|
|
123
|
-
for (
|
124
|
-
|
125
|
-
|
126
|
-
if (_binding) _binding.reference(path);
|
157
|
+
for (const name in ids) {
|
158
|
+
const binding = scope.getBinding(name);
|
159
|
+
if (binding) binding.reference(path);
|
127
160
|
}
|
128
161
|
}
|
129
162
|
}
|
130
163
|
}
|
164
|
+
|
131
165
|
},
|
132
|
-
|
166
|
+
|
167
|
+
LabeledStatement(path) {
|
133
168
|
path.scope.getProgramParent().addGlobal(path.node);
|
134
169
|
path.scope.getBlockParent().registerDeclaration(path);
|
135
170
|
},
|
136
|
-
|
171
|
+
|
172
|
+
AssignmentExpression(path, state) {
|
137
173
|
state.assignments.push(path);
|
138
174
|
},
|
139
|
-
|
175
|
+
|
176
|
+
UpdateExpression(path, state) {
|
140
177
|
state.constantViolations.push(path);
|
141
178
|
},
|
142
|
-
|
179
|
+
|
180
|
+
UnaryExpression(path, state) {
|
143
181
|
if (path.node.operator === "delete") {
|
144
182
|
state.constantViolations.push(path);
|
145
183
|
}
|
146
184
|
},
|
147
|
-
|
148
|
-
|
185
|
+
|
186
|
+
BlockScoped(path) {
|
187
|
+
let scope = path.scope;
|
149
188
|
if (scope.path === path) scope = scope.parent;
|
150
189
|
scope.getBlockParent().registerDeclaration(path);
|
151
190
|
},
|
152
|
-
|
153
|
-
|
191
|
+
|
192
|
+
ClassDeclaration(path) {
|
193
|
+
const id = path.node.id;
|
154
194
|
if (!id) return;
|
155
|
-
|
195
|
+
const name = id.name;
|
156
196
|
path.scope.bindings[name] = path.scope.getBinding(name);
|
157
197
|
},
|
158
|
-
Block: function Block(path) {
|
159
|
-
var paths = path.get("body");
|
160
|
-
var _arr5 = paths;
|
161
198
|
|
162
|
-
|
163
|
-
|
199
|
+
Block(path) {
|
200
|
+
const paths = path.get("body");
|
164
201
|
|
202
|
+
for (const bodyPath of paths) {
|
165
203
|
if (bodyPath.isFunctionDeclaration()) {
|
166
204
|
path.scope.getBlockParent().registerDeclaration(bodyPath);
|
167
205
|
}
|
168
206
|
}
|
169
207
|
}
|
208
|
+
|
170
209
|
};
|
171
|
-
|
172
|
-
var Scope = (_temp = _class = function () {
|
173
|
-
function Scope(path) {
|
174
|
-
var node = path.node;
|
210
|
+
let uid = 0;
|
175
211
|
|
176
|
-
|
212
|
+
class Scope {
|
213
|
+
constructor(path) {
|
214
|
+
const {
|
215
|
+
node
|
216
|
+
} = path;
|
217
|
+
|
218
|
+
const cached = _cache.scope.get(node);
|
177
219
|
|
178
220
|
if (cached && cached.path === path) {
|
179
221
|
return cached;
|
@@ -187,83 +229,86 @@ var Scope = (_temp = _class = function () {
|
|
187
229
|
this.labels = new Map();
|
188
230
|
}
|
189
231
|
|
190
|
-
|
232
|
+
get parent() {
|
233
|
+
const parent = this.path.findParent(p => p.isScope());
|
234
|
+
return parent && parent.scope;
|
235
|
+
}
|
191
236
|
|
192
|
-
|
193
|
-
|
194
|
-
}
|
237
|
+
get parentBlock() {
|
238
|
+
return this.path.parent;
|
239
|
+
}
|
195
240
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
241
|
+
get hub() {
|
242
|
+
return this.path.hub;
|
243
|
+
}
|
244
|
+
|
245
|
+
traverse(node, opts, state) {
|
246
|
+
(0, _index.default)(node, opts, this, state, this.path);
|
247
|
+
}
|
200
248
|
|
201
|
-
|
249
|
+
generateDeclaredUidIdentifier(name) {
|
250
|
+
const id = this.generateUidIdentifier(name);
|
202
251
|
this.push({
|
203
|
-
id
|
252
|
+
id
|
204
253
|
});
|
205
|
-
return id;
|
206
|
-
}
|
207
|
-
|
208
|
-
_proto.generateUidIdentifier = function generateUidIdentifier(name) {
|
209
|
-
if (name === void 0) {
|
210
|
-
name = "temp";
|
211
|
-
}
|
212
|
-
|
213
|
-
return t.identifier(this.generateUid(name));
|
214
|
-
};
|
254
|
+
return t().cloneNode(id);
|
255
|
+
}
|
215
256
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
}
|
257
|
+
generateUidIdentifier(name) {
|
258
|
+
return t().identifier(this.generateUid(name));
|
259
|
+
}
|
220
260
|
|
221
|
-
|
222
|
-
|
223
|
-
|
261
|
+
generateUid(name = "temp") {
|
262
|
+
name = t().toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
263
|
+
let uid;
|
264
|
+
let i = 0;
|
224
265
|
|
225
266
|
do {
|
226
267
|
uid = this._generateUid(name, i);
|
227
268
|
i++;
|
228
269
|
} while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
|
229
270
|
|
230
|
-
|
271
|
+
const program = this.getProgramParent();
|
231
272
|
program.references[uid] = true;
|
232
273
|
program.uids[uid] = true;
|
233
274
|
return uid;
|
234
|
-
}
|
275
|
+
}
|
235
276
|
|
236
|
-
|
237
|
-
|
277
|
+
_generateUid(name, i) {
|
278
|
+
let id = name;
|
238
279
|
if (i > 1) id += i;
|
239
|
-
return
|
240
|
-
}
|
280
|
+
return `_${id}`;
|
281
|
+
}
|
241
282
|
|
242
|
-
|
243
|
-
|
283
|
+
generateUidBasedOnNode(parent, defaultName) {
|
284
|
+
let node = parent;
|
244
285
|
|
245
|
-
if (t.isAssignmentExpression(parent)) {
|
286
|
+
if (t().isAssignmentExpression(parent)) {
|
246
287
|
node = parent.left;
|
247
|
-
} else if (t.isVariableDeclarator(parent)) {
|
288
|
+
} else if (t().isVariableDeclarator(parent)) {
|
248
289
|
node = parent.id;
|
249
|
-
} else if (t.isObjectProperty(node) || t.isObjectMethod(node)) {
|
290
|
+
} else if (t().isObjectProperty(node) || t().isObjectMethod(node)) {
|
250
291
|
node = node.key;
|
251
292
|
}
|
252
293
|
|
253
|
-
|
294
|
+
const parts = [];
|
254
295
|
gatherNodeParts(node, parts);
|
255
|
-
|
296
|
+
let id = parts.join("$");
|
256
297
|
id = id.replace(/^_/, "") || defaultName || "ref";
|
257
|
-
return this.
|
258
|
-
}
|
298
|
+
return this.generateUid(id.slice(0, 20));
|
299
|
+
}
|
259
300
|
|
260
|
-
|
261
|
-
|
301
|
+
generateUidIdentifierBasedOnNode(parent, defaultName) {
|
302
|
+
return t().identifier(this.generateUidBasedOnNode(parent, defaultName));
|
303
|
+
}
|
304
|
+
|
305
|
+
isStatic(node) {
|
306
|
+
if (t().isThisExpression(node) || t().isSuper(node)) {
|
262
307
|
return true;
|
263
308
|
}
|
264
309
|
|
265
|
-
if (t.isIdentifier(node)) {
|
266
|
-
|
310
|
+
if (t().isIdentifier(node)) {
|
311
|
+
const binding = this.getBinding(node.name);
|
267
312
|
|
268
313
|
if (binding) {
|
269
314
|
return binding.constant;
|
@@ -273,58 +318,62 @@ var Scope = (_temp = _class = function () {
|
|
273
318
|
}
|
274
319
|
|
275
320
|
return false;
|
276
|
-
}
|
321
|
+
}
|
277
322
|
|
278
|
-
|
323
|
+
maybeGenerateMemoised(node, dontPush) {
|
279
324
|
if (this.isStatic(node)) {
|
280
325
|
return null;
|
281
326
|
} else {
|
282
|
-
|
327
|
+
const id = this.generateUidIdentifierBasedOnNode(node);
|
328
|
+
|
329
|
+
if (!dontPush) {
|
330
|
+
this.push({
|
331
|
+
id
|
332
|
+
});
|
333
|
+
return t().cloneNode(id);
|
334
|
+
}
|
283
335
|
|
284
|
-
|
285
|
-
id: _id2
|
286
|
-
});
|
287
|
-
return _id2;
|
336
|
+
return id;
|
288
337
|
}
|
289
|
-
}
|
338
|
+
}
|
290
339
|
|
291
|
-
|
340
|
+
checkBlockScopedCollisions(local, kind, name, id) {
|
292
341
|
if (kind === "param") return;
|
293
342
|
if (local.kind === "local") return;
|
294
343
|
if (kind === "hoisted" && local.kind === "let") return;
|
295
|
-
|
344
|
+
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const");
|
296
345
|
|
297
346
|
if (duplicate) {
|
298
|
-
throw this.hub.file.buildCodeFrameError(id,
|
347
|
+
throw this.hub.file.buildCodeFrameError(id, `Duplicate declaration "${name}"`, TypeError);
|
299
348
|
}
|
300
|
-
}
|
349
|
+
}
|
301
350
|
|
302
|
-
|
303
|
-
|
351
|
+
rename(oldName, newName, block) {
|
352
|
+
const binding = this.getBinding(oldName);
|
304
353
|
|
305
354
|
if (binding) {
|
306
355
|
newName = newName || this.generateUidIdentifier(oldName).name;
|
307
356
|
return new _renamer.default(binding, oldName, newName).rename(block);
|
308
357
|
}
|
309
|
-
}
|
358
|
+
}
|
310
359
|
|
311
|
-
|
360
|
+
_renameFromMap(map, oldName, newName, value) {
|
312
361
|
if (map[oldName]) {
|
313
362
|
map[newName] = value;
|
314
363
|
map[oldName] = null;
|
315
364
|
}
|
316
|
-
}
|
365
|
+
}
|
317
366
|
|
318
|
-
|
319
|
-
|
367
|
+
dump() {
|
368
|
+
const sep = (0, _repeat().default)("-", 60);
|
320
369
|
console.log(sep);
|
321
|
-
|
370
|
+
let scope = this;
|
322
371
|
|
323
372
|
do {
|
324
373
|
console.log("#", scope.block.type);
|
325
374
|
|
326
|
-
for (
|
327
|
-
|
375
|
+
for (const name in scope.bindings) {
|
376
|
+
const binding = scope.bindings[name];
|
328
377
|
console.log(" -", name, {
|
329
378
|
constant: binding.constant,
|
330
379
|
references: binding.references,
|
@@ -335,157 +384,135 @@ var Scope = (_temp = _class = function () {
|
|
335
384
|
} while (scope = scope.parent);
|
336
385
|
|
337
386
|
console.log(sep);
|
338
|
-
}
|
387
|
+
}
|
339
388
|
|
340
|
-
|
341
|
-
|
389
|
+
toArray(node, i) {
|
390
|
+
const file = this.hub.file;
|
342
391
|
|
343
|
-
if (t.isIdentifier(node)) {
|
344
|
-
|
392
|
+
if (t().isIdentifier(node)) {
|
393
|
+
const binding = this.getBinding(node.name);
|
345
394
|
|
346
395
|
if (binding && binding.constant && binding.path.isGenericType("Array")) {
|
347
396
|
return node;
|
348
397
|
}
|
349
398
|
}
|
350
399
|
|
351
|
-
if (t.isArrayExpression(node)) {
|
400
|
+
if (t().isArrayExpression(node)) {
|
352
401
|
return node;
|
353
402
|
}
|
354
403
|
|
355
|
-
if (t.isIdentifier(node, {
|
404
|
+
if (t().isIdentifier(node, {
|
356
405
|
name: "arguments"
|
357
406
|
})) {
|
358
|
-
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]);
|
407
|
+
return t().callExpression(t().memberExpression(t().memberExpression(t().memberExpression(t().identifier("Array"), t().identifier("prototype")), t().identifier("slice")), t().identifier("call")), [node]);
|
359
408
|
}
|
360
409
|
|
361
|
-
|
362
|
-
|
410
|
+
let helperName;
|
411
|
+
const args = [node];
|
363
412
|
|
364
413
|
if (i === true) {
|
365
414
|
helperName = "toConsumableArray";
|
366
415
|
} else if (i) {
|
367
|
-
args.push(t.numericLiteral(i));
|
416
|
+
args.push(t().numericLiteral(i));
|
368
417
|
helperName = "slicedToArray";
|
418
|
+
} else {
|
419
|
+
helperName = "toArray";
|
369
420
|
}
|
370
421
|
|
371
|
-
return t.callExpression(file.addHelper(helperName), args);
|
372
|
-
}
|
422
|
+
return t().callExpression(file.addHelper(helperName), args);
|
423
|
+
}
|
373
424
|
|
374
|
-
|
425
|
+
hasLabel(name) {
|
375
426
|
return !!this.getLabel(name);
|
376
|
-
}
|
427
|
+
}
|
377
428
|
|
378
|
-
|
429
|
+
getLabel(name) {
|
379
430
|
return this.labels.get(name);
|
380
|
-
}
|
431
|
+
}
|
381
432
|
|
382
|
-
|
433
|
+
registerLabel(path) {
|
383
434
|
this.labels.set(path.node.label.name, path);
|
384
|
-
}
|
435
|
+
}
|
385
436
|
|
386
|
-
|
437
|
+
registerDeclaration(path) {
|
387
438
|
if (path.isLabeledStatement()) {
|
388
439
|
this.registerLabel(path);
|
389
440
|
} else if (path.isFunctionDeclaration()) {
|
390
441
|
this.registerBinding("hoisted", path.get("id"), path);
|
391
442
|
} else if (path.isVariableDeclaration()) {
|
392
|
-
|
393
|
-
var _arr6 = declarations;
|
443
|
+
const declarations = path.get("declarations");
|
394
444
|
|
395
|
-
for (
|
396
|
-
var declar = _arr6[_i6];
|
445
|
+
for (const declar of declarations) {
|
397
446
|
this.registerBinding(path.node.kind, declar);
|
398
447
|
}
|
399
448
|
} else if (path.isClassDeclaration()) {
|
400
449
|
this.registerBinding("let", path);
|
401
450
|
} else if (path.isImportDeclaration()) {
|
402
|
-
|
403
|
-
var _arr7 = specifiers;
|
451
|
+
const specifiers = path.get("specifiers");
|
404
452
|
|
405
|
-
for (
|
406
|
-
var specifier = _arr7[_i7];
|
453
|
+
for (const specifier of specifiers) {
|
407
454
|
this.registerBinding("module", specifier);
|
408
455
|
}
|
409
456
|
} else if (path.isExportDeclaration()) {
|
410
|
-
|
457
|
+
const declar = path.get("declaration");
|
411
458
|
|
412
|
-
if (
|
413
|
-
this.registerDeclaration(
|
459
|
+
if (declar.isClassDeclaration() || declar.isFunctionDeclaration() || declar.isVariableDeclaration()) {
|
460
|
+
this.registerDeclaration(declar);
|
414
461
|
}
|
415
462
|
} else {
|
416
463
|
this.registerBinding("unknown", path);
|
417
464
|
}
|
418
|
-
}
|
465
|
+
}
|
419
466
|
|
420
|
-
|
467
|
+
buildUndefinedNode() {
|
421
468
|
if (this.hasBinding("undefined")) {
|
422
|
-
return t.unaryExpression("void", t.numericLiteral(0), true);
|
469
|
+
return t().unaryExpression("void", t().numericLiteral(0), true);
|
423
470
|
} else {
|
424
|
-
return t.identifier("undefined");
|
471
|
+
return t().identifier("undefined");
|
425
472
|
}
|
426
|
-
}
|
473
|
+
}
|
427
474
|
|
428
|
-
|
429
|
-
|
475
|
+
registerConstantViolation(path) {
|
476
|
+
const ids = path.getBindingIdentifiers();
|
430
477
|
|
431
|
-
for (
|
432
|
-
|
478
|
+
for (const name in ids) {
|
479
|
+
const binding = this.getBinding(name);
|
433
480
|
if (binding) binding.reassign(path);
|
434
481
|
}
|
435
|
-
}
|
436
|
-
|
437
|
-
_proto.registerBinding = function registerBinding(kind, path, bindingPath) {
|
438
|
-
if (bindingPath === void 0) {
|
439
|
-
bindingPath = path;
|
440
|
-
}
|
482
|
+
}
|
441
483
|
|
484
|
+
registerBinding(kind, path, bindingPath = path) {
|
442
485
|
if (!kind) throw new ReferenceError("no `kind`");
|
443
486
|
|
444
487
|
if (path.isVariableDeclaration()) {
|
445
|
-
|
446
|
-
|
447
|
-
for (var _iterator = declarators, _isArray = Array.isArray(_iterator), _i8 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
448
|
-
var _ref;
|
449
|
-
|
450
|
-
if (_isArray) {
|
451
|
-
if (_i8 >= _iterator.length) break;
|
452
|
-
_ref = _iterator[_i8++];
|
453
|
-
} else {
|
454
|
-
_i8 = _iterator.next();
|
455
|
-
if (_i8.done) break;
|
456
|
-
_ref = _i8.value;
|
457
|
-
}
|
488
|
+
const declarators = path.get("declarations");
|
458
489
|
|
459
|
-
|
460
|
-
this.registerBinding(kind,
|
490
|
+
for (const declar of declarators) {
|
491
|
+
this.registerBinding(kind, declar);
|
461
492
|
}
|
462
493
|
|
463
494
|
return;
|
464
495
|
}
|
465
496
|
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
for (var name in ids) {
|
470
|
-
var _arr8 = ids[name];
|
497
|
+
const parent = this.getProgramParent();
|
498
|
+
const ids = path.getBindingIdentifiers(true);
|
471
499
|
|
472
|
-
|
473
|
-
|
474
|
-
|
500
|
+
for (const name in ids) {
|
501
|
+
for (const id of ids[name]) {
|
502
|
+
const local = this.getOwnBinding(name);
|
475
503
|
|
476
504
|
if (local) {
|
477
|
-
if (local.identifier ===
|
478
|
-
this.checkBlockScopedCollisions(local, kind, name,
|
505
|
+
if (local.identifier === id) continue;
|
506
|
+
this.checkBlockScopedCollisions(local, kind, name, id);
|
479
507
|
}
|
480
508
|
|
481
|
-
if (local && local.path.isFlow()) local = null;
|
482
509
|
parent.references[name] = true;
|
483
510
|
|
484
511
|
if (local) {
|
485
512
|
this.registerConstantViolation(bindingPath);
|
486
513
|
} else {
|
487
|
-
this.bindings[name] = new
|
488
|
-
identifier:
|
514
|
+
this.bindings[name] = new _binding.default({
|
515
|
+
identifier: id,
|
489
516
|
scope: this,
|
490
517
|
path: bindingPath,
|
491
518
|
kind: kind
|
@@ -493,153 +520,124 @@ var Scope = (_temp = _class = function () {
|
|
493
520
|
}
|
494
521
|
}
|
495
522
|
}
|
496
|
-
}
|
523
|
+
}
|
497
524
|
|
498
|
-
|
525
|
+
addGlobal(node) {
|
499
526
|
this.globals[node.name] = node;
|
500
|
-
}
|
527
|
+
}
|
501
528
|
|
502
|
-
|
503
|
-
|
529
|
+
hasUid(name) {
|
530
|
+
let scope = this;
|
504
531
|
|
505
532
|
do {
|
506
533
|
if (scope.uids[name]) return true;
|
507
534
|
} while (scope = scope.parent);
|
508
535
|
|
509
536
|
return false;
|
510
|
-
}
|
537
|
+
}
|
511
538
|
|
512
|
-
|
513
|
-
|
539
|
+
hasGlobal(name) {
|
540
|
+
let scope = this;
|
514
541
|
|
515
542
|
do {
|
516
543
|
if (scope.globals[name]) return true;
|
517
544
|
} while (scope = scope.parent);
|
518
545
|
|
519
546
|
return false;
|
520
|
-
}
|
547
|
+
}
|
521
548
|
|
522
|
-
|
523
|
-
|
549
|
+
hasReference(name) {
|
550
|
+
let scope = this;
|
524
551
|
|
525
552
|
do {
|
526
553
|
if (scope.references[name]) return true;
|
527
554
|
} while (scope = scope.parent);
|
528
555
|
|
529
556
|
return false;
|
530
|
-
}
|
557
|
+
}
|
531
558
|
|
532
|
-
|
533
|
-
if (t.isIdentifier(node)) {
|
534
|
-
|
559
|
+
isPure(node, constantsOnly) {
|
560
|
+
if (t().isIdentifier(node)) {
|
561
|
+
const binding = this.getBinding(node.name);
|
535
562
|
if (!binding) return false;
|
536
563
|
if (constantsOnly) return binding.constant;
|
537
564
|
return true;
|
538
|
-
} else if (t.isClass(node)) {
|
565
|
+
} else if (t().isClass(node)) {
|
539
566
|
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
|
540
567
|
return false;
|
541
568
|
}
|
542
569
|
|
543
570
|
return this.isPure(node.body, constantsOnly);
|
544
|
-
} else if (t.isClassBody(node)) {
|
545
|
-
for (
|
546
|
-
|
547
|
-
|
548
|
-
if (_isArray2) {
|
549
|
-
if (_i10 >= _iterator2.length) break;
|
550
|
-
_ref2 = _iterator2[_i10++];
|
551
|
-
} else {
|
552
|
-
_i10 = _iterator2.next();
|
553
|
-
if (_i10.done) break;
|
554
|
-
_ref2 = _i10.value;
|
555
|
-
}
|
556
|
-
|
557
|
-
var _method = _ref2;
|
558
|
-
if (!this.isPure(_method, constantsOnly)) return false;
|
571
|
+
} else if (t().isClassBody(node)) {
|
572
|
+
for (const method of node.body) {
|
573
|
+
if (!this.isPure(method, constantsOnly)) return false;
|
559
574
|
}
|
560
575
|
|
561
576
|
return true;
|
562
|
-
} else if (t.isBinary(node)) {
|
577
|
+
} else if (t().isBinary(node)) {
|
563
578
|
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
564
|
-
} else if (t.isArrayExpression(node)) {
|
565
|
-
|
566
|
-
|
567
|
-
for (var _i11 = 0; _i11 < _arr9.length; _i11++) {
|
568
|
-
var elem = _arr9[_i11];
|
579
|
+
} else if (t().isArrayExpression(node)) {
|
580
|
+
for (const elem of node.elements) {
|
569
581
|
if (!this.isPure(elem, constantsOnly)) return false;
|
570
582
|
}
|
571
583
|
|
572
584
|
return true;
|
573
|
-
} else if (t.isObjectExpression(node)) {
|
574
|
-
|
575
|
-
|
576
|
-
for (var _i12 = 0; _i12 < _arr10.length; _i12++) {
|
577
|
-
var prop = _arr10[_i12];
|
585
|
+
} else if (t().isObjectExpression(node)) {
|
586
|
+
for (const prop of node.properties) {
|
578
587
|
if (!this.isPure(prop, constantsOnly)) return false;
|
579
588
|
}
|
580
589
|
|
581
590
|
return true;
|
582
|
-
} else if (t.isClassMethod(node)) {
|
591
|
+
} else if (t().isClassMethod(node)) {
|
583
592
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
584
593
|
if (node.kind === "get" || node.kind === "set") return false;
|
585
594
|
return true;
|
586
|
-
} else if (t
|
595
|
+
} else if (t().isProperty(node)) {
|
587
596
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
588
597
|
return this.isPure(node.value, constantsOnly);
|
589
|
-
} else if (t.isUnaryExpression(node)) {
|
598
|
+
} else if (t().isUnaryExpression(node)) {
|
590
599
|
return this.isPure(node.argument, constantsOnly);
|
591
|
-
} else if (t.isTaggedTemplateExpression(node)) {
|
592
|
-
return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
593
|
-
} else if (t.isTemplateLiteral(node)) {
|
594
|
-
|
595
|
-
|
596
|
-
for (var _i13 = 0; _i13 < _arr11.length; _i13++) {
|
597
|
-
var expression = _arr11[_i13];
|
600
|
+
} else if (t().isTaggedTemplateExpression(node)) {
|
601
|
+
return t().matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
602
|
+
} else if (t().isTemplateLiteral(node)) {
|
603
|
+
for (const expression of node.expressions) {
|
598
604
|
if (!this.isPure(expression, constantsOnly)) return false;
|
599
605
|
}
|
600
606
|
|
601
607
|
return true;
|
602
608
|
} else {
|
603
|
-
return t.isPureish(node);
|
609
|
+
return t().isPureish(node);
|
604
610
|
}
|
605
|
-
}
|
611
|
+
}
|
606
612
|
|
607
|
-
|
613
|
+
setData(key, val) {
|
608
614
|
return this.data[key] = val;
|
609
|
-
}
|
615
|
+
}
|
610
616
|
|
611
|
-
|
612
|
-
|
617
|
+
getData(key) {
|
618
|
+
let scope = this;
|
613
619
|
|
614
620
|
do {
|
615
|
-
|
621
|
+
const data = scope.data[key];
|
616
622
|
if (data != null) return data;
|
617
623
|
} while (scope = scope.parent);
|
618
|
-
}
|
624
|
+
}
|
619
625
|
|
620
|
-
|
621
|
-
|
626
|
+
removeData(key) {
|
627
|
+
let scope = this;
|
622
628
|
|
623
629
|
do {
|
624
|
-
|
630
|
+
const data = scope.data[key];
|
625
631
|
if (data != null) scope.data[key] = null;
|
626
632
|
} while (scope = scope.parent);
|
627
|
-
}
|
633
|
+
}
|
628
634
|
|
629
|
-
|
635
|
+
init() {
|
630
636
|
if (!this.references) this.crawl();
|
631
|
-
}
|
632
|
-
|
633
|
-
_proto.crawl = function crawl() {
|
634
|
-
_crawlCallsCount++;
|
635
|
-
|
636
|
-
this._crawl();
|
637
|
-
|
638
|
-
_crawlCallsCount--;
|
639
|
-
};
|
637
|
+
}
|
640
638
|
|
641
|
-
|
642
|
-
|
639
|
+
crawl() {
|
640
|
+
const path = this.path;
|
643
641
|
this.references = Object.create(null);
|
644
642
|
this.bindings = Object.create(null);
|
645
643
|
this.globals = Object.create(null);
|
@@ -647,44 +645,29 @@ var Scope = (_temp = _class = function () {
|
|
647
645
|
this.data = Object.create(null);
|
648
646
|
|
649
647
|
if (path.isLoop()) {
|
650
|
-
|
651
|
-
|
652
|
-
for (var _i14 = 0; _i14 < _arr12.length; _i14++) {
|
653
|
-
var key = _arr12[_i14];
|
654
|
-
var node = path.get(key);
|
648
|
+
for (const key of t().FOR_INIT_KEYS) {
|
649
|
+
const node = path.get(key);
|
655
650
|
if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
|
656
651
|
}
|
657
652
|
}
|
658
653
|
|
659
654
|
if (path.isFunctionExpression() && path.has("id")) {
|
660
|
-
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
655
|
+
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) {
|
661
656
|
this.registerBinding("local", path.get("id"), path);
|
662
657
|
}
|
663
658
|
}
|
664
659
|
|
665
660
|
if (path.isClassExpression() && path.has("id")) {
|
666
|
-
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
661
|
+
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) {
|
667
662
|
this.registerBinding("local", path);
|
668
663
|
}
|
669
664
|
}
|
670
665
|
|
671
666
|
if (path.isFunction()) {
|
672
|
-
|
673
|
-
|
674
|
-
for (var _iterator3 = params, _isArray3 = Array.isArray(_iterator3), _i15 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
675
|
-
var _ref3;
|
676
|
-
|
677
|
-
if (_isArray3) {
|
678
|
-
if (_i15 >= _iterator3.length) break;
|
679
|
-
_ref3 = _iterator3[_i15++];
|
680
|
-
} else {
|
681
|
-
_i15 = _iterator3.next();
|
682
|
-
if (_i15.done) break;
|
683
|
-
_ref3 = _i15.value;
|
684
|
-
}
|
667
|
+
const params = path.get("params");
|
685
668
|
|
686
|
-
|
687
|
-
this.registerBinding("param",
|
669
|
+
for (const param of params) {
|
670
|
+
this.registerBinding("param", param);
|
688
671
|
}
|
689
672
|
}
|
690
673
|
|
@@ -692,9 +675,9 @@ var Scope = (_temp = _class = function () {
|
|
692
675
|
this.registerBinding("let", path);
|
693
676
|
}
|
694
677
|
|
695
|
-
|
678
|
+
const parent = this.getProgramParent();
|
696
679
|
if (parent.crawling) return;
|
697
|
-
|
680
|
+
const state = {
|
698
681
|
references: [],
|
699
682
|
constantViolations: [],
|
700
683
|
assignments: []
|
@@ -703,76 +686,36 @@ var Scope = (_temp = _class = function () {
|
|
703
686
|
path.traverse(collectorVisitor, state);
|
704
687
|
this.crawling = false;
|
705
688
|
|
706
|
-
for (
|
707
|
-
|
708
|
-
|
709
|
-
if (_isArray4) {
|
710
|
-
if (_i16 >= _iterator4.length) break;
|
711
|
-
_ref4 = _iterator4[_i16++];
|
712
|
-
} else {
|
713
|
-
_i16 = _iterator4.next();
|
714
|
-
if (_i16.done) break;
|
715
|
-
_ref4 = _i16.value;
|
716
|
-
}
|
717
|
-
|
718
|
-
var _path3 = _ref4;
|
719
|
-
|
720
|
-
var ids = _path3.getBindingIdentifiers();
|
689
|
+
for (const path of state.assignments) {
|
690
|
+
const ids = path.getBindingIdentifiers();
|
691
|
+
let programParent;
|
721
692
|
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
if (_path3.scope.getBinding(name)) continue;
|
726
|
-
programParent = programParent || _path3.scope.getProgramParent();
|
693
|
+
for (const name in ids) {
|
694
|
+
if (path.scope.getBinding(name)) continue;
|
695
|
+
programParent = programParent || path.scope.getProgramParent();
|
727
696
|
programParent.addGlobal(ids[name]);
|
728
697
|
}
|
729
698
|
|
730
|
-
|
699
|
+
path.scope.registerConstantViolation(path);
|
731
700
|
}
|
732
701
|
|
733
|
-
for (
|
734
|
-
|
735
|
-
|
736
|
-
if (_isArray5) {
|
737
|
-
if (_i17 >= _iterator5.length) break;
|
738
|
-
_ref5 = _iterator5[_i17++];
|
739
|
-
} else {
|
740
|
-
_i17 = _iterator5.next();
|
741
|
-
if (_i17.done) break;
|
742
|
-
_ref5 = _i17.value;
|
743
|
-
}
|
744
|
-
|
745
|
-
var _ref7 = _ref5;
|
746
|
-
|
747
|
-
var binding = _ref7.scope.getBinding(_ref7.node.name);
|
702
|
+
for (const ref of state.references) {
|
703
|
+
const binding = ref.scope.getBinding(ref.node.name);
|
748
704
|
|
749
705
|
if (binding) {
|
750
|
-
binding.reference(
|
706
|
+
binding.reference(ref);
|
751
707
|
} else {
|
752
|
-
|
708
|
+
ref.scope.getProgramParent().addGlobal(ref.node);
|
753
709
|
}
|
754
710
|
}
|
755
711
|
|
756
|
-
for (
|
757
|
-
|
758
|
-
|
759
|
-
if (_isArray6) {
|
760
|
-
if (_i18 >= _iterator6.length) break;
|
761
|
-
_ref6 = _iterator6[_i18++];
|
762
|
-
} else {
|
763
|
-
_i18 = _iterator6.next();
|
764
|
-
if (_i18.done) break;
|
765
|
-
_ref6 = _i18.value;
|
766
|
-
}
|
767
|
-
|
768
|
-
var _path4 = _ref6;
|
769
|
-
|
770
|
-
_path4.scope.registerConstantViolation(_path4);
|
712
|
+
for (const path of state.constantViolations) {
|
713
|
+
path.scope.registerConstantViolation(path);
|
771
714
|
}
|
772
|
-
}
|
715
|
+
}
|
773
716
|
|
774
|
-
|
775
|
-
|
717
|
+
push(opts) {
|
718
|
+
let path = this.path;
|
776
719
|
|
777
720
|
if (!path.isBlockStatement() && !path.isProgram()) {
|
778
721
|
path = this.getBlockParent().path;
|
@@ -787,29 +730,26 @@ var Scope = (_temp = _class = function () {
|
|
787
730
|
path = path.get("body");
|
788
731
|
}
|
789
732
|
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
733
|
+
const unique = opts.unique;
|
734
|
+
const kind = opts.kind || "var";
|
735
|
+
const blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist;
|
736
|
+
const dataKey = `declaration:${kind}:${blockHoist}`;
|
737
|
+
let declarPath = !unique && path.getData(dataKey);
|
795
738
|
|
796
739
|
if (!declarPath) {
|
797
|
-
|
740
|
+
const declar = t().variableDeclaration(kind, []);
|
798
741
|
declar._blockHoist = blockHoist;
|
799
|
-
|
800
|
-
var _path$unshiftContaine = path.unshiftContainer("body", [declar]);
|
801
|
-
|
802
|
-
declarPath = _path$unshiftContaine[0];
|
742
|
+
[declarPath] = path.unshiftContainer("body", [declar]);
|
803
743
|
if (!unique) path.setData(dataKey, declarPath);
|
804
744
|
}
|
805
745
|
|
806
|
-
|
746
|
+
const declarator = t().variableDeclarator(opts.id, opts.init);
|
807
747
|
declarPath.node.declarations.push(declarator);
|
808
748
|
this.registerBinding(kind, declarPath.get("declarations").pop());
|
809
|
-
}
|
749
|
+
}
|
810
750
|
|
811
|
-
|
812
|
-
|
751
|
+
getProgramParent() {
|
752
|
+
let scope = this;
|
813
753
|
|
814
754
|
do {
|
815
755
|
if (scope.path.isProgram()) {
|
@@ -818,10 +758,10 @@ var Scope = (_temp = _class = function () {
|
|
818
758
|
} while (scope = scope.parent);
|
819
759
|
|
820
760
|
throw new Error("Couldn't find a Program");
|
821
|
-
}
|
761
|
+
}
|
822
762
|
|
823
|
-
|
824
|
-
|
763
|
+
getFunctionParent() {
|
764
|
+
let scope = this;
|
825
765
|
|
826
766
|
do {
|
827
767
|
if (scope.path.isFunctionParent()) {
|
@@ -830,10 +770,10 @@ var Scope = (_temp = _class = function () {
|
|
830
770
|
} while (scope = scope.parent);
|
831
771
|
|
832
772
|
return null;
|
833
|
-
}
|
773
|
+
}
|
834
774
|
|
835
|
-
|
836
|
-
|
775
|
+
getBlockParent() {
|
776
|
+
let scope = this;
|
837
777
|
|
838
778
|
do {
|
839
779
|
if (scope.path.isBlockParent()) {
|
@@ -842,31 +782,29 @@ var Scope = (_temp = _class = function () {
|
|
842
782
|
} while (scope = scope.parent);
|
843
783
|
|
844
784
|
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
845
|
-
}
|
785
|
+
}
|
846
786
|
|
847
|
-
|
848
|
-
|
849
|
-
|
787
|
+
getAllBindings() {
|
788
|
+
const ids = Object.create(null);
|
789
|
+
let scope = this;
|
850
790
|
|
851
791
|
do {
|
852
|
-
(0, _defaults.default)(ids, scope.bindings);
|
792
|
+
(0, _defaults().default)(ids, scope.bindings);
|
853
793
|
scope = scope.parent;
|
854
794
|
} while (scope);
|
855
795
|
|
856
796
|
return ids;
|
857
|
-
}
|
797
|
+
}
|
858
798
|
|
859
|
-
|
860
|
-
|
861
|
-
var _arr13 = arguments;
|
799
|
+
getAllBindingsOfKind() {
|
800
|
+
const ids = Object.create(null);
|
862
801
|
|
863
|
-
for (
|
864
|
-
|
865
|
-
var scope = this;
|
802
|
+
for (const kind of arguments) {
|
803
|
+
let scope = this;
|
866
804
|
|
867
805
|
do {
|
868
|
-
for (
|
869
|
-
|
806
|
+
for (const name in scope.bindings) {
|
807
|
+
const binding = scope.bindings[name];
|
870
808
|
if (binding.kind === kind) ids[name] = binding;
|
871
809
|
}
|
872
810
|
|
@@ -875,121 +813,85 @@ var Scope = (_temp = _class = function () {
|
|
875
813
|
}
|
876
814
|
|
877
815
|
return ids;
|
878
|
-
}
|
816
|
+
}
|
879
817
|
|
880
|
-
|
818
|
+
bindingIdentifierEquals(name, node) {
|
881
819
|
return this.getBindingIdentifier(name) === node;
|
882
|
-
}
|
883
|
-
|
884
|
-
_proto.warnOnFlowBinding = function warnOnFlowBinding(binding) {
|
885
|
-
if (_crawlCallsCount === 0 && binding && binding.path.isFlow()) {
|
886
|
-
console.warn("\n You or one of the Babel plugins you are using are using Flow declarations as bindings.\n Support for this will be removed in version 7. To find out the caller, grep for this\n message and change it to a `console.trace()`.\n ");
|
887
|
-
}
|
888
|
-
|
889
|
-
return binding;
|
890
|
-
};
|
820
|
+
}
|
891
821
|
|
892
|
-
|
893
|
-
|
822
|
+
getBinding(name) {
|
823
|
+
let scope = this;
|
894
824
|
|
895
825
|
do {
|
896
|
-
|
897
|
-
if (binding) return
|
826
|
+
const binding = scope.getOwnBinding(name);
|
827
|
+
if (binding) return binding;
|
898
828
|
} while (scope = scope.parent);
|
899
|
-
}
|
829
|
+
}
|
900
830
|
|
901
|
-
|
902
|
-
return this.
|
903
|
-
}
|
831
|
+
getOwnBinding(name) {
|
832
|
+
return this.bindings[name];
|
833
|
+
}
|
904
834
|
|
905
|
-
|
906
|
-
|
835
|
+
getBindingIdentifier(name) {
|
836
|
+
const info = this.getBinding(name);
|
907
837
|
return info && info.identifier;
|
908
|
-
}
|
838
|
+
}
|
909
839
|
|
910
|
-
|
911
|
-
|
840
|
+
getOwnBindingIdentifier(name) {
|
841
|
+
const binding = this.bindings[name];
|
912
842
|
return binding && binding.identifier;
|
913
|
-
}
|
843
|
+
}
|
914
844
|
|
915
|
-
|
845
|
+
hasOwnBinding(name) {
|
916
846
|
return !!this.getOwnBinding(name);
|
917
|
-
}
|
847
|
+
}
|
918
848
|
|
919
|
-
|
849
|
+
hasBinding(name, noGlobals) {
|
920
850
|
if (!name) return false;
|
921
851
|
if (this.hasOwnBinding(name)) return true;
|
922
852
|
if (this.parentHasBinding(name, noGlobals)) return true;
|
923
853
|
if (this.hasUid(name)) return true;
|
924
|
-
if (!noGlobals && (0, _includes.default)(Scope.globals, name)) return true;
|
925
|
-
if (!noGlobals && (0, _includes.default)(Scope.contextVariables, name)) return true;
|
854
|
+
if (!noGlobals && (0, _includes().default)(Scope.globals, name)) return true;
|
855
|
+
if (!noGlobals && (0, _includes().default)(Scope.contextVariables, name)) return true;
|
926
856
|
return false;
|
927
|
-
}
|
857
|
+
}
|
928
858
|
|
929
|
-
|
859
|
+
parentHasBinding(name, noGlobals) {
|
930
860
|
return this.parent && this.parent.hasBinding(name, noGlobals);
|
931
|
-
}
|
861
|
+
}
|
932
862
|
|
933
|
-
|
934
|
-
|
863
|
+
moveBindingTo(name, scope) {
|
864
|
+
const info = this.getBinding(name);
|
935
865
|
|
936
866
|
if (info) {
|
937
867
|
info.scope.removeOwnBinding(name);
|
938
868
|
info.scope = scope;
|
939
869
|
scope.bindings[name] = info;
|
940
870
|
}
|
941
|
-
}
|
871
|
+
}
|
942
872
|
|
943
|
-
|
873
|
+
removeOwnBinding(name) {
|
944
874
|
delete this.bindings[name];
|
945
|
-
}
|
875
|
+
}
|
946
876
|
|
947
|
-
|
948
|
-
|
877
|
+
removeBinding(name) {
|
878
|
+
const info = this.getBinding(name);
|
949
879
|
|
950
880
|
if (info) {
|
951
881
|
info.scope.removeOwnBinding(name);
|
952
882
|
}
|
953
883
|
|
954
|
-
|
884
|
+
let scope = this;
|
955
885
|
|
956
886
|
do {
|
957
887
|
if (scope.uids[name]) {
|
958
888
|
scope.uids[name] = false;
|
959
889
|
}
|
960
890
|
} while (scope = scope.parent);
|
961
|
-
}
|
891
|
+
}
|
892
|
+
|
893
|
+
}
|
962
894
|
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
var parent = this.path.findParent(function (p) {
|
967
|
-
return p.isScope();
|
968
|
-
});
|
969
|
-
return parent && parent.scope;
|
970
|
-
}
|
971
|
-
}, {
|
972
|
-
key: "parentBlock",
|
973
|
-
get: function get() {
|
974
|
-
return this.path.parent;
|
975
|
-
}
|
976
|
-
}, {
|
977
|
-
key: "hub",
|
978
|
-
get: function get() {
|
979
|
-
return this.path.hub;
|
980
|
-
}
|
981
|
-
}]);
|
982
|
-
|
983
|
-
return Scope;
|
984
|
-
}(), Object.defineProperty(_class, "globals", {
|
985
|
-
configurable: true,
|
986
|
-
enumerable: true,
|
987
|
-
writable: true,
|
988
|
-
value: Object.keys(_globals.default.builtin)
|
989
|
-
}), Object.defineProperty(_class, "contextVariables", {
|
990
|
-
configurable: true,
|
991
|
-
enumerable: true,
|
992
|
-
writable: true,
|
993
|
-
value: ["arguments", "undefined", "Infinity", "NaN"]
|
994
|
-
}), _temp);
|
995
|
-
exports.default = Scope;
|
895
|
+
exports.default = Scope;
|
896
|
+
Scope.globals = Object.keys(_globals().default.builtin);
|
897
|
+
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
|