babel-schmooze-sprockets 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/bin/console +14 -0
  3. data/bin/export-external-helpers +3 -0
  4. data/bin/setup +6 -0
  5. data/bin/update-npm-deps +8 -0
  6. data/examples/myapp/Gemfile +4 -5
  7. data/examples/myapp/Gemfile.lock +69 -93
  8. data/examples/myapp/app/assets/javascripts/code/hello.es6 +5 -1
  9. data/examples/myapp/app/views/layouts/application.html.erb +1 -0
  10. data/examples/myapp/app/views/site/home.html.erb +0 -1
  11. data/lib/babel-schmooze-sprockets/babel_processor.rb +6 -4
  12. data/lib/babel-schmooze-sprockets/engine.rb +1 -4
  13. data/lib/babel-schmooze-sprockets/version.rb +1 -1
  14. data/node_modules/amdefine/package.json +8 -1
  15. data/node_modules/babel-core/node_modules/babel-runtime/package.json +9 -5
  16. data/node_modules/babel-core/node_modules/babel-traverse/.npmignore +3 -0
  17. data/node_modules/babel-core/node_modules/babel-traverse/README.md +1 -0
  18. data/node_modules/babel-core/node_modules/babel-traverse/lib/cache.js +20 -0
  19. data/node_modules/babel-core/node_modules/babel-traverse/lib/context.js +219 -0
  20. data/node_modules/babel-core/node_modules/babel-traverse/lib/hub.js +19 -0
  21. data/node_modules/babel-core/node_modules/babel-traverse/lib/index.js +250 -0
  22. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/ancestry.js +317 -0
  23. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/comments.js +55 -0
  24. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js +297 -0
  25. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/conversion.js +48 -0
  26. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/evaluation.js +406 -0
  27. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/family.js +168 -0
  28. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js +245 -0
  29. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/inference/index.js +151 -0
  30. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/inference/inferer-reference.js +225 -0
  31. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/inference/inferers.js +198 -0
  32. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/introspection.js +518 -0
  33. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/lib/hoister.js +166 -0
  34. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/lib/removal-hooks.js +64 -0
  35. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/lib/virtual-types.js +141 -0
  36. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/modification.js +293 -0
  37. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/removal.js +72 -0
  38. data/node_modules/babel-core/node_modules/babel-traverse/lib/path/replacement.js +302 -0
  39. data/node_modules/babel-core/node_modules/babel-traverse/lib/scope/binding.js +105 -0
  40. data/node_modules/babel-core/node_modules/babel-traverse/lib/scope/index.js +1222 -0
  41. data/node_modules/babel-core/node_modules/babel-traverse/lib/scope/lib/renamer.js +154 -0
  42. data/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js +360 -0
  43. data/node_modules/babel-core/node_modules/babel-traverse/package.json +107 -0
  44. data/node_modules/babel-core/node_modules/core-js/package.json +20 -2
  45. data/node_modules/babel-core/package.json +31 -24
  46. data/node_modules/babel-generator/lib/buffer.js +69 -70
  47. data/node_modules/babel-generator/lib/generators/base.js +16 -12
  48. data/node_modules/babel-generator/lib/generators/classes.js +28 -19
  49. data/node_modules/babel-generator/lib/generators/expressions.js +76 -99
  50. data/node_modules/babel-generator/lib/generators/flow.js +178 -119
  51. data/node_modules/babel-generator/lib/generators/jsx.js +38 -29
  52. data/node_modules/babel-generator/lib/generators/methods.js +34 -25
  53. data/node_modules/babel-generator/lib/generators/modules.js +67 -40
  54. data/node_modules/babel-generator/lib/generators/statements.js +93 -76
  55. data/node_modules/babel-generator/lib/generators/template-literals.js +12 -11
  56. data/node_modules/babel-generator/lib/generators/types.js +56 -49
  57. data/node_modules/babel-generator/lib/index.js +52 -39
  58. data/node_modules/babel-generator/lib/node/index.js +12 -18
  59. data/node_modules/babel-generator/lib/node/parentheses.js +23 -27
  60. data/node_modules/babel-generator/lib/node/whitespace.js +20 -26
  61. data/node_modules/babel-generator/lib/position.js +5 -5
  62. data/node_modules/babel-generator/lib/printer.js +52 -81
  63. data/node_modules/babel-generator/lib/source-map.js +9 -11
  64. data/node_modules/babel-generator/lib/whitespace.js +13 -13
  65. data/node_modules/babel-generator/node_modules/babel-runtime/package.json +19 -6
  66. data/node_modules/babel-generator/node_modules/babel-types/.npmignore +3 -0
  67. data/node_modules/babel-generator/node_modules/babel-types/README.md +1141 -0
  68. data/node_modules/babel-generator/node_modules/babel-types/lib/constants.js +40 -0
  69. data/node_modules/babel-generator/node_modules/babel-types/lib/converters.js +378 -0
  70. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/core.js +704 -0
  71. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/es2015.js +354 -0
  72. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/experimental.js +85 -0
  73. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/flow.js +319 -0
  74. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/index.js +247 -0
  75. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/init.js +15 -0
  76. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/jsx.js +137 -0
  77. data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/misc.js +21 -0
  78. data/node_modules/babel-generator/node_modules/babel-types/lib/flow.js +129 -0
  79. data/node_modules/babel-generator/node_modules/babel-types/lib/index.js +848 -0
  80. data/node_modules/babel-generator/node_modules/babel-types/lib/react.js +83 -0
  81. data/node_modules/babel-generator/node_modules/babel-types/lib/retrievers.js +123 -0
  82. data/node_modules/babel-generator/node_modules/babel-types/lib/validators.js +276 -0
  83. data/node_modules/babel-generator/node_modules/babel-types/package.json +103 -0
  84. data/node_modules/babel-generator/node_modules/core-js/package.json +10 -5
  85. data/node_modules/babel-generator/package.json +19 -16
  86. data/node_modules/babel-helpers/node_modules/babel-runtime/package.json +19 -3
  87. data/node_modules/babel-helpers/node_modules/core-js/package.json +20 -4
  88. data/node_modules/babel-helpers/package.json +8 -1
  89. data/node_modules/babel-register/node_modules/babel-runtime/package.json +19 -3
  90. data/node_modules/babel-register/node_modules/core-js/package.json +20 -4
  91. data/node_modules/babel-register/package.json +8 -1
  92. data/node_modules/balanced-match/package.json +8 -1
  93. data/node_modules/brace-expansion/package.json +19 -12
  94. data/node_modules/concat-map/package.json +9 -2
  95. data/node_modules/convert-source-map/package.json +8 -1
  96. data/node_modules/detect-indent/package.json +8 -1
  97. data/node_modules/get-stdin/package.json +8 -1
  98. data/node_modules/home-or-tmp/package.json +9 -2
  99. data/node_modules/is-finite/package.json +8 -2
  100. data/node_modules/json5/package.json +8 -1
  101. data/node_modules/minimatch/README.md +2 -9
  102. data/node_modules/minimatch/minimatch.js +15 -3
  103. data/node_modules/minimatch/package.json +29 -21
  104. data/node_modules/minimist/package.json +8 -1
  105. data/node_modules/mkdirp/node_modules/minimist/package.json +8 -1
  106. data/node_modules/mkdirp/package.json +8 -1
  107. data/node_modules/number-is-nan/package.json +8 -1
  108. data/node_modules/os-tmpdir/package.json +8 -1
  109. data/node_modules/path-exists/package.json +8 -1
  110. data/node_modules/path-is-absolute/package.json +8 -1
  111. data/node_modules/repeating/package.json +15 -11
  112. data/node_modules/shebang-regex/package.json +8 -1
  113. data/node_modules/slash/package.json +8 -1
  114. data/node_modules/source-map-support/node_modules/source-map/package.json +8 -1
  115. data/node_modules/source-map-support/package.json +8 -1
  116. data/node_modules/source-map/package.json +8 -1
  117. data/node_modules/user-home/package.json +8 -1
  118. data/package.json +1 -1
  119. metadata +54 -6
  120. data/node_modules/brace-expansion/.npmignore +0 -3
  121. data/node_modules/brace-expansion/example.js +0 -8
  122. data/node_modules/minimatch/browser.js +0 -1159
@@ -0,0 +1,1222 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _keys = require("babel-runtime/core-js/object/keys");
6
+
7
+ var _keys2 = _interopRequireDefault(_keys);
8
+
9
+ var _create = require("babel-runtime/core-js/object/create");
10
+
11
+ var _create2 = _interopRequireDefault(_create);
12
+
13
+ var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
14
+
15
+ var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
16
+
17
+ var _getIterator2 = require("babel-runtime/core-js/get-iterator");
18
+
19
+ var _getIterator3 = _interopRequireDefault(_getIterator2);
20
+
21
+ var _includes = require("lodash/includes");
22
+
23
+ var _includes2 = _interopRequireDefault(_includes);
24
+
25
+ var _repeat = require("lodash/repeat");
26
+
27
+ var _repeat2 = _interopRequireDefault(_repeat);
28
+
29
+ var _renamer = require("./lib/renamer");
30
+
31
+ var _renamer2 = _interopRequireDefault(_renamer);
32
+
33
+ var _index = require("../index");
34
+
35
+ var _index2 = _interopRequireDefault(_index);
36
+
37
+ var _defaults = require("lodash/defaults");
38
+
39
+ var _defaults2 = _interopRequireDefault(_defaults);
40
+
41
+ var _babelMessages = require("babel-messages");
42
+
43
+ var messages = _interopRequireWildcard(_babelMessages);
44
+
45
+ var _binding2 = require("./binding");
46
+
47
+ var _binding3 = _interopRequireDefault(_binding2);
48
+
49
+ var _globals = require("globals");
50
+
51
+ var _globals2 = _interopRequireDefault(_globals);
52
+
53
+ var _babelTypes = require("babel-types");
54
+
55
+ var t = _interopRequireWildcard(_babelTypes);
56
+
57
+ var _cache = require("../cache");
58
+
59
+ 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; } }
60
+
61
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
62
+
63
+ // Number of calls to the crawl method to figure out whether we're
64
+ // somewhere inside a call that was trigerred by call. This is meant
65
+ // to be used to figure out whether a warning should be trigerred.
66
+ // See `warnOnFlowBinding`.
67
+ /* eslint max-len: 0 */
68
+
69
+ var _crawlCallsCount = 0;
70
+
71
+ /**
72
+ * To avoid creating a new Scope instance for each traversal, we maintain a cache on the
73
+ * node itself containing all scopes it has been associated with.
74
+ */
75
+
76
+ function getCache(path, parentScope, self) {
77
+ var scopes = _cache.scope.get(path.node) || [];
78
+
79
+ for (var _iterator = scopes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
80
+ var _ref;
81
+
82
+ if (_isArray) {
83
+ if (_i >= _iterator.length) break;
84
+ _ref = _iterator[_i++];
85
+ } else {
86
+ _i = _iterator.next();
87
+ if (_i.done) break;
88
+ _ref = _i.value;
89
+ }
90
+
91
+ var scope = _ref;
92
+
93
+ if (scope.parent === parentScope && scope.path === path) return scope;
94
+ }
95
+
96
+ scopes.push(self);
97
+
98
+ if (!_cache.scope.has(path.node)) {
99
+ _cache.scope.set(path.node, scopes);
100
+ }
101
+ }
102
+
103
+ //
104
+
105
+ var collectorVisitor = {
106
+ For: function For(path) {
107
+ for (var _iterator2 = t.FOR_INIT_KEYS, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
108
+ var _ref2;
109
+
110
+ if (_isArray2) {
111
+ if (_i2 >= _iterator2.length) break;
112
+ _ref2 = _iterator2[_i2++];
113
+ } else {
114
+ _i2 = _iterator2.next();
115
+ if (_i2.done) break;
116
+ _ref2 = _i2.value;
117
+ }
118
+
119
+ var key = _ref2;
120
+
121
+ var declar = path.get(key);
122
+ if (declar.isVar()) path.scope.getFunctionParent().registerBinding("var", declar);
123
+ }
124
+ },
125
+ Declaration: function Declaration(path) {
126
+ // delegate block scope handling to the `blockVariableVisitor`
127
+ if (path.isBlockScoped()) return;
128
+
129
+ // this will be hit again once we traverse into it after this iteration
130
+ if (path.isExportDeclaration() && path.get("declaration").isDeclaration()) return;
131
+
132
+ // TODO(amasad): remove support for flow as bindings (See warning below).
133
+ //if (path.isFlow()) return;
134
+
135
+ // we've ran into a declaration!
136
+ path.scope.getFunctionParent().registerDeclaration(path);
137
+ },
138
+ ReferencedIdentifier: function ReferencedIdentifier(path, state) {
139
+ state.references.push(path);
140
+ },
141
+ ForXStatement: function ForXStatement(path, state) {
142
+ var left = path.get("left");
143
+ if (left.isPattern() || left.isIdentifier()) {
144
+ state.constantViolations.push(left);
145
+ }
146
+ },
147
+
148
+
149
+ ExportDeclaration: {
150
+ exit: function exit(_ref3) {
151
+ var node = _ref3.node;
152
+ var scope = _ref3.scope;
153
+
154
+ var declar = node.declaration;
155
+ if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
156
+ var _id = declar.id;
157
+ if (!_id) return;
158
+
159
+ var binding = scope.getBinding(_id.name);
160
+ if (binding) binding.reference();
161
+ } else if (t.isVariableDeclaration(declar)) {
162
+ for (var _iterator3 = declar.declarations, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
163
+ var _ref4;
164
+
165
+ if (_isArray3) {
166
+ if (_i3 >= _iterator3.length) break;
167
+ _ref4 = _iterator3[_i3++];
168
+ } else {
169
+ _i3 = _iterator3.next();
170
+ if (_i3.done) break;
171
+ _ref4 = _i3.value;
172
+ }
173
+
174
+ var decl = _ref4;
175
+
176
+ var ids = t.getBindingIdentifiers(decl);
177
+ for (var name in ids) {
178
+ var _binding = scope.getBinding(name);
179
+ if (_binding) _binding.reference();
180
+ }
181
+ }
182
+ }
183
+ }
184
+ },
185
+
186
+ LabeledStatement: function LabeledStatement(path) {
187
+ path.scope.getProgramParent().addGlobal(path.node);
188
+ path.scope.getBlockParent().registerDeclaration(path);
189
+ },
190
+ AssignmentExpression: function AssignmentExpression(path, state) {
191
+ state.assignments.push(path);
192
+ },
193
+ UpdateExpression: function UpdateExpression(path, state) {
194
+ state.constantViolations.push(path.get("argument"));
195
+ },
196
+ UnaryExpression: function UnaryExpression(path, state) {
197
+ if (path.node.operator === "delete") {
198
+ state.constantViolations.push(path.get("argument"));
199
+ }
200
+ },
201
+ BlockScoped: function BlockScoped(path) {
202
+ var scope = path.scope;
203
+ if (scope.path === path) scope = scope.parent;
204
+ scope.getBlockParent().registerDeclaration(path);
205
+ },
206
+ ClassDeclaration: function ClassDeclaration(path) {
207
+ var id = path.node.id;
208
+ if (!id) return;
209
+
210
+ var name = id.name;
211
+ path.scope.bindings[name] = path.scope.getBinding(name);
212
+ },
213
+ Block: function Block(path) {
214
+ var paths = path.get("body");
215
+ for (var _iterator4 = paths, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
216
+ var _ref5;
217
+
218
+ if (_isArray4) {
219
+ if (_i4 >= _iterator4.length) break;
220
+ _ref5 = _iterator4[_i4++];
221
+ } else {
222
+ _i4 = _iterator4.next();
223
+ if (_i4.done) break;
224
+ _ref5 = _i4.value;
225
+ }
226
+
227
+ var bodyPath = _ref5;
228
+
229
+ if (bodyPath.isFunctionDeclaration()) {
230
+ path.scope.getBlockParent().registerDeclaration(bodyPath);
231
+ }
232
+ }
233
+ }
234
+ };
235
+
236
+ var uid = 0;
237
+
238
+ var Scope = function () {
239
+
240
+ /**
241
+ * This searches the current "scope" and collects all references/bindings
242
+ * within.
243
+ */
244
+
245
+ function Scope(path, parentScope) {
246
+ (0, _classCallCheck3.default)(this, Scope);
247
+
248
+ if (parentScope && parentScope.block === path.node) {
249
+ return parentScope;
250
+ }
251
+
252
+ var cached = getCache(path, parentScope, this);
253
+ if (cached) return cached;
254
+
255
+ this.uid = uid++;
256
+ this.parent = parentScope;
257
+ this.hub = path.hub;
258
+
259
+ this.parentBlock = path.parent;
260
+ this.block = path.node;
261
+ this.path = path;
262
+ }
263
+
264
+ /**
265
+ * Globals.
266
+ */
267
+
268
+ /**
269
+ * Variables available in current context.
270
+ */
271
+
272
+ /**
273
+ * Traverse node with current scope and path.
274
+ */
275
+
276
+ Scope.prototype.traverse = function traverse(node, opts, state) {
277
+ (0, _index2.default)(node, opts, this, state, this.path);
278
+ };
279
+
280
+ /**
281
+ * Generate a unique identifier and add it to the current scope.
282
+ */
283
+
284
+ Scope.prototype.generateDeclaredUidIdentifier = function generateDeclaredUidIdentifier() {
285
+ var name = arguments.length <= 0 || arguments[0] === undefined ? "temp" : arguments[0];
286
+
287
+ var id = this.generateUidIdentifier(name);
288
+ this.push({ id: id });
289
+ return id;
290
+ };
291
+
292
+ /**
293
+ * Generate a unique identifier.
294
+ */
295
+
296
+ Scope.prototype.generateUidIdentifier = function generateUidIdentifier() {
297
+ var name = arguments.length <= 0 || arguments[0] === undefined ? "temp" : arguments[0];
298
+
299
+ return t.identifier(this.generateUid(name));
300
+ };
301
+
302
+ /**
303
+ * Generate a unique `_id1` binding.
304
+ */
305
+
306
+ Scope.prototype.generateUid = function generateUid() {
307
+ var name = arguments.length <= 0 || arguments[0] === undefined ? "temp" : arguments[0];
308
+
309
+ name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
310
+
311
+ var uid = void 0;
312
+ var i = 0;
313
+ do {
314
+ uid = this._generateUid(name, i);
315
+ i++;
316
+ } while (this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
317
+
318
+ var program = this.getProgramParent();
319
+ program.references[uid] = true;
320
+ program.uids[uid] = true;
321
+
322
+ return uid;
323
+ };
324
+
325
+ /**
326
+ * Generate an `_id1`.
327
+ */
328
+
329
+ Scope.prototype._generateUid = function _generateUid(name, i) {
330
+ var id = name;
331
+ if (i > 1) id += i;
332
+ return "_" + id;
333
+ };
334
+
335
+ /**
336
+ * Generate a unique identifier based on a node.
337
+ */
338
+
339
+ Scope.prototype.generateUidIdentifierBasedOnNode = function generateUidIdentifierBasedOnNode(parent, defaultName) {
340
+ var node = parent;
341
+
342
+ if (t.isAssignmentExpression(parent)) {
343
+ node = parent.left;
344
+ } else if (t.isVariableDeclarator(parent)) {
345
+ node = parent.id;
346
+ } else if (t.isObjectProperty(node) || t.isObjectMethod(node)) {
347
+ node = node.key;
348
+ }
349
+
350
+ var parts = [];
351
+
352
+ var add = function add(node) {
353
+ if (t.isModuleDeclaration(node)) {
354
+ if (node.source) {
355
+ add(node.source);
356
+ } else if (node.specifiers && node.specifiers.length) {
357
+ for (var _iterator5 = node.specifiers, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : (0, _getIterator3.default)(_iterator5);;) {
358
+ var _ref6;
359
+
360
+ if (_isArray5) {
361
+ if (_i5 >= _iterator5.length) break;
362
+ _ref6 = _iterator5[_i5++];
363
+ } else {
364
+ _i5 = _iterator5.next();
365
+ if (_i5.done) break;
366
+ _ref6 = _i5.value;
367
+ }
368
+
369
+ var specifier = _ref6;
370
+
371
+ add(specifier);
372
+ }
373
+ } else if (node.declaration) {
374
+ add(node.declaration);
375
+ }
376
+ } else if (t.isModuleSpecifier(node)) {
377
+ add(node.local);
378
+ } else if (t.isMemberExpression(node)) {
379
+ add(node.object);
380
+ add(node.property);
381
+ } else if (t.isIdentifier(node)) {
382
+ parts.push(node.name);
383
+ } else if (t.isLiteral(node)) {
384
+ parts.push(node.value);
385
+ } else if (t.isCallExpression(node)) {
386
+ add(node.callee);
387
+ } else if (t.isObjectExpression(node) || t.isObjectPattern(node)) {
388
+ for (var _iterator6 = node.properties, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : (0, _getIterator3.default)(_iterator6);;) {
389
+ var _ref7;
390
+
391
+ if (_isArray6) {
392
+ if (_i6 >= _iterator6.length) break;
393
+ _ref7 = _iterator6[_i6++];
394
+ } else {
395
+ _i6 = _iterator6.next();
396
+ if (_i6.done) break;
397
+ _ref7 = _i6.value;
398
+ }
399
+
400
+ var prop = _ref7;
401
+
402
+ add(prop.key || prop.argument);
403
+ }
404
+ }
405
+ };
406
+
407
+ add(node);
408
+
409
+ var id = parts.join("$");
410
+ id = id.replace(/^_/, "") || defaultName || "ref";
411
+
412
+ return this.generateUidIdentifier(id.slice(0, 20));
413
+ };
414
+
415
+ /**
416
+ * Determine whether evaluating the specific input `node` is a consequenceless reference. ie.
417
+ * evaluating it wont result in potentially arbitrary code from being ran. The following are
418
+ * whitelisted and determined not to cause side effects:
419
+ *
420
+ * - `this` expressions
421
+ * - `super` expressions
422
+ * - Bound identifiers
423
+ */
424
+
425
+ Scope.prototype.isStatic = function isStatic(node) {
426
+ if (t.isThisExpression(node) || t.isSuper(node)) {
427
+ return true;
428
+ }
429
+
430
+ if (t.isIdentifier(node)) {
431
+ var binding = this.getBinding(node.name);
432
+ if (binding) {
433
+ return binding.constant;
434
+ } else {
435
+ return this.hasBinding(node.name);
436
+ }
437
+ }
438
+
439
+ return false;
440
+ };
441
+
442
+ /**
443
+ * Possibly generate a memoised identifier if it is not static and has consequences.
444
+ */
445
+
446
+ Scope.prototype.maybeGenerateMemoised = function maybeGenerateMemoised(node, dontPush) {
447
+ if (this.isStatic(node)) {
448
+ return null;
449
+ } else {
450
+ var _id2 = this.generateUidIdentifierBasedOnNode(node);
451
+ if (!dontPush) this.push({ id: _id2 });
452
+ return _id2;
453
+ }
454
+ };
455
+
456
+ Scope.prototype.checkBlockScopedCollisions = function checkBlockScopedCollisions(local, kind, name, id) {
457
+ // ignore parameters
458
+ if (kind === "param") return;
459
+
460
+ // ignore hoisted functions if there's also a local let
461
+ if (kind === "hoisted" && local.kind === "let") return;
462
+
463
+ var duplicate = false;
464
+
465
+ // don't allow duplicate bindings to exist alongside
466
+ if (!duplicate) duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module";
467
+
468
+ // don't allow a local of param with a kind of let
469
+ if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const");
470
+
471
+ if (duplicate) {
472
+ throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
473
+ }
474
+ };
475
+
476
+ Scope.prototype.rename = function rename(oldName, newName, block) {
477
+ var binding = this.getBinding(oldName);
478
+ if (binding) {
479
+ newName = newName || this.generateUidIdentifier(oldName).name;
480
+ return new _renamer2.default(binding, oldName, newName).rename(block);
481
+ }
482
+ };
483
+
484
+ Scope.prototype._renameFromMap = function _renameFromMap(map, oldName, newName, value) {
485
+ if (map[oldName]) {
486
+ map[newName] = value;
487
+ map[oldName] = null;
488
+ }
489
+ };
490
+
491
+ Scope.prototype.dump = function dump() {
492
+ var sep = (0, _repeat2.default)("-", 60);
493
+ console.log(sep);
494
+ var scope = this;
495
+ do {
496
+ console.log("#", scope.block.type);
497
+ for (var name in scope.bindings) {
498
+ var binding = scope.bindings[name];
499
+ console.log(" -", name, {
500
+ constant: binding.constant,
501
+ references: binding.references,
502
+ violations: binding.constantViolations.length,
503
+ kind: binding.kind
504
+ });
505
+ }
506
+ } while (scope = scope.parent);
507
+ console.log(sep);
508
+ };
509
+
510
+ Scope.prototype.toArray = function toArray(node, i) {
511
+ var file = this.hub.file;
512
+
513
+ if (t.isIdentifier(node)) {
514
+ var binding = this.getBinding(node.name);
515
+ if (binding && binding.constant && binding.path.isGenericType("Array")) return node;
516
+ }
517
+
518
+ if (t.isArrayExpression(node)) {
519
+ return node;
520
+ }
521
+
522
+ if (t.isIdentifier(node, { name: "arguments" })) {
523
+ return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]);
524
+ }
525
+
526
+ var helperName = "toArray";
527
+ var args = [node];
528
+ if (i === true) {
529
+ helperName = "toConsumableArray";
530
+ } else if (i) {
531
+ args.push(t.numericLiteral(i));
532
+ helperName = "slicedToArray";
533
+ // TODO if (this.hub.file.isLoose("es6.forOf")) helperName += "-loose";
534
+ }
535
+ return t.callExpression(file.addHelper(helperName), args);
536
+ };
537
+
538
+ Scope.prototype.registerDeclaration = function registerDeclaration(path) {
539
+ if (path.isLabeledStatement()) {
540
+ this.registerBinding("label", path);
541
+ } else if (path.isFunctionDeclaration()) {
542
+ this.registerBinding("hoisted", path.get("id"), path);
543
+ } else if (path.isVariableDeclaration()) {
544
+ var declarations = path.get("declarations");
545
+ for (var _iterator7 = declarations, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : (0, _getIterator3.default)(_iterator7);;) {
546
+ var _ref8;
547
+
548
+ if (_isArray7) {
549
+ if (_i7 >= _iterator7.length) break;
550
+ _ref8 = _iterator7[_i7++];
551
+ } else {
552
+ _i7 = _iterator7.next();
553
+ if (_i7.done) break;
554
+ _ref8 = _i7.value;
555
+ }
556
+
557
+ var declar = _ref8;
558
+
559
+ this.registerBinding(path.node.kind, declar);
560
+ }
561
+ } else if (path.isClassDeclaration()) {
562
+ this.registerBinding("let", path);
563
+ } else if (path.isImportDeclaration()) {
564
+ var specifiers = path.get("specifiers");
565
+ for (var _iterator8 = specifiers, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : (0, _getIterator3.default)(_iterator8);;) {
566
+ var _ref9;
567
+
568
+ if (_isArray8) {
569
+ if (_i8 >= _iterator8.length) break;
570
+ _ref9 = _iterator8[_i8++];
571
+ } else {
572
+ _i8 = _iterator8.next();
573
+ if (_i8.done) break;
574
+ _ref9 = _i8.value;
575
+ }
576
+
577
+ var specifier = _ref9;
578
+
579
+ this.registerBinding("module", specifier);
580
+ }
581
+ } else if (path.isExportDeclaration()) {
582
+ var _declar = path.get("declaration");
583
+ if (_declar.isClassDeclaration() || _declar.isFunctionDeclaration() || _declar.isVariableDeclaration()) {
584
+ this.registerDeclaration(_declar);
585
+ }
586
+ } else {
587
+ this.registerBinding("unknown", path);
588
+ }
589
+ };
590
+
591
+ Scope.prototype.buildUndefinedNode = function buildUndefinedNode() {
592
+ if (this.hasBinding("undefined")) {
593
+ return t.unaryExpression("void", t.numericLiteral(0), true);
594
+ } else {
595
+ return t.identifier("undefined");
596
+ }
597
+ };
598
+
599
+ Scope.prototype.registerConstantViolation = function registerConstantViolation(path) {
600
+ var ids = path.getBindingIdentifiers();
601
+ for (var name in ids) {
602
+ var binding = this.getBinding(name);
603
+ if (binding) binding.reassign(path);
604
+ }
605
+ };
606
+
607
+ Scope.prototype.registerBinding = function registerBinding(kind, path) {
608
+ var bindingPath = arguments.length <= 2 || arguments[2] === undefined ? path : arguments[2];
609
+
610
+ if (!kind) throw new ReferenceError("no `kind`");
611
+
612
+ if (path.isVariableDeclaration()) {
613
+ var declarators = path.get("declarations");
614
+ for (var _iterator9 = declarators, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : (0, _getIterator3.default)(_iterator9);;) {
615
+ var _ref10;
616
+
617
+ if (_isArray9) {
618
+ if (_i9 >= _iterator9.length) break;
619
+ _ref10 = _iterator9[_i9++];
620
+ } else {
621
+ _i9 = _iterator9.next();
622
+ if (_i9.done) break;
623
+ _ref10 = _i9.value;
624
+ }
625
+
626
+ var declar = _ref10;
627
+
628
+ this.registerBinding(kind, declar);
629
+ }
630
+ return;
631
+ }
632
+
633
+ var parent = this.getProgramParent();
634
+ var ids = path.getBindingIdentifiers(true);
635
+
636
+ for (var name in ids) {
637
+ for (var _iterator10 = ids[name], _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : (0, _getIterator3.default)(_iterator10);;) {
638
+ var _ref11;
639
+
640
+ if (_isArray10) {
641
+ if (_i10 >= _iterator10.length) break;
642
+ _ref11 = _iterator10[_i10++];
643
+ } else {
644
+ _i10 = _iterator10.next();
645
+ if (_i10.done) break;
646
+ _ref11 = _i10.value;
647
+ }
648
+
649
+ var _id3 = _ref11;
650
+
651
+ var local = this.getOwnBinding(name);
652
+ if (local) {
653
+ // same identifier so continue safely as we're likely trying to register it
654
+ // multiple times
655
+ if (local.identifier === _id3) continue;
656
+
657
+ this.checkBlockScopedCollisions(local, kind, name, _id3);
658
+ }
659
+
660
+ // It's erroneous that we currently consider flow a binding, however, we can't
661
+ // remove it because people might be depending on it. See warning section
662
+ // in `warnOnFlowBinding`.
663
+ if (local && local.path.isFlow()) local = null;
664
+
665
+ parent.references[name] = true;
666
+
667
+ this.bindings[name] = new _binding3.default({
668
+ identifier: _id3,
669
+ existing: local,
670
+ scope: this,
671
+ path: bindingPath,
672
+ kind: kind
673
+ });
674
+ }
675
+ }
676
+ };
677
+
678
+ Scope.prototype.addGlobal = function addGlobal(node) {
679
+ this.globals[node.name] = node;
680
+ };
681
+
682
+ Scope.prototype.hasUid = function hasUid(name) {
683
+ var scope = this;
684
+
685
+ do {
686
+ if (scope.uids[name]) return true;
687
+ } while (scope = scope.parent);
688
+
689
+ return false;
690
+ };
691
+
692
+ Scope.prototype.hasGlobal = function hasGlobal(name) {
693
+ var scope = this;
694
+
695
+ do {
696
+ if (scope.globals[name]) return true;
697
+ } while (scope = scope.parent);
698
+
699
+ return false;
700
+ };
701
+
702
+ Scope.prototype.hasReference = function hasReference(name) {
703
+ var scope = this;
704
+
705
+ do {
706
+ if (scope.references[name]) return true;
707
+ } while (scope = scope.parent);
708
+
709
+ return false;
710
+ };
711
+
712
+ Scope.prototype.isPure = function isPure(node, constantsOnly) {
713
+ if (t.isIdentifier(node)) {
714
+ var binding = this.getBinding(node.name);
715
+ if (!binding) return false;
716
+ if (constantsOnly) return binding.constant;
717
+ return true;
718
+ } else if (t.isClass(node)) {
719
+ if (node.superClass && !this.isPure(node.superClass, constantsOnly)) return false;
720
+ return this.isPure(node.body, constantsOnly);
721
+ } else if (t.isClassBody(node)) {
722
+ for (var _iterator11 = node.body, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : (0, _getIterator3.default)(_iterator11);;) {
723
+ var _ref12;
724
+
725
+ if (_isArray11) {
726
+ if (_i11 >= _iterator11.length) break;
727
+ _ref12 = _iterator11[_i11++];
728
+ } else {
729
+ _i11 = _iterator11.next();
730
+ if (_i11.done) break;
731
+ _ref12 = _i11.value;
732
+ }
733
+
734
+ var method = _ref12;
735
+
736
+ if (!this.isPure(method, constantsOnly)) return false;
737
+ }
738
+ return true;
739
+ } else if (t.isBinary(node)) {
740
+ return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
741
+ } else if (t.isArrayExpression(node)) {
742
+ for (var _iterator12 = node.elements, _isArray12 = Array.isArray(_iterator12), _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : (0, _getIterator3.default)(_iterator12);;) {
743
+ var _ref13;
744
+
745
+ if (_isArray12) {
746
+ if (_i12 >= _iterator12.length) break;
747
+ _ref13 = _iterator12[_i12++];
748
+ } else {
749
+ _i12 = _iterator12.next();
750
+ if (_i12.done) break;
751
+ _ref13 = _i12.value;
752
+ }
753
+
754
+ var elem = _ref13;
755
+
756
+ if (!this.isPure(elem, constantsOnly)) return false;
757
+ }
758
+ return true;
759
+ } else if (t.isObjectExpression(node)) {
760
+ for (var _iterator13 = node.properties, _isArray13 = Array.isArray(_iterator13), _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : (0, _getIterator3.default)(_iterator13);;) {
761
+ var _ref14;
762
+
763
+ if (_isArray13) {
764
+ if (_i13 >= _iterator13.length) break;
765
+ _ref14 = _iterator13[_i13++];
766
+ } else {
767
+ _i13 = _iterator13.next();
768
+ if (_i13.done) break;
769
+ _ref14 = _i13.value;
770
+ }
771
+
772
+ var prop = _ref14;
773
+
774
+ if (!this.isPure(prop, constantsOnly)) return false;
775
+ }
776
+ return true;
777
+ } else if (t.isClassMethod(node)) {
778
+ if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
779
+ if (node.kind === "get" || node.kind === "set") return false;
780
+ return true;
781
+ } else if (t.isClassProperty(node) || t.isObjectProperty(node)) {
782
+ if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
783
+ return this.isPure(node.value, constantsOnly);
784
+ } else if (t.isUnaryExpression(node)) {
785
+ return this.isPure(node.argument, constantsOnly);
786
+ } else {
787
+ return t.isPureish(node);
788
+ }
789
+ };
790
+
791
+ /**
792
+ * Set some arbitrary data on the current scope.
793
+ */
794
+
795
+ Scope.prototype.setData = function setData(key, val) {
796
+ return this.data[key] = val;
797
+ };
798
+
799
+ /**
800
+ * Recursively walk up scope tree looking for the data `key`.
801
+ */
802
+
803
+ Scope.prototype.getData = function getData(key) {
804
+ var scope = this;
805
+ do {
806
+ var data = scope.data[key];
807
+ if (data != null) return data;
808
+ } while (scope = scope.parent);
809
+ };
810
+
811
+ /**
812
+ * Recursively walk up scope tree looking for the data `key` and if it exists,
813
+ * remove it.
814
+ */
815
+
816
+ Scope.prototype.removeData = function removeData(key) {
817
+ var scope = this;
818
+ do {
819
+ var data = scope.data[key];
820
+ if (data != null) scope.data[key] = null;
821
+ } while (scope = scope.parent);
822
+ };
823
+
824
+ Scope.prototype.init = function init() {
825
+ if (!this.references) this.crawl();
826
+ };
827
+
828
+ Scope.prototype.crawl = function crawl() {
829
+ _crawlCallsCount++;
830
+ this._crawl();
831
+ _crawlCallsCount--;
832
+ };
833
+
834
+ Scope.prototype._crawl = function _crawl() {
835
+ var path = this.path;
836
+
837
+ //
838
+
839
+ this.references = (0, _create2.default)(null);
840
+ this.bindings = (0, _create2.default)(null);
841
+ this.globals = (0, _create2.default)(null);
842
+ this.uids = (0, _create2.default)(null);
843
+ this.data = (0, _create2.default)(null);
844
+
845
+ // ForStatement - left, init
846
+
847
+ if (path.isLoop()) {
848
+ for (var _iterator14 = t.FOR_INIT_KEYS, _isArray14 = Array.isArray(_iterator14), _i14 = 0, _iterator14 = _isArray14 ? _iterator14 : (0, _getIterator3.default)(_iterator14);;) {
849
+ var _ref15;
850
+
851
+ if (_isArray14) {
852
+ if (_i14 >= _iterator14.length) break;
853
+ _ref15 = _iterator14[_i14++];
854
+ } else {
855
+ _i14 = _iterator14.next();
856
+ if (_i14.done) break;
857
+ _ref15 = _i14.value;
858
+ }
859
+
860
+ var key = _ref15;
861
+
862
+ var node = path.get(key);
863
+ if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
864
+ }
865
+ }
866
+
867
+ // FunctionExpression - id
868
+
869
+ if (path.isFunctionExpression() && path.has("id")) {
870
+ if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
871
+ this.registerBinding("local", path.get("id"), path);
872
+ }
873
+ }
874
+
875
+ // Class
876
+
877
+ if (path.isClassExpression() && path.has("id")) {
878
+ if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
879
+ this.registerBinding("local", path);
880
+ }
881
+ }
882
+
883
+ // Function - params, rest
884
+
885
+ if (path.isFunction()) {
886
+ var params = path.get("params");
887
+ for (var _iterator15 = params, _isArray15 = Array.isArray(_iterator15), _i15 = 0, _iterator15 = _isArray15 ? _iterator15 : (0, _getIterator3.default)(_iterator15);;) {
888
+ var _ref16;
889
+
890
+ if (_isArray15) {
891
+ if (_i15 >= _iterator15.length) break;
892
+ _ref16 = _iterator15[_i15++];
893
+ } else {
894
+ _i15 = _iterator15.next();
895
+ if (_i15.done) break;
896
+ _ref16 = _i15.value;
897
+ }
898
+
899
+ var param = _ref16;
900
+
901
+ this.registerBinding("param", param);
902
+ }
903
+ }
904
+
905
+ // CatchClause - param
906
+
907
+ if (path.isCatchClause()) {
908
+ this.registerBinding("let", path);
909
+ }
910
+
911
+ // Program
912
+
913
+ var parent = this.getProgramParent();
914
+ if (parent.crawling) return;
915
+
916
+ var state = {
917
+ references: [],
918
+ constantViolations: [],
919
+ assignments: []
920
+ };
921
+
922
+ this.crawling = true;
923
+ path.traverse(collectorVisitor, state);
924
+ this.crawling = false;
925
+
926
+ // register assignments
927
+ for (var _iterator16 = state.assignments, _isArray16 = Array.isArray(_iterator16), _i16 = 0, _iterator16 = _isArray16 ? _iterator16 : (0, _getIterator3.default)(_iterator16);;) {
928
+ var _ref17;
929
+
930
+ if (_isArray16) {
931
+ if (_i16 >= _iterator16.length) break;
932
+ _ref17 = _iterator16[_i16++];
933
+ } else {
934
+ _i16 = _iterator16.next();
935
+ if (_i16.done) break;
936
+ _ref17 = _i16.value;
937
+ }
938
+
939
+ var _path = _ref17;
940
+
941
+ // register undeclared bindings as globals
942
+ var ids = _path.getBindingIdentifiers();
943
+ var programParent = void 0;
944
+ for (var name in ids) {
945
+ if (_path.scope.getBinding(name)) continue;
946
+
947
+ programParent = programParent || _path.scope.getProgramParent();
948
+ programParent.addGlobal(ids[name]);
949
+ }
950
+
951
+ // register as constant violation
952
+ _path.scope.registerConstantViolation(_path);
953
+ }
954
+
955
+ // register references
956
+ for (var _iterator17 = state.references, _isArray17 = Array.isArray(_iterator17), _i17 = 0, _iterator17 = _isArray17 ? _iterator17 : (0, _getIterator3.default)(_iterator17);;) {
957
+ var _ref18;
958
+
959
+ if (_isArray17) {
960
+ if (_i17 >= _iterator17.length) break;
961
+ _ref18 = _iterator17[_i17++];
962
+ } else {
963
+ _i17 = _iterator17.next();
964
+ if (_i17.done) break;
965
+ _ref18 = _i17.value;
966
+ }
967
+
968
+ var ref = _ref18;
969
+
970
+ var binding = ref.scope.getBinding(ref.node.name);
971
+ if (binding) {
972
+ binding.reference(ref);
973
+ } else {
974
+ ref.scope.getProgramParent().addGlobal(ref.node);
975
+ }
976
+ }
977
+
978
+ // register constant violations
979
+ for (var _iterator18 = state.constantViolations, _isArray18 = Array.isArray(_iterator18), _i18 = 0, _iterator18 = _isArray18 ? _iterator18 : (0, _getIterator3.default)(_iterator18);;) {
980
+ var _ref19;
981
+
982
+ if (_isArray18) {
983
+ if (_i18 >= _iterator18.length) break;
984
+ _ref19 = _iterator18[_i18++];
985
+ } else {
986
+ _i18 = _iterator18.next();
987
+ if (_i18.done) break;
988
+ _ref19 = _i18.value;
989
+ }
990
+
991
+ var _path2 = _ref19;
992
+
993
+ _path2.scope.registerConstantViolation(_path2);
994
+ }
995
+ };
996
+
997
+ Scope.prototype.push = function push(opts) {
998
+ var path = this.path;
999
+
1000
+ if (!path.isBlockStatement() && !path.isProgram()) {
1001
+ path = this.getBlockParent().path;
1002
+ }
1003
+
1004
+ if (path.isSwitchStatement()) {
1005
+ path = this.getFunctionParent().path;
1006
+ }
1007
+
1008
+ if (path.isLoop() || path.isCatchClause() || path.isFunction()) {
1009
+ t.ensureBlock(path.node);
1010
+ path = path.get("body");
1011
+ }
1012
+
1013
+ var unique = opts.unique;
1014
+ var kind = opts.kind || "var";
1015
+ var blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist;
1016
+
1017
+ var dataKey = "declaration:" + kind + ":" + blockHoist;
1018
+ var declarPath = !unique && path.getData(dataKey);
1019
+
1020
+ if (!declarPath) {
1021
+ var declar = t.variableDeclaration(kind, []);
1022
+ declar._generated = true;
1023
+ declar._blockHoist = blockHoist;
1024
+
1025
+ var _path$unshiftContaine = path.unshiftContainer("body", [declar]);
1026
+
1027
+ declarPath = _path$unshiftContaine[0];
1028
+
1029
+ if (!unique) path.setData(dataKey, declarPath);
1030
+ }
1031
+
1032
+ var declarator = t.variableDeclarator(opts.id, opts.init);
1033
+ declarPath.node.declarations.push(declarator);
1034
+ this.registerBinding(kind, declarPath.get("declarations").pop());
1035
+ };
1036
+
1037
+ /**
1038
+ * Walk up to the top of the scope tree and get the `Program`.
1039
+ */
1040
+
1041
+ Scope.prototype.getProgramParent = function getProgramParent() {
1042
+ var scope = this;
1043
+ do {
1044
+ if (scope.path.isProgram()) {
1045
+ return scope;
1046
+ }
1047
+ } while (scope = scope.parent);
1048
+ throw new Error("We couldn't find a Function or Program...");
1049
+ };
1050
+
1051
+ /**
1052
+ * Walk up the scope tree until we hit either a Function or reach the
1053
+ * very top and hit Program.
1054
+ */
1055
+
1056
+ Scope.prototype.getFunctionParent = function getFunctionParent() {
1057
+ var scope = this;
1058
+ do {
1059
+ if (scope.path.isFunctionParent()) {
1060
+ return scope;
1061
+ }
1062
+ } while (scope = scope.parent);
1063
+ throw new Error("We couldn't find a Function or Program...");
1064
+ };
1065
+
1066
+ /**
1067
+ * Walk up the scope tree until we hit either a BlockStatement/Loop/Program/Function/Switch or reach the
1068
+ * very top and hit Program.
1069
+ */
1070
+
1071
+ Scope.prototype.getBlockParent = function getBlockParent() {
1072
+ var scope = this;
1073
+ do {
1074
+ if (scope.path.isBlockParent()) {
1075
+ return scope;
1076
+ }
1077
+ } while (scope = scope.parent);
1078
+ throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
1079
+ };
1080
+
1081
+ /**
1082
+ * Walks the scope tree and gathers **all** bindings.
1083
+ */
1084
+
1085
+ Scope.prototype.getAllBindings = function getAllBindings() {
1086
+ var ids = (0, _create2.default)(null);
1087
+
1088
+ var scope = this;
1089
+ do {
1090
+ (0, _defaults2.default)(ids, scope.bindings);
1091
+ scope = scope.parent;
1092
+ } while (scope);
1093
+
1094
+ return ids;
1095
+ };
1096
+
1097
+ /**
1098
+ * Walks the scope tree and gathers all declarations of `kind`.
1099
+ */
1100
+
1101
+ Scope.prototype.getAllBindingsOfKind = function getAllBindingsOfKind() {
1102
+ var ids = (0, _create2.default)(null);
1103
+
1104
+ for (var _iterator19 = arguments, _isArray19 = Array.isArray(_iterator19), _i19 = 0, _iterator19 = _isArray19 ? _iterator19 : (0, _getIterator3.default)(_iterator19);;) {
1105
+ var _ref20;
1106
+
1107
+ if (_isArray19) {
1108
+ if (_i19 >= _iterator19.length) break;
1109
+ _ref20 = _iterator19[_i19++];
1110
+ } else {
1111
+ _i19 = _iterator19.next();
1112
+ if (_i19.done) break;
1113
+ _ref20 = _i19.value;
1114
+ }
1115
+
1116
+ var kind = _ref20;
1117
+
1118
+ var scope = this;
1119
+ do {
1120
+ for (var name in scope.bindings) {
1121
+ var binding = scope.bindings[name];
1122
+ if (binding.kind === kind) ids[name] = binding;
1123
+ }
1124
+ scope = scope.parent;
1125
+ } while (scope);
1126
+ }
1127
+
1128
+ return ids;
1129
+ };
1130
+
1131
+ Scope.prototype.bindingIdentifierEquals = function bindingIdentifierEquals(name, node) {
1132
+ return this.getBindingIdentifier(name) === node;
1133
+ };
1134
+
1135
+ Scope.prototype.warnOnFlowBinding = function warnOnFlowBinding(binding) {
1136
+ if (_crawlCallsCount === 0 && binding && binding.path.isFlow()) {
1137
+ 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 6.8. To find out the caller, grep for this\n message and change it to a `console.trace()`.\n ");
1138
+ }
1139
+ return binding;
1140
+ };
1141
+
1142
+ Scope.prototype.getBinding = function getBinding(name) {
1143
+ var scope = this;
1144
+
1145
+ do {
1146
+ var binding = scope.getOwnBinding(name);
1147
+ if (binding) return this.warnOnFlowBinding(binding);
1148
+ } while (scope = scope.parent);
1149
+ };
1150
+
1151
+ Scope.prototype.getOwnBinding = function getOwnBinding(name) {
1152
+ return this.warnOnFlowBinding(this.bindings[name]);
1153
+ };
1154
+
1155
+ Scope.prototype.getBindingIdentifier = function getBindingIdentifier(name) {
1156
+ var info = this.getBinding(name);
1157
+ return info && info.identifier;
1158
+ };
1159
+
1160
+ Scope.prototype.getOwnBindingIdentifier = function getOwnBindingIdentifier(name) {
1161
+ var binding = this.bindings[name];
1162
+ return binding && binding.identifier;
1163
+ };
1164
+
1165
+ Scope.prototype.hasOwnBinding = function hasOwnBinding(name) {
1166
+ return !!this.getOwnBinding(name);
1167
+ };
1168
+
1169
+ Scope.prototype.hasBinding = function hasBinding(name, noGlobals) {
1170
+ if (!name) return false;
1171
+ if (this.hasOwnBinding(name)) return true;
1172
+ if (this.parentHasBinding(name, noGlobals)) return true;
1173
+ if (this.hasUid(name)) return true;
1174
+ if (!noGlobals && (0, _includes2.default)(Scope.globals, name)) return true;
1175
+ if (!noGlobals && (0, _includes2.default)(Scope.contextVariables, name)) return true;
1176
+ return false;
1177
+ };
1178
+
1179
+ Scope.prototype.parentHasBinding = function parentHasBinding(name, noGlobals) {
1180
+ return this.parent && this.parent.hasBinding(name, noGlobals);
1181
+ };
1182
+
1183
+ /**
1184
+ * Move a binding of `name` to another `scope`.
1185
+ */
1186
+
1187
+ Scope.prototype.moveBindingTo = function moveBindingTo(name, scope) {
1188
+ var info = this.getBinding(name);
1189
+ if (info) {
1190
+ info.scope.removeOwnBinding(name);
1191
+ info.scope = scope;
1192
+ scope.bindings[name] = info;
1193
+ }
1194
+ };
1195
+
1196
+ Scope.prototype.removeOwnBinding = function removeOwnBinding(name) {
1197
+ delete this.bindings[name];
1198
+ };
1199
+
1200
+ Scope.prototype.removeBinding = function removeBinding(name) {
1201
+ // clear literal binding
1202
+ var info = this.getBinding(name);
1203
+ if (info) {
1204
+ info.scope.removeOwnBinding(name);
1205
+ }
1206
+
1207
+ // clear uids with this name - https://github.com/babel/babel/issues/2101
1208
+ var scope = this;
1209
+ do {
1210
+ if (scope.uids[name]) {
1211
+ scope.uids[name] = false;
1212
+ }
1213
+ } while (scope = scope.parent);
1214
+ };
1215
+
1216
+ return Scope;
1217
+ }();
1218
+
1219
+ Scope.globals = (0, _keys2.default)(_globals2.default.builtin);
1220
+ Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
1221
+ exports.default = Scope;
1222
+ module.exports = exports["default"];