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