@babel/traverse 7.10.5 → 7.12.1

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
@@ -19,6 +19,10 @@ const testing = process.env.NODE_ENV === "test";
19
19
 
20
20
  class TraversalContext {
21
21
  constructor(scope, opts, state, parentPath) {
22
+ this.parentPath = void 0;
23
+ this.scope = void 0;
24
+ this.state = void 0;
25
+ this.opts = void 0;
22
26
  this.queue = null;
23
27
  this.parentPath = parentPath;
24
28
  this.scope = scope;
package/lib/index.js CHANGED
@@ -93,15 +93,15 @@ traverse.removeProperties = function (tree, opts) {
93
93
  return tree;
94
94
  };
95
95
 
96
- function hasBlacklistedType(path, state) {
96
+ function hasDenylistedType(path, state) {
97
97
  if (path.node.type === state.type) {
98
98
  state.has = true;
99
99
  path.stop();
100
100
  }
101
101
  }
102
102
 
103
- traverse.hasType = function (tree, type, blacklistTypes) {
104
- if (blacklistTypes == null ? void 0 : blacklistTypes.includes(tree.type)) return false;
103
+ traverse.hasType = function (tree, type, denylistTypes) {
104
+ if (denylistTypes == null ? void 0 : denylistTypes.includes(tree.type)) return false;
105
105
  if (tree.type === type) return true;
106
106
  const state = {
107
107
  has: false,
@@ -109,8 +109,8 @@ traverse.hasType = function (tree, type, blacklistTypes) {
109
109
  };
110
110
  traverse(tree, {
111
111
  noScope: true,
112
- blacklist: blacklistTypes,
113
- enter: hasBlacklistedType
112
+ denylist: denylistTypes,
113
+ enter: hasDenylistedType
114
114
  }, null, state);
115
115
  return state.has;
116
116
  };
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.call = call;
7
7
  exports._call = _call;
8
- exports.isBlacklisted = isBlacklisted;
8
+ exports.isBlacklisted = exports.isDenylisted = isDenylisted;
9
9
  exports.visit = visit;
10
10
  exports.skip = skip;
11
11
  exports.skipKey = skipKey;
@@ -69,9 +69,11 @@ function _call(fns) {
69
69
  return false;
70
70
  }
71
71
 
72
- function isBlacklisted() {
73
- const blacklist = this.opts.blacklist;
74
- return blacklist && blacklist.indexOf(this.node.type) > -1;
72
+ function isDenylisted() {
73
+ var _this$opts$denylist;
74
+
75
+ const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
76
+ return denylist && denylist.indexOf(this.node.type) > -1;
75
77
  }
76
78
 
77
79
  function visit() {
@@ -79,7 +81,7 @@ function visit() {
79
81
  return false;
80
82
  }
81
83
 
82
- if (this.isBlacklisted()) {
84
+ if (this.isDenylisted()) {
83
85
  return false;
84
86
  }
85
87
 
@@ -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,6 +57,25 @@ exports.SHOULD_SKIP = SHOULD_SKIP;
57
57
 
58
58
  class NodePath {
59
59
  constructor(hub, parent) {
60
+ this.parent = void 0;
61
+ this.hub = void 0;
62
+ this.contexts = void 0;
63
+ this.data = void 0;
64
+ this.shouldSkip = void 0;
65
+ this.shouldStop = void 0;
66
+ this.removed = void 0;
67
+ this.state = void 0;
68
+ this.opts = void 0;
69
+ this._traverseFlags = void 0;
70
+ this.skipKeys = void 0;
71
+ this.parentPath = void 0;
72
+ this.context = void 0;
73
+ this.container = void 0;
74
+ this.listKey = void 0;
75
+ this.key = void 0;
76
+ this.node = void 0;
77
+ this.scope = void 0;
78
+ this.type = void 0;
60
79
  this.parent = parent;
61
80
  this.hub = hub;
62
81
  this.contexts = [];
@@ -12,6 +12,14 @@ class Binding {
12
12
  path,
13
13
  kind
14
14
  }) {
15
+ this.constantViolations = void 0;
16
+ this.constant = void 0;
17
+ this.referencePaths = void 0;
18
+ this.referenced = void 0;
19
+ this.references = void 0;
20
+ this.hasDeoptedValue = void 0;
21
+ this.hasValue = void 0;
22
+ this.value = void 0;
15
23
  this.identifier = identifier;
16
24
  this.scope = scope;
17
25
  this.path = path;
@@ -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
  }
@@ -45,6 +45,9 @@ const renameVisitor = {
45
45
 
46
46
  class Renamer {
47
47
  constructor(binding, oldName, newName) {
48
+ this.oldName = void 0;
49
+ this.newName = void 0;
50
+ this.binding = void 0;
48
51
  this.newName = newName;
49
52
  this.oldName = oldName;
50
53
  this.binding = binding;
package/lib/visitors.js CHANGED
@@ -226,7 +226,7 @@ function shouldIgnoreKey(key) {
226
226
  if (key[0] === "_") return true;
227
227
  if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
228
228
 
229
- if (key === "blacklist" || key === "noScope" || key === "skipKeys") {
229
+ if (key === "denylist" || key === "noScope" || key === "skipKeys" || key === "blacklist") {
230
230
  return true;
231
231
  }
232
232
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.10.5",
3
+ "version": "7.12.1",
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,17 +16,16 @@
16
16
  "main": "lib/index.js",
17
17
  "dependencies": {
18
18
  "@babel/code-frame": "^7.10.4",
19
- "@babel/generator": "^7.10.5",
19
+ "@babel/generator": "^7.12.1",
20
20
  "@babel/helper-function-name": "^7.10.4",
21
- "@babel/helper-split-export-declaration": "^7.10.4",
22
- "@babel/parser": "^7.10.5",
23
- "@babel/types": "^7.10.5",
21
+ "@babel/helper-split-export-declaration": "^7.11.0",
22
+ "@babel/parser": "^7.12.1",
23
+ "@babel/types": "^7.12.1",
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"
30
- },
31
- "gitHead": "f7964a9ac51356f7df6404a25b27ba1cffba1ba7"
32
- }
29
+ "@babel/helper-plugin-test-runner": "7.10.4"
30
+ }
31
+ }