@babel/traverse 7.9.5 → 7.10.3

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/context.js CHANGED
@@ -31,7 +31,7 @@ class TraversalContext {
31
31
  if (opts.enter || opts.exit) return true;
32
32
  if (opts[node.type]) return true;
33
33
  const keys = t.VISITOR_KEYS[node.type];
34
- if (!keys || !keys.length) return false;
34
+ if (!(keys == null ? void 0 : keys.length)) return false;
35
35
 
36
36
  for (const key of keys) {
37
37
  if (node[key]) return true;
@@ -221,9 +221,11 @@ function setup(parentPath, container, listKey, key) {
221
221
  }
222
222
 
223
223
  function setKey(key) {
224
+ var _this$node;
225
+
224
226
  this.key = key;
225
227
  this.node = this.container[this.key];
226
- this.type = this.node && this.node.type;
228
+ this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
227
229
  }
228
230
 
229
231
  function requeue(pathToQueue = this) {
@@ -127,7 +127,7 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
127
127
  static: false
128
128
  });
129
129
  });
130
- const inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor";
130
+ const inConstructor = (thisEnvFn == null ? void 0 : thisEnvFn.node.kind) === "constructor";
131
131
 
132
132
  if (thisEnvFn.isClassProperty()) {
133
133
  throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
@@ -132,7 +132,7 @@ function _evaluate(path, state) {
132
132
  return deopt(binding.path, state);
133
133
  }
134
134
 
135
- if (binding && binding.hasValue) {
135
+ if (binding == null ? void 0 : binding.hasValue) {
136
136
  return binding.value;
137
137
  } else {
138
138
  if (node.name === "undefined") {
@@ -26,6 +26,8 @@ function getTypeAnnotation() {
26
26
  }
27
27
 
28
28
  function _getTypeAnnotation() {
29
+ var _inferer;
30
+
29
31
  const node = this.node;
30
32
 
31
33
  if (!node) {
@@ -59,7 +61,7 @@ function _getTypeAnnotation() {
59
61
 
60
62
  inferer = inferers[this.parentPath.type];
61
63
 
62
- if (inferer && inferer.validParent) {
64
+ if ((_inferer = inferer) == null ? void 0 : _inferer.validParent) {
63
65
  return this.parentPath.getTypeAnnotation();
64
66
  }
65
67
  }
@@ -50,9 +50,19 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
50
50
  }
51
51
  }
52
52
 
53
- if (types.length) {
54
- return t.createUnionTypeAnnotation(types);
53
+ if (!types.length) {
54
+ return;
55
+ }
56
+
57
+ if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
58
+ return t.createTSUnionType(types);
59
+ }
60
+
61
+ if (t.createFlowUnionType) {
62
+ return t.createFlowUnionType(types);
55
63
  }
64
+
65
+ return t.createUnionTypeAnnotation(types);
56
66
  }
57
67
 
58
68
  function getConstantViolationsBefore(binding, path, functions) {
@@ -165,6 +175,20 @@ function getConditionalAnnotation(binding, path, name) {
165
175
  }
166
176
 
167
177
  if (types.length) {
178
+ if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
179
+ return {
180
+ typeAnnotation: t.createTSUnionType(types),
181
+ ifStatement
182
+ };
183
+ }
184
+
185
+ if (t.createFlowUnionType) {
186
+ return {
187
+ typeAnnotation: t.createFlowUnionType(types),
188
+ ifStatement
189
+ };
190
+ }
191
+
168
192
  return {
169
193
  typeAnnotation: t.createUnionTypeAnnotation(types),
170
194
  ifStatement
@@ -44,12 +44,14 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
44
44
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
45
45
 
46
46
  function VariableDeclarator() {
47
+ var _type;
48
+
47
49
  const id = this.get("id");
48
50
  if (!id.isIdentifier()) return;
49
51
  const init = this.get("init");
50
52
  let type = init.getTypeAnnotation();
51
53
 
52
- if (type && type.type === "AnyTypeAnnotation") {
54
+ if (((_type = type) == null ? void 0 : _type.type) === "AnyTypeAnnotation") {
53
55
  if (init.isCallExpression() && init.get("callee").isIdentifier({
54
56
  name: "Array"
55
57
  }) && !init.scope.hasBinding("Array", true)) {
@@ -112,11 +114,31 @@ function BinaryExpression(node) {
112
114
  }
113
115
 
114
116
  function LogicalExpression() {
115
- return t.createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]);
117
+ const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
118
+
119
+ if (t.isTSTypeAnnotation(argumentTypes[0]) && t.createTSUnionType) {
120
+ return t.createTSUnionType(argumentTypes);
121
+ }
122
+
123
+ if (t.createFlowUnionType) {
124
+ return t.createFlowUnionType(argumentTypes);
125
+ }
126
+
127
+ return t.createUnionTypeAnnotation(argumentTypes);
116
128
  }
117
129
 
118
130
  function ConditionalExpression() {
119
- return t.createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]);
131
+ const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
132
+
133
+ if (t.isTSTypeAnnotation(argumentTypes[0]) && t.createTSUnionType) {
134
+ return t.createTSUnionType(argumentTypes);
135
+ }
136
+
137
+ if (t.createFlowUnionType) {
138
+ return t.createFlowUnionType(argumentTypes);
139
+ }
140
+
141
+ return t.createUnionTypeAnnotation(argumentTypes);
120
142
  }
121
143
 
122
144
  function SequenceExpression() {
@@ -15,11 +15,13 @@ var _removalHooks = require("./lib/removal-hooks");
15
15
  var _index = require("./index");
16
16
 
17
17
  function remove() {
18
+ var _this$opts;
19
+
18
20
  this._assertUnremoved();
19
21
 
20
22
  this.resync();
21
23
 
22
- if (!this.opts || !this.opts.noScope) {
24
+ if (!((_this$opts = this.opts) == null ? void 0 : _this$opts.noScope)) {
23
25
  this._removeFromScope();
24
26
  }
25
27
 
@@ -172,7 +172,7 @@ function _replaceWith(node) {
172
172
  t.validate(this.parent, this.key, node);
173
173
  }
174
174
 
175
- this.debug(`Replace with ${node && node.type}`);
175
+ this.debug(`Replace with ${node == null ? void 0 : node.type}`);
176
176
  this.node = this.container[this.key] = node;
177
177
  }
178
178
 
@@ -185,7 +185,7 @@ function replaceExpressionWithStatements(nodes) {
185
185
  }
186
186
 
187
187
  const functionParent = this.getFunctionParent();
188
- const isParentAsync = functionParent && functionParent.is("async");
188
+ const isParentAsync = functionParent == null ? void 0 : functionParent.is("async");
189
189
  const container = t.arrowFunctionExpression([], t.blockStatement(nodes));
190
190
  this.replaceWith(t.callExpression(container, []));
191
191
  this.traverse(hoistVariablesVisitor);
@@ -305,7 +305,7 @@ class Scope {
305
305
 
306
306
  const cached = _cache.scope.get(node);
307
307
 
308
- if (cached && cached.path === path) {
308
+ if ((cached == null ? void 0 : cached.path) === path) {
309
309
  return cached;
310
310
  }
311
311
 
@@ -320,7 +320,7 @@ class Scope {
320
320
 
321
321
  get parent() {
322
322
  const parent = this.path.findParent(p => p.isScope());
323
- return parent && parent.scope;
323
+ return parent == null ? void 0 : parent.scope;
324
324
  }
325
325
 
326
326
  get parentBlock() {
@@ -464,11 +464,11 @@ class Scope {
464
464
  console.log(sep);
465
465
  }
466
466
 
467
- toArray(node, i) {
467
+ toArray(node, i, allowArrayLike) {
468
468
  if (t.isIdentifier(node)) {
469
469
  const binding = this.getBinding(node.name);
470
470
 
471
- if (binding && binding.constant && binding.path.isGenericType("Array")) {
471
+ if ((binding == null ? void 0 : binding.constant) && binding.path.isGenericType("Array")) {
472
472
  return node;
473
473
  }
474
474
  }
@@ -495,6 +495,11 @@ class Scope {
495
495
  helperName = "toArray";
496
496
  }
497
497
 
498
+ if (allowArrayLike) {
499
+ args.unshift(this.hub.addHelper(helperName));
500
+ helperName = "maybeArrayLike";
501
+ }
502
+
498
503
  return t.callExpression(this.hub.addHelper(helperName), args);
499
504
  }
500
505
 
@@ -654,7 +659,7 @@ class Scope {
654
659
  }
655
660
 
656
661
  return true;
657
- } else if (t.isClassMethod(node)) {
662
+ } else if (t.isMethod(node)) {
658
663
  if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
659
664
  if (node.kind === "get" || node.kind === "set") return false;
660
665
  return true;
@@ -889,13 +894,14 @@ class Scope {
889
894
  }
890
895
 
891
896
  getBindingIdentifier(name) {
892
- const info = this.getBinding(name);
893
- return info && info.identifier;
897
+ var _this$getBinding;
898
+
899
+ return (_this$getBinding = this.getBinding(name)) == null ? void 0 : _this$getBinding.identifier;
894
900
  }
895
901
 
896
902
  getOwnBindingIdentifier(name) {
897
903
  const binding = this.bindings[name];
898
- return binding && binding.identifier;
904
+ return binding == null ? void 0 : binding.identifier;
899
905
  }
900
906
 
901
907
  hasOwnBinding(name) {
@@ -913,7 +919,9 @@ class Scope {
913
919
  }
914
920
 
915
921
  parentHasBinding(name, noGlobals) {
916
- return this.parent && this.parent.hasBinding(name, noGlobals);
922
+ var _this$parent;
923
+
924
+ return (_this$parent = this.parent) == null ? void 0 : _this$parent.hasBinding(name, noGlobals);
917
925
  }
918
926
 
919
927
  moveBindingTo(name, scope) {
@@ -931,12 +939,9 @@ class Scope {
931
939
  }
932
940
 
933
941
  removeBinding(name) {
934
- const info = this.getBinding(name);
935
-
936
- if (info) {
937
- info.scope.removeOwnBinding(name);
938
- }
942
+ var _this$getBinding2;
939
943
 
944
+ (_this$getBinding2 = this.getBinding(name)) == null ? void 0 : _this$getBinding2.scope.removeOwnBinding(name);
940
945
  let scope = this;
941
946
 
942
947
  do {
@@ -32,7 +32,8 @@ const renameVisitor = {
32
32
  }
33
33
  },
34
34
 
35
- "AssignmentExpression|Declaration"(path, state) {
35
+ "AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
36
+ if (path.isVariableDeclaration()) return;
36
37
  const ids = path.getOuterBindingIdentifiers();
37
38
 
38
39
  for (const name in ids) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.9.5",
3
+ "version": "7.10.3",
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/",
@@ -8,21 +8,25 @@
8
8
  "publishConfig": {
9
9
  "access": "public"
10
10
  },
11
- "repository": "https://github.com/babel/babel/tree/master/packages/babel-traverse",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/babel/babel.git",
14
+ "directory": "packages/babel-traverse"
15
+ },
12
16
  "main": "lib/index.js",
13
17
  "dependencies": {
14
- "@babel/code-frame": "^7.8.3",
15
- "@babel/generator": "^7.9.5",
16
- "@babel/helper-function-name": "^7.9.5",
17
- "@babel/helper-split-export-declaration": "^7.8.3",
18
- "@babel/parser": "^7.9.0",
19
- "@babel/types": "^7.9.5",
18
+ "@babel/code-frame": "^7.10.3",
19
+ "@babel/generator": "^7.10.3",
20
+ "@babel/helper-function-name": "^7.10.3",
21
+ "@babel/helper-split-export-declaration": "^7.10.1",
22
+ "@babel/parser": "^7.10.3",
23
+ "@babel/types": "^7.10.3",
20
24
  "debug": "^4.1.0",
21
25
  "globals": "^11.1.0",
22
26
  "lodash": "^4.17.13"
23
27
  },
24
28
  "devDependencies": {
25
- "@babel/helper-plugin-test-runner": "^7.8.3"
29
+ "@babel/helper-plugin-test-runner": "^7.10.3"
26
30
  },
27
- "gitHead": "5b97e77e030cf3853a147fdff81844ea4026219d"
31
+ "gitHead": "2787ee2f967b6d8e1121fca00a8d578d75449a53"
28
32
  }