@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.

@@ -24,9 +24,9 @@ exports.isConstantExpression = isConstantExpression;
24
24
  exports.is = void 0;
25
25
 
26
26
  function _includes() {
27
- const data = _interopRequireDefault(require("lodash/includes"));
27
+ var data = _interopRequireDefault(require("lodash/includes"));
28
28
 
29
- _includes = function () {
29
+ _includes = function _includes() {
30
30
  return data;
31
31
  };
32
32
 
@@ -34,9 +34,9 @@ function _includes() {
34
34
  }
35
35
 
36
36
  function t() {
37
- const data = _interopRequireWildcard(require("@babel/types"));
37
+ var data = _interopRequireWildcard(require("@babel/types"));
38
38
 
39
- t = function () {
39
+ t = function t() {
40
40
  return data;
41
41
  };
42
42
 
@@ -52,7 +52,7 @@ function matchesPattern(pattern, allowPartial) {
52
52
  }
53
53
 
54
54
  function has(key) {
55
- const val = this.node && this.node[key];
55
+ var val = this.node && this.node[key];
56
56
 
57
57
  if (val && Array.isArray(val)) {
58
58
  return !!val.length;
@@ -65,7 +65,7 @@ function isStatic() {
65
65
  return this.scope.isStatic(this.node);
66
66
  }
67
67
 
68
- const is = has;
68
+ var is = has;
69
69
  exports.is = is;
70
70
 
71
71
  function isnt(key) {
@@ -99,11 +99,11 @@ function canSwapBetweenExpressionAndStatement(replacement) {
99
99
  }
100
100
 
101
101
  function isCompletionRecord(allowInsideFunction) {
102
- let path = this;
103
- let first = true;
102
+ var path = this;
103
+ var first = true;
104
104
 
105
105
  do {
106
- const container = path.container;
106
+ var container = path.container;
107
107
 
108
108
  if (path.isFunction() && !first) {
109
109
  return !!allowInsideFunction;
@@ -129,10 +129,10 @@ function isStatementOrBlock() {
129
129
 
130
130
  function referencesImport(moduleSource, importName) {
131
131
  if (!this.isReferencedIdentifier()) return false;
132
- const binding = this.scope.getBinding(this.node.name);
132
+ var binding = this.scope.getBinding(this.node.name);
133
133
  if (!binding || binding.kind !== "module") return false;
134
- const path = binding.path;
135
- const parent = path.parentPath;
134
+ var path = binding.path;
135
+ var parent = path.parentPath;
136
136
  if (!parent.isImportDeclaration()) return false;
137
137
 
138
138
  if (parent.node.source.value === moduleSource) {
@@ -157,7 +157,7 @@ function referencesImport(moduleSource, importName) {
157
157
  }
158
158
 
159
159
  function getSource() {
160
- const node = this.node;
160
+ var node = this.node;
161
161
 
162
162
  if (node.end) {
163
163
  return this.hub.file.code.slice(node.start, node.end);
@@ -171,11 +171,11 @@ function willIMaybeExecuteBefore(target) {
171
171
  }
172
172
 
173
173
  function _guessExecutionStatusRelativeTo(target) {
174
- const targetFuncParent = target.scope.getFunctionParent() || target.scope.getProgramParent();
175
- const selfFuncParent = this.scope.getFunctionParent() || target.scope.getProgramParent();
174
+ var targetFuncParent = target.scope.getFunctionParent() || target.scope.getProgramParent();
175
+ var selfFuncParent = this.scope.getFunctionParent() || target.scope.getProgramParent();
176
176
 
177
177
  if (targetFuncParent.node !== selfFuncParent.node) {
178
- const status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent);
178
+ var status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent);
179
179
 
180
180
  if (status) {
181
181
  return status;
@@ -184,15 +184,15 @@ function _guessExecutionStatusRelativeTo(target) {
184
184
  }
185
185
  }
186
186
 
187
- const targetPaths = target.getAncestry();
187
+ var targetPaths = target.getAncestry();
188
188
  if (targetPaths.indexOf(this) >= 0) return "after";
189
- const selfPaths = this.getAncestry();
190
- let commonPath;
191
- let targetIndex;
192
- let selfIndex;
189
+ var selfPaths = this.getAncestry();
190
+ var commonPath;
191
+ var targetIndex;
192
+ var selfIndex;
193
193
 
194
194
  for (selfIndex = 0; selfIndex < selfPaths.length; selfIndex++) {
195
- const selfPath = selfPaths[selfIndex];
195
+ var selfPath = selfPaths[selfIndex];
196
196
  targetIndex = targetPaths.indexOf(selfPath);
197
197
 
198
198
  if (targetIndex >= 0) {
@@ -205,8 +205,8 @@ function _guessExecutionStatusRelativeTo(target) {
205
205
  return "before";
206
206
  }
207
207
 
208
- const targetRelationship = targetPaths[targetIndex - 1];
209
- const selfRelationship = selfPaths[selfIndex - 1];
208
+ var targetRelationship = targetPaths[targetIndex - 1];
209
+ var selfRelationship = selfPaths[selfIndex - 1];
210
210
 
211
211
  if (!targetRelationship || !selfRelationship) {
212
212
  return "before";
@@ -216,32 +216,59 @@ function _guessExecutionStatusRelativeTo(target) {
216
216
  return targetRelationship.key > selfRelationship.key ? "before" : "after";
217
217
  }
218
218
 
219
- const keys = t().VISITOR_KEYS[commonPath.type];
220
- const targetKeyPosition = keys.indexOf(targetRelationship.key);
221
- const selfKeyPosition = keys.indexOf(selfRelationship.key);
219
+ var keys = t().VISITOR_KEYS[commonPath.type];
220
+ var targetKeyPosition = keys.indexOf(targetRelationship.key);
221
+ var selfKeyPosition = keys.indexOf(selfRelationship.key);
222
222
  return targetKeyPosition > selfKeyPosition ? "before" : "after";
223
223
  }
224
224
 
225
225
  function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) {
226
- const targetFuncPath = targetFuncParent.path;
226
+ var targetFuncPath = targetFuncParent.path;
227
227
  if (!targetFuncPath.isFunctionDeclaration()) return;
228
- const binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name);
228
+ var binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name);
229
229
  if (!binding.references) return "before";
230
- const referencePaths = binding.referencePaths;
230
+ var referencePaths = binding.referencePaths;
231
+
232
+ for (var _iterator = referencePaths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
233
+ var _ref;
234
+
235
+ if (_isArray) {
236
+ if (_i >= _iterator.length) break;
237
+ _ref = _iterator[_i++];
238
+ } else {
239
+ _i = _iterator.next();
240
+ if (_i.done) break;
241
+ _ref = _i.value;
242
+ }
243
+
244
+ var path = _ref;
231
245
 
232
- for (const path of referencePaths) {
233
246
  if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
234
247
  return;
235
248
  }
236
249
  }
237
250
 
238
- let allStatus;
251
+ var allStatus;
252
+
253
+ for (var _iterator2 = referencePaths, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
254
+ var _ref2;
255
+
256
+ if (_isArray2) {
257
+ if (_i2 >= _iterator2.length) break;
258
+ _ref2 = _iterator2[_i2++];
259
+ } else {
260
+ _i2 = _iterator2.next();
261
+ if (_i2.done) break;
262
+ _ref2 = _i2.value;
263
+ }
239
264
 
240
- for (const path of referencePaths) {
241
- const childOfFunction = !!path.find(path => path.node === targetFuncPath.node);
265
+ var _path = _ref2;
266
+ var childOfFunction = !!_path.find(function (path) {
267
+ return path.node === targetFuncPath.node;
268
+ });
242
269
  if (childOfFunction) continue;
243
270
 
244
- const status = this._guessExecutionStatusRelativeTo(path);
271
+ var status = this._guessExecutionStatusRelativeTo(_path);
245
272
 
246
273
  if (allStatus) {
247
274
  if (allStatus !== status) return;
@@ -267,31 +294,35 @@ function _resolve(dangerous, resolved) {
267
294
  return this.get("init").resolve(dangerous, resolved);
268
295
  } else {}
269
296
  } else if (this.isReferencedIdentifier()) {
270
- const binding = this.scope.getBinding(this.node.name);
297
+ var binding = this.scope.getBinding(this.node.name);
271
298
  if (!binding) return;
272
299
  if (!binding.constant) return;
273
300
  if (binding.kind === "module") return;
274
301
 
275
302
  if (binding.path !== this) {
276
- const ret = binding.path.resolve(dangerous, resolved);
277
- if (this.find(parent => parent.node === ret.node)) return;
303
+ var ret = binding.path.resolve(dangerous, resolved);
304
+ if (this.find(function (parent) {
305
+ return parent.node === ret.node;
306
+ })) return;
278
307
  return ret;
279
308
  }
280
309
  } else if (this.isTypeCastExpression()) {
281
310
  return this.get("expression").resolve(dangerous, resolved);
282
311
  } else if (dangerous && this.isMemberExpression()) {
283
- const targetKey = this.toComputedKey();
312
+ var targetKey = this.toComputedKey();
284
313
  if (!t().isLiteral(targetKey)) return;
285
- const targetName = targetKey.value;
286
- const target = this.get("object").resolve(dangerous, resolved);
314
+ var targetName = targetKey.value;
315
+ var target = this.get("object").resolve(dangerous, resolved);
287
316
 
288
317
  if (target.isObjectExpression()) {
289
- const props = target.get("properties");
318
+ var props = target.get("properties");
319
+ var _arr = props;
290
320
 
291
- for (const prop of props) {
321
+ for (var _i3 = 0; _i3 < _arr.length; _i3++) {
322
+ var prop = _arr[_i3];
292
323
  if (!prop.isProperty()) continue;
293
- const key = prop.get("key");
294
- let match = prop.isnt("computed") && key.isIdentifier({
324
+ var key = prop.get("key");
325
+ var match = prop.isnt("computed") && key.isIdentifier({
295
326
  name: targetName
296
327
  });
297
328
  match = match || key.isLiteral({
@@ -300,8 +331,8 @@ function _resolve(dangerous, resolved) {
300
331
  if (match) return prop.get("value").resolve(dangerous, resolved);
301
332
  }
302
333
  } else if (target.isArrayExpression() && !isNaN(+targetName)) {
303
- const elems = target.get("elements");
304
- const elem = elems[targetName];
334
+ var elems = target.get("elements");
335
+ var elem = elems[targetName];
305
336
  if (elem) return elem.resolve(dangerous, resolved);
306
337
  }
307
338
  }
@@ -309,7 +340,7 @@ function _resolve(dangerous, resolved) {
309
340
 
310
341
  function isConstantExpression() {
311
342
  if (this.isIdentifier()) {
312
- const binding = this.scope.getBinding(this.node.name);
343
+ var binding = this.scope.getBinding(this.node.name);
313
344
 
314
345
  if (!binding) {
315
346
  return false;
@@ -324,7 +355,9 @@ function isConstantExpression() {
324
355
  }
325
356
 
326
357
  if (this.isTemplateLiteral()) {
327
- return this.get("expressions").every(expression => expression.isConstantExpression());
358
+ return this.get("expressions").every(function (expression) {
359
+ return expression.isConstantExpression();
360
+ });
328
361
  }
329
362
 
330
363
  return true;
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  function t() {
9
- const data = _interopRequireWildcard(require("@babel/types"));
9
+ var data = _interopRequireWildcard(require("@babel/types"));
10
10
 
11
- t = function () {
11
+ t = function t() {
12
12
  return data;
13
13
  };
14
14
 
@@ -17,14 +17,14 @@ function t() {
17
17
 
18
18
  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; } }
19
19
 
20
- const referenceVisitor = {
21
- ReferencedIdentifier(path, state) {
20
+ var referenceVisitor = {
21
+ ReferencedIdentifier: function ReferencedIdentifier(path, state) {
22
22
  if (path.isJSXIdentifier() && t().react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
23
23
  return;
24
24
  }
25
25
 
26
26
  if (path.node.name === "this") {
27
- let scope = path.scope;
27
+ var scope = path.scope;
28
28
 
29
29
  do {
30
30
  if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
@@ -35,16 +35,15 @@ const referenceVisitor = {
35
35
  if (scope) state.breakOnScopePaths.push(scope.path);
36
36
  }
37
37
 
38
- const binding = path.scope.getBinding(path.node.name);
38
+ var binding = path.scope.getBinding(path.node.name);
39
39
  if (!binding) return;
40
40
  if (binding !== state.scope.getBinding(path.node.name)) return;
41
41
  state.bindings[path.node.name] = binding;
42
42
  }
43
-
44
43
  };
45
44
 
46
- class PathHoister {
47
- constructor(path, scope) {
45
+ var PathHoister = function () {
46
+ function PathHoister(path, scope) {
48
47
  this.breakOnScopePaths = [];
49
48
  this.bindings = {};
50
49
  this.scopes = [];
@@ -53,9 +52,11 @@ class PathHoister {
53
52
  this.attachAfter = false;
54
53
  }
55
54
 
56
- isCompatibleScope(scope) {
57
- for (const key in this.bindings) {
58
- const binding = this.bindings[key];
55
+ var _proto = PathHoister.prototype;
56
+
57
+ _proto.isCompatibleScope = function isCompatibleScope(scope) {
58
+ for (var key in this.bindings) {
59
+ var binding = this.bindings[key];
59
60
 
60
61
  if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
61
62
  return false;
@@ -63,10 +64,10 @@ class PathHoister {
63
64
  }
64
65
 
65
66
  return true;
66
- }
67
+ };
67
68
 
68
- getCompatibleScopes() {
69
- let scope = this.path.scope;
69
+ _proto.getCompatibleScopes = function getCompatibleScopes() {
70
+ var scope = this.path.scope;
70
71
 
71
72
  do {
72
73
  if (this.isCompatibleScope(scope)) {
@@ -79,34 +80,37 @@ class PathHoister {
79
80
  break;
80
81
  }
81
82
  } while (scope = scope.parent);
82
- }
83
+ };
83
84
 
84
- getAttachmentPath() {
85
- let path = this._getAttachmentPath();
85
+ _proto.getAttachmentPath = function getAttachmentPath() {
86
+ var path = this._getAttachmentPath();
86
87
 
87
88
  if (!path) return;
88
- let targetScope = path.scope;
89
+ var targetScope = path.scope;
89
90
 
90
91
  if (targetScope.path === path) {
91
92
  targetScope = path.scope.parent;
92
93
  }
93
94
 
94
95
  if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
95
- for (const name in this.bindings) {
96
+ for (var name in this.bindings) {
96
97
  if (!targetScope.hasOwnBinding(name)) continue;
97
- const binding = this.bindings[name];
98
+ var binding = this.bindings[name];
98
99
 
99
100
  if (binding.kind === "param" || binding.path.parentKey === "params") {
100
101
  continue;
101
102
  }
102
103
 
103
- const bindingParentPath = this.getAttachmentParentForPath(binding.path);
104
+ var bindingParentPath = this.getAttachmentParentForPath(binding.path);
104
105
 
105
106
  if (bindingParentPath.key >= path.key) {
106
107
  this.attachAfter = true;
107
108
  path = binding.path;
109
+ var _arr = binding.constantViolations;
110
+
111
+ for (var _i = 0; _i < _arr.length; _i++) {
112
+ var violationPath = _arr[_i];
108
113
 
109
- for (const violationPath of binding.constantViolations) {
110
114
  if (this.getAttachmentParentForPath(violationPath).key > path.key) {
111
115
  path = violationPath;
112
116
  }
@@ -116,19 +120,19 @@ class PathHoister {
116
120
  }
117
121
 
118
122
  return path;
119
- }
123
+ };
120
124
 
121
- _getAttachmentPath() {
122
- const scopes = this.scopes;
123
- const scope = scopes.pop();
125
+ _proto._getAttachmentPath = function _getAttachmentPath() {
126
+ var scopes = this.scopes;
127
+ var scope = scopes.pop();
124
128
  if (!scope) return;
125
129
 
126
130
  if (scope.path.isFunction()) {
127
131
  if (this.hasOwnParamBindings(scope)) {
128
132
  if (this.scope === scope) return;
129
- const bodies = scope.path.get("body").get("body");
133
+ var bodies = scope.path.get("body").get("body");
130
134
 
131
- for (let i = 0; i < bodies.length; i++) {
135
+ for (var i = 0; i < bodies.length; i++) {
132
136
  if (bodies[i].node._blockHoist) continue;
133
137
  return bodies[i];
134
138
  }
@@ -138,42 +142,45 @@ class PathHoister {
138
142
  } else if (scope.path.isProgram()) {
139
143
  return this.getNextScopeAttachmentParent();
140
144
  }
141
- }
145
+ };
142
146
 
143
- getNextScopeAttachmentParent() {
144
- const scope = this.scopes.pop();
147
+ _proto.getNextScopeAttachmentParent = function getNextScopeAttachmentParent() {
148
+ var scope = this.scopes.pop();
145
149
  if (scope) return this.getAttachmentParentForPath(scope.path);
146
- }
150
+ };
147
151
 
148
- getAttachmentParentForPath(path) {
152
+ _proto.getAttachmentParentForPath = function getAttachmentParentForPath(path) {
149
153
  do {
150
154
  if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
151
155
  return path;
152
156
  }
153
157
  } while (path = path.parentPath);
154
- }
158
+ };
155
159
 
156
- hasOwnParamBindings(scope) {
157
- for (const name in this.bindings) {
160
+ _proto.hasOwnParamBindings = function hasOwnParamBindings(scope) {
161
+ for (var name in this.bindings) {
158
162
  if (!scope.hasOwnBinding(name)) continue;
159
- const binding = this.bindings[name];
163
+ var binding = this.bindings[name];
160
164
  if (binding.kind === "param" && binding.constant) return true;
161
165
  }
162
166
 
163
167
  return false;
164
- }
168
+ };
165
169
 
166
- run() {
170
+ _proto.run = function run() {
167
171
  this.path.traverse(referenceVisitor, this);
168
172
  this.getCompatibleScopes();
169
- const attachTo = this.getAttachmentPath();
173
+ var attachTo = this.getAttachmentPath();
170
174
  if (!attachTo) return;
171
175
  if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
172
- let uid = attachTo.scope.generateUidIdentifier("ref");
173
- const declarator = t().variableDeclarator(uid, this.path.node);
174
- const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
175
- const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t().variableDeclaration("var", [declarator])]);
176
- const parent = this.path.parentPath;
176
+ var uid = attachTo.scope.generateUidIdentifier("ref");
177
+ var declarator = t().variableDeclarator(uid, this.path.node);
178
+ var insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
179
+
180
+ var _attachTo$insertFn = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t().variableDeclaration("var", [declarator])]),
181
+ attached = _attachTo$insertFn[0];
182
+
183
+ var parent = this.path.parentPath;
177
184
 
178
185
  if (parent.isJSXElement() && this.path.container === parent.node.children) {
179
186
  uid = t().JSXExpressionContainer(uid);
@@ -181,8 +188,9 @@ class PathHoister {
181
188
 
182
189
  this.path.replaceWith(t().cloneNode(uid));
183
190
  return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
184
- }
191
+ };
185
192
 
186
- }
193
+ return PathHoister;
194
+ }();
187
195
 
188
196
  exports.default = PathHoister;
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.hooks = void 0;
7
- const hooks = [function (self, parent) {
8
- const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
7
+ var hooks = [function (self, parent) {
8
+ var removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
9
9
 
10
10
  if (removeParent) {
11
11
  parent.remove();