@babel/traverse 7.1.6 → 7.4.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2018 Sebastian McKenzie and other contributors
3
+ Copyright (c) 2014-present Sebastian McKenzie and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -169,7 +169,7 @@ function _resyncKey() {
169
169
  }
170
170
  }
171
171
  } else {
172
- for (const key in this.container) {
172
+ for (const key of Object.keys(this.container)) {
173
173
  if (this.container[key] === this.node) {
174
174
  return this.setKey(key);
175
175
  }
@@ -168,7 +168,6 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
168
168
  },
169
169
 
170
170
  ClassProperty(child) {
171
- if (child.node.static) return;
172
171
  child.skip();
173
172
  },
174
173
 
@@ -316,7 +315,6 @@ function getThisBinding(thisEnvFn, inConstructor) {
316
315
  },
317
316
 
318
317
  ClassProperty(child) {
319
- if (child.node.static) return;
320
318
  child.skip();
321
319
  },
322
320
 
@@ -324,7 +322,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
324
322
  if (!child.get("callee").isSuper()) return;
325
323
  if (supers.has(child.node)) return;
326
324
  supers.add(child.node);
327
- child.replaceWith(t().assignmentExpression("=", t().identifier(thisBinding), child.node));
325
+ child.replaceWithMultiple([child.node, t().assignmentExpression("=", t().identifier(thisBinding), t().identifier("this"))]);
328
326
  }
329
327
 
330
328
  });
@@ -405,7 +403,6 @@ function getScopeInformation(fnPath) {
405
403
  const superCalls = [];
406
404
  fnPath.traverse({
407
405
  ClassProperty(child) {
408
- if (child.node.static) return;
409
406
  child.skip();
410
407
  },
411
408
 
package/lib/path/index.js CHANGED
@@ -208,7 +208,7 @@ for (const type of t().TYPES) {
208
208
  };
209
209
  }
210
210
 
211
- for (const type in virtualTypes) {
211
+ for (const type of Object.keys(virtualTypes)) {
212
212
  if (type[0] === "_") continue;
213
213
  if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type);
214
214
  const virtualType = virtualTypes[type];
@@ -12,6 +12,7 @@ exports.BinaryExpression = BinaryExpression;
12
12
  exports.LogicalExpression = LogicalExpression;
13
13
  exports.ConditionalExpression = ConditionalExpression;
14
14
  exports.SequenceExpression = SequenceExpression;
15
+ exports.ParenthesizedExpression = ParenthesizedExpression;
15
16
  exports.AssignmentExpression = AssignmentExpression;
16
17
  exports.UpdateExpression = UpdateExpression;
17
18
  exports.StringLiteral = StringLiteral;
@@ -128,6 +129,10 @@ function SequenceExpression() {
128
129
  return this.get("expressions").pop().getTypeAnnotation();
129
130
  }
130
131
 
132
+ function ParenthesizedExpression() {
133
+ return this.get("expression").getTypeAnnotation();
134
+ }
135
+
131
136
  function AssignmentExpression() {
132
137
  return this.get("right").getTypeAnnotation();
133
138
  }
@@ -54,7 +54,7 @@ class PathHoister {
54
54
  }
55
55
 
56
56
  isCompatibleScope(scope) {
57
- for (const key in this.bindings) {
57
+ for (const key of Object.keys(this.bindings)) {
58
58
  const binding = this.bindings[key];
59
59
 
60
60
  if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
@@ -92,7 +92,7 @@ class PathHoister {
92
92
  }
93
93
 
94
94
  if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
95
- for (const name in this.bindings) {
95
+ for (const name of Object.keys(this.bindings)) {
96
96
  if (!targetScope.hasOwnBinding(name)) continue;
97
97
  const binding = this.bindings[name];
98
98
 
@@ -154,7 +154,7 @@ class PathHoister {
154
154
  }
155
155
 
156
156
  hasOwnParamBindings(scope) {
157
- for (const name in this.bindings) {
157
+ for (const name of Object.keys(this.bindings)) {
158
158
  if (!scope.hasOwnBinding(name)) continue;
159
159
  const binding = this.bindings[name];
160
160
  if (binding.kind === "param" && binding.constant) return true;
@@ -20,10 +20,12 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
20
20
  const ReferencedIdentifier = {
21
21
  types: ["Identifier", "JSXIdentifier"],
22
22
 
23
- checkPath({
24
- node,
25
- parent
26
- }, opts) {
23
+ checkPath(path, opts) {
24
+ const {
25
+ node,
26
+ parent
27
+ } = path;
28
+
27
29
  if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) {
28
30
  if (t().isJSXIdentifier(node, opts)) {
29
31
  if (t().react.isCompatTag(node.name)) return false;
@@ -32,7 +34,7 @@ const ReferencedIdentifier = {
32
34
  }
33
35
  }
34
36
 
35
- return t().isReferenced(node, parent);
37
+ return t().isReferenced(node, parent, path.parentPath.parent);
36
38
  }
37
39
 
38
40
  };
@@ -52,11 +54,13 @@ exports.ReferencedMemberExpression = ReferencedMemberExpression;
52
54
  const BindingIdentifier = {
53
55
  types: ["Identifier"],
54
56
 
55
- checkPath({
56
- node,
57
- parent
58
- }) {
59
- return t().isIdentifier(node) && t().isBinding(node, parent);
57
+ checkPath(path) {
58
+ const {
59
+ node,
60
+ parent
61
+ } = path;
62
+ const grandparent = path.parentPath.parent;
63
+ return t().isIdentifier(node) && t().isBinding(node, parent, grandparent);
60
64
  }
61
65
 
62
66
  };
@@ -57,7 +57,7 @@ const hoistVariablesVisitor = {
57
57
  if (path.node.kind !== "var") return;
58
58
  const bindings = path.getBindingIdentifiers();
59
59
 
60
- for (const key in bindings) {
60
+ for (const key of Object.keys(bindings)) {
61
61
  path.scope.push({
62
62
  id: bindings[key]
63
63
  });
@@ -152,9 +152,7 @@ const collectorVisitor = {
152
152
  if (binding) binding.reference(path);
153
153
  } else if (t().isVariableDeclaration(declar)) {
154
154
  for (const decl of declar.declarations) {
155
- const ids = t().getBindingIdentifiers(decl);
156
-
157
- for (const name in ids) {
155
+ for (const name of Object.keys(t().getBindingIdentifiers(decl))) {
158
156
  const binding = scope.getBinding(name);
159
157
  if (binding) binding.reference(path);
160
158
  }
@@ -340,7 +338,6 @@ class Scope {
340
338
  checkBlockScopedCollisions(local, kind, name, id) {
341
339
  if (kind === "param") return;
342
340
  if (local.kind === "local") return;
343
- if (kind === "hoisted" && local.kind === "let") return;
344
341
  const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const");
345
342
 
346
343
  if (duplicate) {
@@ -372,7 +369,7 @@ class Scope {
372
369
  do {
373
370
  console.log("#", scope.block.type);
374
371
 
375
- for (const name in scope.bindings) {
372
+ for (const name of Object.keys(scope.bindings)) {
376
373
  const binding = scope.bindings[name];
377
374
  console.log(" -", name, {
378
375
  constant: binding.constant,
@@ -473,7 +470,7 @@ class Scope {
473
470
  registerConstantViolation(path) {
474
471
  const ids = path.getBindingIdentifiers();
475
472
 
476
- for (const name in ids) {
473
+ for (const name of Object.keys(ids)) {
477
474
  const binding = this.getBinding(name);
478
475
  if (binding) binding.reassign(path);
479
476
  }
@@ -493,9 +490,9 @@ class Scope {
493
490
  }
494
491
 
495
492
  const parent = this.getProgramParent();
496
- const ids = path.getBindingIdentifiers(true);
493
+ const ids = path.getOuterBindingIdentifiers(true);
497
494
 
498
- for (const name in ids) {
495
+ for (const name of Object.keys(ids)) {
499
496
  for (const id of ids[name]) {
500
497
  const local = this.getOwnBinding(name);
501
498
 
@@ -688,7 +685,7 @@ class Scope {
688
685
  const ids = path.getBindingIdentifiers();
689
686
  let programParent;
690
687
 
691
- for (const name in ids) {
688
+ for (const name of Object.keys(ids)) {
692
689
  if (path.scope.getBinding(name)) continue;
693
690
  programParent = programParent || path.scope.getProgramParent();
694
691
  programParent.addGlobal(ids[name]);
@@ -801,7 +798,7 @@ class Scope {
801
798
  let scope = this;
802
799
 
803
800
  do {
804
- for (const name in scope.bindings) {
801
+ for (const name of Object.keys(scope.bindings)) {
805
802
  const binding = scope.bindings[name];
806
803
  if (binding.kind === kind) ids[name] = binding;
807
804
  }
package/lib/visitors.js CHANGED
@@ -37,7 +37,7 @@ function explode(visitor) {
37
37
  if (visitor._exploded) return visitor;
38
38
  visitor._exploded = true;
39
39
 
40
- for (const nodeType in visitor) {
40
+ for (const nodeType of Object.keys(visitor)) {
41
41
  if (shouldIgnoreKey(nodeType)) continue;
42
42
  const parts = nodeType.split("|");
43
43
  if (parts.length === 1) continue;
@@ -60,7 +60,7 @@ function explode(visitor) {
60
60
  if (!wrapper) continue;
61
61
  const fns = visitor[nodeType];
62
62
 
63
- for (const type in fns) {
63
+ for (const type of Object.keys(fns)) {
64
64
  fns[type] = wrapCheck(wrapper, fns[type]);
65
65
  }
66
66
 
@@ -79,7 +79,7 @@ function explode(visitor) {
79
79
  }
80
80
  }
81
81
 
82
- for (const nodeType in visitor) {
82
+ for (const nodeType of Object.keys(visitor)) {
83
83
  if (shouldIgnoreKey(nodeType)) continue;
84
84
  const fns = visitor[nodeType];
85
85
  let aliases = t().FLIPPED_ALIAS_KEYS[nodeType];
@@ -104,7 +104,7 @@ function explode(visitor) {
104
104
  }
105
105
  }
106
106
 
107
- for (const nodeType in visitor) {
107
+ for (const nodeType of Object.keys(visitor)) {
108
108
  if (shouldIgnoreKey(nodeType)) continue;
109
109
  ensureCallbackArrays(visitor[nodeType]);
110
110
  }
@@ -119,7 +119,7 @@ function verify(visitor) {
119
119
  throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
120
120
  }
121
121
 
122
- for (const nodeType in visitor) {
122
+ for (const nodeType of Object.keys(visitor)) {
123
123
  if (nodeType === "enter" || nodeType === "exit") {
124
124
  validateVisitorMethods(nodeType, visitor[nodeType]);
125
125
  }
@@ -133,7 +133,7 @@ function verify(visitor) {
133
133
  const visitors = visitor[nodeType];
134
134
 
135
135
  if (typeof visitors === "object") {
136
- for (const visitorKey in visitors) {
136
+ for (const visitorKey of Object.keys(visitors)) {
137
137
  if (visitorKey === "enter" || visitorKey === "exit") {
138
138
  validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
139
139
  } else {
@@ -164,7 +164,7 @@ function merge(visitors, states = [], wrapper) {
164
164
  const state = states[i];
165
165
  explode(visitor);
166
166
 
167
- for (const type in visitor) {
167
+ for (const type of Object.keys(visitor)) {
168
168
  let visitorType = visitor[type];
169
169
 
170
170
  if (state || wrapper) {
@@ -182,7 +182,7 @@ function merge(visitors, states = [], wrapper) {
182
182
  function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
183
183
  const newVisitor = {};
184
184
 
185
- for (const key in oldVisitor) {
185
+ for (const key of Object.keys(oldVisitor)) {
186
186
  let fns = oldVisitor[key];
187
187
  if (!Array.isArray(fns)) continue;
188
188
  fns = fns.map(function (fn) {
@@ -207,7 +207,7 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
207
207
  }
208
208
 
209
209
  function ensureEntranceObjects(obj) {
210
- for (const key in obj) {
210
+ for (const key of Object.keys(obj)) {
211
211
  if (shouldIgnoreKey(key)) continue;
212
212
  const fns = obj[key];
213
213
 
@@ -248,7 +248,7 @@ function shouldIgnoreKey(key) {
248
248
  }
249
249
 
250
250
  function mergePair(dest, src) {
251
- for (const key in src) {
251
+ for (const key of Object.keys(src)) {
252
252
  dest[key] = [].concat(dest[key] || [], src[key]);
253
253
  }
254
254
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.1.6",
3
+ "version": "7.4.0",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "Sebastian McKenzie <sebmck@gmail.com>",
6
6
  "homepage": "https://babeljs.io/",
@@ -12,16 +12,17 @@
12
12
  "main": "lib/index.js",
13
13
  "dependencies": {
14
14
  "@babel/code-frame": "^7.0.0",
15
- "@babel/generator": "^7.1.6",
15
+ "@babel/generator": "^7.4.0",
16
16
  "@babel/helper-function-name": "^7.1.0",
17
- "@babel/helper-split-export-declaration": "^7.0.0",
18
- "@babel/parser": "^7.1.6",
19
- "@babel/types": "^7.1.6",
17
+ "@babel/helper-split-export-declaration": "^7.4.0",
18
+ "@babel/parser": "^7.4.0",
19
+ "@babel/types": "^7.4.0",
20
20
  "debug": "^4.1.0",
21
21
  "globals": "^11.1.0",
22
- "lodash": "^4.17.10"
22
+ "lodash": "^4.17.11"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@babel/helper-plugin-test-runner": "^7.0.0"
26
- }
26
+ },
27
+ "gitHead": "f1328fb913b5a93d54dfc6e3728b1f56c8f4a804"
27
28
  }