@babel/traverse 7.12.5 → 7.12.7

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
@@ -90,7 +90,7 @@ class TraversalContext {
90
90
  visitQueue(queue) {
91
91
  this.queue = queue;
92
92
  this.priorityQueue = [];
93
- const visited = [];
93
+ const visited = new WeakSet();
94
94
  let stop = false;
95
95
 
96
96
  for (const path of queue) {
@@ -106,8 +106,11 @@ class TraversalContext {
106
106
  this.trap = true;
107
107
  }
108
108
 
109
- if (visited.indexOf(path.node) >= 0) continue;
110
- visited.push(path.node);
109
+ const {
110
+ node
111
+ } = path;
112
+ if (visited.has(node)) continue;
113
+ if (node) visited.add(node);
111
114
 
112
115
  if (path.visit()) {
113
116
  stop = true;
@@ -178,7 +178,7 @@ function getAllPrevSiblings() {
178
178
  return siblings;
179
179
  }
180
180
 
181
- function get(key, context) {
181
+ function get(key, context = true) {
182
182
  if (context === true) context = this.context;
183
183
  const parts = key.split(".");
184
184
 
package/lib/path/index.js CHANGED
@@ -92,26 +92,20 @@ class NodePath {
92
92
  }
93
93
 
94
94
  const targetNode = container[key];
95
- const paths = _cache.path.get(parent) || [];
96
95
 
97
- if (!_cache.path.has(parent)) {
98
- _cache.path.set(parent, paths);
99
- }
100
-
101
- let path;
96
+ let paths = _cache.path.get(parent);
102
97
 
103
- for (let i = 0; i < paths.length; i++) {
104
- const pathCheck = paths[i];
98
+ if (!paths) {
99
+ paths = new Map();
105
100
 
106
- if (pathCheck.node === targetNode) {
107
- path = pathCheck;
108
- break;
109
- }
101
+ _cache.path.set(parent, paths);
110
102
  }
111
103
 
104
+ let path = paths.get(targetNode);
105
+
112
106
  if (!path) {
113
107
  path = new NodePath(hub, parent);
114
- paths.push(path);
108
+ if (targetNode) paths.set(targetNode, path);
115
109
  }
116
110
 
117
111
  path.setup(parentPath, container, listKey, key);
@@ -136,9 +136,7 @@ function updateSiblingKeys(fromIndex, incrementBy) {
136
136
 
137
137
  const paths = _cache.path.get(this.parent);
138
138
 
139
- for (let i = 0; i < paths.length; i++) {
140
- const path = paths[i];
141
-
139
+ for (const [, path] of paths) {
142
140
  if (path.key >= fromIndex) {
143
141
  path.key += incrementBy;
144
142
  }
@@ -12,6 +12,8 @@ exports._assertUnremoved = _assertUnremoved;
12
12
 
13
13
  var _removalHooks = require("./lib/removal-hooks");
14
14
 
15
+ var _cache = require("../cache");
16
+
15
17
  var _index = require("./index");
16
18
 
17
19
  function remove() {
@@ -60,6 +62,7 @@ function _remove() {
60
62
 
61
63
  function _markRemoved() {
62
64
  this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
65
+ if (this.parent) _cache.path.get(this.parent).delete(this.node);
63
66
  this.node = null;
64
67
  }
65
68
 
@@ -16,6 +16,8 @@ var _index = _interopRequireDefault(require("../index"));
16
16
 
17
17
  var _index2 = _interopRequireDefault(require("./index"));
18
18
 
19
+ var _cache = require("../cache");
20
+
19
21
  var _parser = require("@babel/parser");
20
22
 
21
23
  var t = _interopRequireWildcard(require("@babel/types"));
@@ -59,6 +61,9 @@ function replaceWithMultiple(nodes) {
59
61
  nodes = this._verifyNodeList(nodes);
60
62
  t.inheritLeadingComments(nodes[0], this.node);
61
63
  t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
64
+
65
+ _cache.path.get(this.parent).delete(this.node);
66
+
62
67
  this.node = this.container[this.key] = null;
63
68
  const paths = this.insertAfter(nodes);
64
69
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.12.5",
3
+ "version": "7.12.7",
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/",
@@ -19,8 +19,8 @@
19
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.12.5",
23
- "@babel/types": "^7.12.5",
22
+ "@babel/parser": "^7.12.7",
23
+ "@babel/types": "^7.12.7",
24
24
  "debug": "^4.1.0",
25
25
  "globals": "^11.1.0",
26
26
  "lodash": "^4.17.19"