@babel/traverse 7.11.0 → 7.12.5

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes
4
4
 
5
- See our website [@babel/traverse](https://babeljs.io/docs/en/next/babel-traverse.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen) associated with this package.
5
+ See our website [@babel/traverse](https://babeljs.io/docs/en/babel-traverse) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen) associated with this package.
6
6
 
7
7
  ## Install
8
8
 
@@ -197,7 +197,7 @@ function _evaluate(path, state) {
197
197
  if (elemValue.confident) {
198
198
  arr.push(elemValue.value);
199
199
  } else {
200
- return deopt(elem, state);
200
+ return deopt(elemValue.deopt, state);
201
201
  }
202
202
  }
203
203
 
@@ -220,7 +220,7 @@ function _evaluate(path, state) {
220
220
  key = key.evaluate();
221
221
 
222
222
  if (!key.confident) {
223
- return deopt(keyPath, state);
223
+ return deopt(key.deopt, state);
224
224
  }
225
225
 
226
226
  key = key.value;
@@ -234,7 +234,7 @@ function _evaluate(path, state) {
234
234
  let value = valuePath.evaluate();
235
235
 
236
236
  if (!value.confident) {
237
- return deopt(valuePath, state);
237
+ return deopt(value.deopt, state);
238
238
  }
239
239
 
240
240
  value = value.value;
@@ -41,27 +41,43 @@ function addCompletionRecords(path, paths) {
41
41
  return paths;
42
42
  }
43
43
 
44
+ function findBreak(statements) {
45
+ let breakStatement;
46
+
47
+ if (!Array.isArray(statements)) {
48
+ statements = [statements];
49
+ }
50
+
51
+ for (const statement of statements) {
52
+ if (statement.isDoExpression() || statement.isProgram() || statement.isBlockStatement() || statement.isCatchClause() || statement.isLabeledStatement()) {
53
+ breakStatement = findBreak(statement.get("body"));
54
+ } else if (statement.isIfStatement()) {
55
+ var _findBreak;
56
+
57
+ breakStatement = (_findBreak = findBreak(statement.get("consequent"))) != null ? _findBreak : findBreak(statement.get("alternate"));
58
+ } else if (statement.isTryStatement()) {
59
+ var _findBreak2;
60
+
61
+ breakStatement = (_findBreak2 = findBreak(statement.get("block"))) != null ? _findBreak2 : findBreak(statement.get("handler"));
62
+ } else if (statement.isBreakStatement()) {
63
+ breakStatement = statement;
64
+ }
65
+
66
+ if (breakStatement) {
67
+ return breakStatement;
68
+ }
69
+ }
70
+
71
+ return null;
72
+ }
73
+
44
74
  function completionRecordForSwitch(cases, paths) {
45
75
  let isLastCaseWithConsequent = true;
46
76
 
47
77
  for (let i = cases.length - 1; i >= 0; i--) {
48
78
  const switchCase = cases[i];
49
79
  const consequent = switchCase.get("consequent");
50
- let breakStatement;
51
-
52
- findBreak: for (const statement of consequent) {
53
- if (statement.isBlockStatement()) {
54
- for (const statementInBlock of statement.get("body")) {
55
- if (statementInBlock.isBreakStatement()) {
56
- breakStatement = statementInBlock;
57
- break findBreak;
58
- }
59
- }
60
- } else if (statement.isBreakStatement()) {
61
- breakStatement = statement;
62
- break;
63
- }
64
- }
80
+ let breakStatement = findBreak(consequent);
65
81
 
66
82
  if (breakStatement) {
67
83
  while (breakStatement.key === 0 && breakStatement.parentPath.isBlockStatement()) {
package/lib/path/index.js CHANGED
@@ -57,22 +57,22 @@ exports.SHOULD_SKIP = SHOULD_SKIP;
57
57
 
58
58
  class NodePath {
59
59
  constructor(hub, parent) {
60
- this.parent = parent;
61
- this.hub = hub;
62
60
  this.contexts = [];
63
- this.data = null;
64
- this._traverseFlags = 0;
65
61
  this.state = null;
66
62
  this.opts = null;
63
+ this._traverseFlags = 0;
67
64
  this.skipKeys = null;
68
65
  this.parentPath = null;
69
- this.context = null;
70
66
  this.container = null;
71
67
  this.listKey = null;
72
68
  this.key = null;
73
69
  this.node = null;
74
- this.scope = null;
75
70
  this.type = null;
71
+ this.parent = parent;
72
+ this.hub = hub;
73
+ this.data = null;
74
+ this.context = null;
75
+ this.scope = null;
76
76
  }
77
77
 
78
78
  static get({
@@ -12,15 +12,15 @@ class Binding {
12
12
  path,
13
13
  kind
14
14
  }) {
15
- this.identifier = identifier;
16
- this.scope = scope;
17
- this.path = path;
18
- this.kind = kind;
19
15
  this.constantViolations = [];
20
16
  this.constant = true;
21
17
  this.referencePaths = [];
22
18
  this.referenced = false;
23
19
  this.references = 0;
20
+ this.identifier = identifier;
21
+ this.scope = scope;
22
+ this.path = path;
23
+ this.kind = kind;
24
24
  this.clearValue();
25
25
  }
26
26
 
@@ -9,8 +9,6 @@ var _renamer = _interopRequireDefault(require("./lib/renamer"));
9
9
 
10
10
  var _index = _interopRequireDefault(require("../index"));
11
11
 
12
- var _defaults = _interopRequireDefault(require("lodash/defaults"));
13
-
14
12
  var _binding = _interopRequireDefault(require("./binding"));
15
13
 
16
14
  var _globals = _interopRequireDefault(require("globals"));
@@ -346,7 +344,7 @@ class Scope {
346
344
  generateUid(name = "temp") {
347
345
  name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
348
346
  let uid;
349
- let i = 0;
347
+ let i = 1;
350
348
 
351
349
  do {
352
350
  uid = this._generateUid(name, i);
@@ -838,7 +836,12 @@ class Scope {
838
836
  let scope = this;
839
837
 
840
838
  do {
841
- (0, _defaults.default)(ids, scope.bindings);
839
+ for (const key of Object.keys(scope.bindings)) {
840
+ if (key in ids === false) {
841
+ ids[key] = scope.bindings[key];
842
+ }
843
+ }
844
+
842
845
  scope = scope.parent;
843
846
  } while (scope);
844
847
 
@@ -876,7 +879,9 @@ class Scope {
876
879
  const binding = scope.getOwnBinding(name);
877
880
 
878
881
  if (binding) {
879
- if (previousPath && previousPath.isPattern() && previousPath.parentPath.isFunction() && binding.kind !== "param") {} else {
882
+ var _previousPath;
883
+
884
+ if (((_previousPath = previousPath) == null ? void 0 : _previousPath.isPattern()) && binding.kind !== "param") {} else {
880
885
  return binding;
881
886
  }
882
887
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.11.0",
3
+ "version": "7.12.5",
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/",
@@ -16,16 +16,16 @@
16
16
  "main": "lib/index.js",
17
17
  "dependencies": {
18
18
  "@babel/code-frame": "^7.10.4",
19
- "@babel/generator": "^7.11.0",
19
+ "@babel/generator": "^7.12.5",
20
20
  "@babel/helper-function-name": "^7.10.4",
21
21
  "@babel/helper-split-export-declaration": "^7.11.0",
22
- "@babel/parser": "^7.11.0",
23
- "@babel/types": "^7.11.0",
22
+ "@babel/parser": "^7.12.5",
23
+ "@babel/types": "^7.12.5",
24
24
  "debug": "^4.1.0",
25
25
  "globals": "^11.1.0",
26
26
  "lodash": "^4.17.19"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/helper-plugin-test-runner": "^7.10.4"
29
+ "@babel/helper-plugin-test-runner": "7.10.4"
30
30
  }
31
- }
31
+ }