@babel/traverse 7.12.1 → 7.12.9
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 +1 -1
- package/lib/context.js +6 -7
- package/lib/path/family.js +2 -2
- package/lib/path/index.js +13 -38
- package/lib/path/inference/index.js +21 -9
- package/lib/path/modification.js +1 -3
- package/lib/path/removal.js +3 -0
- package/lib/path/replacement.js +8 -0
- package/lib/scope/binding.js +4 -12
- package/lib/scope/lib/renamer.js +0 -3
- package/package.json +4 -4
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/
|
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
|
|
package/lib/context.js
CHANGED
@@ -19,10 +19,6 @@ 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;
|
26
22
|
this.queue = null;
|
27
23
|
this.parentPath = parentPath;
|
28
24
|
this.scope = scope;
|
@@ -94,7 +90,7 @@ class TraversalContext {
|
|
94
90
|
visitQueue(queue) {
|
95
91
|
this.queue = queue;
|
96
92
|
this.priorityQueue = [];
|
97
|
-
const visited =
|
93
|
+
const visited = new WeakSet();
|
98
94
|
let stop = false;
|
99
95
|
|
100
96
|
for (const path of queue) {
|
@@ -110,8 +106,11 @@ class TraversalContext {
|
|
110
106
|
this.trap = true;
|
111
107
|
}
|
112
108
|
|
113
|
-
|
114
|
-
|
109
|
+
const {
|
110
|
+
node
|
111
|
+
} = path;
|
112
|
+
if (visited.has(node)) continue;
|
113
|
+
if (node) visited.add(node);
|
115
114
|
|
116
115
|
if (path.visit()) {
|
117
116
|
stop = true;
|
package/lib/path/family.js
CHANGED
@@ -141,7 +141,7 @@ function getSibling(key) {
|
|
141
141
|
container: this.container,
|
142
142
|
listKey: this.listKey,
|
143
143
|
key: key
|
144
|
-
});
|
144
|
+
}).setContext(this.context);
|
145
145
|
}
|
146
146
|
|
147
147
|
function getPrevSibling() {
|
@@ -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
@@ -57,41 +57,22 @@ 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;
|
79
|
-
this.parent = parent;
|
80
|
-
this.hub = hub;
|
81
60
|
this.contexts = [];
|
82
|
-
this.data = null;
|
83
|
-
this._traverseFlags = 0;
|
84
61
|
this.state = null;
|
85
62
|
this.opts = null;
|
63
|
+
this._traverseFlags = 0;
|
86
64
|
this.skipKeys = null;
|
87
65
|
this.parentPath = null;
|
88
|
-
this.context = null;
|
89
66
|
this.container = null;
|
90
67
|
this.listKey = null;
|
91
68
|
this.key = null;
|
92
69
|
this.node = null;
|
93
|
-
this.scope = null;
|
94
70
|
this.type = null;
|
71
|
+
this.parent = parent;
|
72
|
+
this.hub = hub;
|
73
|
+
this.data = null;
|
74
|
+
this.context = null;
|
75
|
+
this.scope = null;
|
95
76
|
}
|
96
77
|
|
97
78
|
static get({
|
@@ -111,26 +92,20 @@ class NodePath {
|
|
111
92
|
}
|
112
93
|
|
113
94
|
const targetNode = container[key];
|
114
|
-
const paths = _cache.path.get(parent) || [];
|
115
|
-
|
116
|
-
if (!_cache.path.has(parent)) {
|
117
|
-
_cache.path.set(parent, paths);
|
118
|
-
}
|
119
95
|
|
120
|
-
let path;
|
96
|
+
let paths = _cache.path.get(parent);
|
121
97
|
|
122
|
-
|
123
|
-
|
98
|
+
if (!paths) {
|
99
|
+
paths = new Map();
|
124
100
|
|
125
|
-
|
126
|
-
path = pathCheck;
|
127
|
-
break;
|
128
|
-
}
|
101
|
+
_cache.path.set(parent, paths);
|
129
102
|
}
|
130
103
|
|
104
|
+
let path = paths.get(targetNode);
|
105
|
+
|
131
106
|
if (!path) {
|
132
107
|
path = new NodePath(hub, parent);
|
133
|
-
paths.
|
108
|
+
if (targetNode) paths.set(targetNode, path);
|
134
109
|
}
|
135
110
|
|
136
111
|
path.setup(parentPath, container, listKey, key);
|
@@ -25,9 +25,9 @@ function getTypeAnnotation() {
|
|
25
25
|
return this.typeAnnotation = type;
|
26
26
|
}
|
27
27
|
|
28
|
-
|
29
|
-
var _inferer;
|
28
|
+
const typeAnnotationInferringNodes = new WeakSet();
|
30
29
|
|
30
|
+
function _getTypeAnnotation() {
|
31
31
|
const node = this.node;
|
32
32
|
|
33
33
|
if (!node) {
|
@@ -53,16 +53,28 @@ function _getTypeAnnotation() {
|
|
53
53
|
return node.typeAnnotation;
|
54
54
|
}
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
if (inferer) {
|
59
|
-
return inferer.call(this, node);
|
56
|
+
if (typeAnnotationInferringNodes.has(node)) {
|
57
|
+
return;
|
60
58
|
}
|
61
59
|
|
62
|
-
|
60
|
+
typeAnnotationInferringNodes.add(node);
|
61
|
+
|
62
|
+
try {
|
63
|
+
var _inferer;
|
64
|
+
|
65
|
+
let inferer = inferers[node.type];
|
63
66
|
|
64
|
-
|
65
|
-
|
67
|
+
if (inferer) {
|
68
|
+
return inferer.call(this, node);
|
69
|
+
}
|
70
|
+
|
71
|
+
inferer = inferers[this.parentPath.type];
|
72
|
+
|
73
|
+
if ((_inferer = inferer) == null ? void 0 : _inferer.validParent) {
|
74
|
+
return this.parentPath.getTypeAnnotation();
|
75
|
+
}
|
76
|
+
} finally {
|
77
|
+
typeAnnotationInferringNodes.delete(node);
|
66
78
|
}
|
67
79
|
}
|
68
80
|
|
package/lib/path/modification.js
CHANGED
@@ -136,9 +136,7 @@ function updateSiblingKeys(fromIndex, incrementBy) {
|
|
136
136
|
|
137
137
|
const paths = _cache.path.get(this.parent);
|
138
138
|
|
139
|
-
for (
|
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
|
}
|
package/lib/path/removal.js
CHANGED
@@ -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
|
|
package/lib/path/replacement.js
CHANGED
@@ -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"));
|
@@ -55,10 +57,13 @@ const hoistVariablesVisitor = {
|
|
55
57
|
};
|
56
58
|
|
57
59
|
function replaceWithMultiple(nodes) {
|
60
|
+
var _pathCache$get;
|
61
|
+
|
58
62
|
this.resync();
|
59
63
|
nodes = this._verifyNodeList(nodes);
|
60
64
|
t.inheritLeadingComments(nodes[0], this.node);
|
61
65
|
t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
66
|
+
(_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node);
|
62
67
|
this.node = this.container[this.key] = null;
|
63
68
|
const paths = this.insertAfter(nodes);
|
64
69
|
|
@@ -162,6 +167,8 @@ function replaceWith(replacement) {
|
|
162
167
|
}
|
163
168
|
|
164
169
|
function _replaceWith(node) {
|
170
|
+
var _pathCache$get2;
|
171
|
+
|
165
172
|
if (!this.container) {
|
166
173
|
throw new ReferenceError("Container is falsy");
|
167
174
|
}
|
@@ -173,6 +180,7 @@ function _replaceWith(node) {
|
|
173
180
|
}
|
174
181
|
|
175
182
|
this.debug(`Replace with ${node == null ? void 0 : node.type}`);
|
183
|
+
(_pathCache$get2 = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get2.set(node, this).delete(this.node);
|
176
184
|
this.node = this.container[this.key] = node;
|
177
185
|
}
|
178
186
|
|
package/lib/scope/binding.js
CHANGED
@@ -12,23 +12,15 @@ 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;
|
23
|
-
this.identifier = identifier;
|
24
|
-
this.scope = scope;
|
25
|
-
this.path = path;
|
26
|
-
this.kind = kind;
|
27
15
|
this.constantViolations = [];
|
28
16
|
this.constant = true;
|
29
17
|
this.referencePaths = [];
|
30
18
|
this.referenced = false;
|
31
19
|
this.references = 0;
|
20
|
+
this.identifier = identifier;
|
21
|
+
this.scope = scope;
|
22
|
+
this.path = path;
|
23
|
+
this.kind = kind;
|
32
24
|
this.clearValue();
|
33
25
|
}
|
34
26
|
|
package/lib/scope/lib/renamer.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.12.
|
3
|
+
"version": "7.12.9",
|
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,11 +16,11 @@
|
|
16
16
|
"main": "lib/index.js",
|
17
17
|
"dependencies": {
|
18
18
|
"@babel/code-frame": "^7.10.4",
|
19
|
-
"@babel/generator": "^7.12.
|
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.
|
23
|
-
"@babel/types": "^7.12.
|
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"
|