@babel/traverse 7.0.0-beta.45 → 7.0.0-beta.49
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/.npmignore +3 -0
- package/README.md +3 -3
- package/lib/cache.js +2 -2
- package/lib/context.js +35 -75
- package/lib/hub.js +6 -3
- package/lib/index.js +12 -24
- package/lib/path/ancestry.js +26 -40
- package/lib/path/comments.js +9 -9
- package/lib/path/context.js +17 -45
- package/lib/path/conversion.js +122 -128
- package/lib/path/evaluation.js +97 -136
- package/lib/path/family.js +27 -40
- package/lib/path/index.js +61 -81
- package/lib/path/inference/index.js +12 -16
- package/lib/path/inference/inferer-reference.js +37 -41
- package/lib/path/inference/inferers.js +18 -16
- package/lib/path/introspection.js +55 -99
- package/lib/path/lib/hoister.js +48 -56
- package/lib/path/lib/removal-hooks.js +2 -2
- package/lib/path/lib/virtual-types.js +76 -46
- package/lib/path/modification.js +40 -56
- package/lib/path/removal.js +3 -10
- package/lib/path/replacement.js +34 -52
- package/lib/scope/binding.js +20 -22
- package/lib/scope/index.js +280 -402
- package/lib/scope/lib/renamer.js +37 -35
- package/lib/visitors.js +62 -120
- package/package.json +9 -9
package/.npmignore
ADDED
package/README.md
CHANGED
@@ -10,17 +10,17 @@ $ npm install --save @babel/traverse
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
-
We can use it alongside
|
13
|
+
We can use it alongside the babel parser to traverse and update nodes:
|
14
14
|
|
15
15
|
```js
|
16
|
-
import * as
|
16
|
+
import * as parser from "@babel/parser";
|
17
17
|
import traverse from "@babel/traverse";
|
18
18
|
|
19
19
|
const code = `function square(n) {
|
20
20
|
return n * n;
|
21
21
|
}`;
|
22
22
|
|
23
|
-
const ast =
|
23
|
+
const ast = parser.parse(code);
|
24
24
|
|
25
25
|
traverse(ast, {
|
26
26
|
enter(path) {
|
package/lib/cache.js
CHANGED
@@ -7,9 +7,9 @@ exports.clear = clear;
|
|
7
7
|
exports.clearPath = clearPath;
|
8
8
|
exports.clearScope = clearScope;
|
9
9
|
exports.scope = exports.path = void 0;
|
10
|
-
|
10
|
+
let path = new WeakMap();
|
11
11
|
exports.path = path;
|
12
|
-
|
12
|
+
let scope = new WeakMap();
|
13
13
|
exports.scope = scope;
|
14
14
|
|
15
15
|
function clear() {
|
package/lib/context.js
CHANGED
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _path = _interopRequireDefault(require("./path"));
|
9
9
|
|
10
10
|
function t() {
|
11
|
-
|
11
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
12
12
|
|
13
|
-
t = function
|
13
|
+
t = function () {
|
14
14
|
return data;
|
15
15
|
};
|
16
16
|
|
@@ -21,10 +21,10 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
21
21
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
23
|
|
24
|
-
|
24
|
+
const testing = process.env.NODE_ENV === "test";
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
class TraversalContext {
|
27
|
+
constructor(scope, opts, state, parentPath) {
|
28
28
|
this.queue = null;
|
29
29
|
this.parentPath = parentPath;
|
30
30
|
this.scope = scope;
|
@@ -32,45 +32,31 @@ var TraversalContext = function () {
|
|
32
32
|
this.opts = opts;
|
33
33
|
}
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
_proto.shouldVisit = function shouldVisit(node) {
|
38
|
-
var opts = this.opts;
|
35
|
+
shouldVisit(node) {
|
36
|
+
const opts = this.opts;
|
39
37
|
if (opts.enter || opts.exit) return true;
|
40
38
|
if (opts[node.type]) return true;
|
41
|
-
|
39
|
+
const keys = t().VISITOR_KEYS[node.type];
|
42
40
|
if (!keys || !keys.length) return false;
|
43
41
|
|
44
|
-
for (
|
45
|
-
var _ref;
|
46
|
-
|
47
|
-
if (_isArray) {
|
48
|
-
if (_i >= _iterator.length) break;
|
49
|
-
_ref = _iterator[_i++];
|
50
|
-
} else {
|
51
|
-
_i = _iterator.next();
|
52
|
-
if (_i.done) break;
|
53
|
-
_ref = _i.value;
|
54
|
-
}
|
55
|
-
|
56
|
-
var key = _ref;
|
42
|
+
for (const key of keys) {
|
57
43
|
if (node[key]) return true;
|
58
44
|
}
|
59
45
|
|
60
46
|
return false;
|
61
|
-
}
|
47
|
+
}
|
62
48
|
|
63
|
-
|
64
|
-
return
|
49
|
+
create(node, obj, key, listKey) {
|
50
|
+
return _path.default.get({
|
65
51
|
parentPath: this.parentPath,
|
66
52
|
parent: node,
|
67
53
|
container: obj,
|
68
54
|
key: key,
|
69
|
-
listKey
|
55
|
+
listKey
|
70
56
|
});
|
71
|
-
}
|
57
|
+
}
|
72
58
|
|
73
|
-
|
59
|
+
maybeQueue(path, notPriority) {
|
74
60
|
if (this.trap) {
|
75
61
|
throw new Error("Infinite cycle detected");
|
76
62
|
}
|
@@ -82,14 +68,14 @@ var TraversalContext = function () {
|
|
82
68
|
this.priorityQueue.push(path);
|
83
69
|
}
|
84
70
|
}
|
85
|
-
}
|
71
|
+
}
|
86
72
|
|
87
|
-
|
73
|
+
visitMultiple(container, parent, listKey) {
|
88
74
|
if (container.length === 0) return false;
|
89
|
-
|
75
|
+
const queue = [];
|
90
76
|
|
91
|
-
for (
|
92
|
-
|
77
|
+
for (let key = 0; key < container.length; key++) {
|
78
|
+
const node = container[key];
|
93
79
|
|
94
80
|
if (node && this.shouldVisit(node)) {
|
95
81
|
queue.push(this.create(parent, container, key, listKey));
|
@@ -97,35 +83,23 @@ var TraversalContext = function () {
|
|
97
83
|
}
|
98
84
|
|
99
85
|
return this.visitQueue(queue);
|
100
|
-
}
|
86
|
+
}
|
101
87
|
|
102
|
-
|
88
|
+
visitSingle(node, key) {
|
103
89
|
if (this.shouldVisit(node[key])) {
|
104
90
|
return this.visitQueue([this.create(node, node, key)]);
|
105
91
|
} else {
|
106
92
|
return false;
|
107
93
|
}
|
108
|
-
}
|
94
|
+
}
|
109
95
|
|
110
|
-
|
96
|
+
visitQueue(queue) {
|
111
97
|
this.queue = queue;
|
112
98
|
this.priorityQueue = [];
|
113
|
-
|
114
|
-
|
99
|
+
const visited = [];
|
100
|
+
let stop = false;
|
115
101
|
|
116
|
-
for (
|
117
|
-
var _ref2;
|
118
|
-
|
119
|
-
if (_isArray2) {
|
120
|
-
if (_i2 >= _iterator2.length) break;
|
121
|
-
_ref2 = _iterator2[_i2++];
|
122
|
-
} else {
|
123
|
-
_i2 = _iterator2.next();
|
124
|
-
if (_i2.done) break;
|
125
|
-
_ref2 = _i2.value;
|
126
|
-
}
|
127
|
-
|
128
|
-
var path = _ref2;
|
102
|
+
for (const path of queue) {
|
129
103
|
path.resync();
|
130
104
|
|
131
105
|
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
|
@@ -154,29 +128,16 @@ var TraversalContext = function () {
|
|
154
128
|
}
|
155
129
|
}
|
156
130
|
|
157
|
-
for (
|
158
|
-
|
159
|
-
|
160
|
-
if (_isArray3) {
|
161
|
-
if (_i3 >= _iterator3.length) break;
|
162
|
-
_ref3 = _iterator3[_i3++];
|
163
|
-
} else {
|
164
|
-
_i3 = _iterator3.next();
|
165
|
-
if (_i3.done) break;
|
166
|
-
_ref3 = _i3.value;
|
167
|
-
}
|
168
|
-
|
169
|
-
var _path = _ref3;
|
170
|
-
|
171
|
-
_path.popContext();
|
131
|
+
for (const path of queue) {
|
132
|
+
path.popContext();
|
172
133
|
}
|
173
134
|
|
174
135
|
this.queue = null;
|
175
136
|
return stop;
|
176
|
-
}
|
137
|
+
}
|
177
138
|
|
178
|
-
|
179
|
-
|
139
|
+
visit(node, key) {
|
140
|
+
const nodes = node[key];
|
180
141
|
if (!nodes) return false;
|
181
142
|
|
182
143
|
if (Array.isArray(nodes)) {
|
@@ -184,9 +145,8 @@ var TraversalContext = function () {
|
|
184
145
|
} else {
|
185
146
|
return this.visitSingle(node, key);
|
186
147
|
}
|
187
|
-
}
|
148
|
+
}
|
188
149
|
|
189
|
-
|
190
|
-
}();
|
150
|
+
}
|
191
151
|
|
192
152
|
exports.default = TraversalContext;
|
package/lib/hub.js
CHANGED
package/lib/index.js
CHANGED
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.default = traverse;
|
7
7
|
Object.defineProperty(exports, "NodePath", {
|
8
8
|
enumerable: true,
|
9
|
-
get: function
|
9
|
+
get: function () {
|
10
10
|
return _path.default;
|
11
11
|
}
|
12
12
|
});
|
13
13
|
Object.defineProperty(exports, "Scope", {
|
14
14
|
enumerable: true,
|
15
|
-
get: function
|
15
|
+
get: function () {
|
16
16
|
return _scope.default;
|
17
17
|
}
|
18
18
|
});
|
19
19
|
Object.defineProperty(exports, "Hub", {
|
20
20
|
enumerable: true,
|
21
|
-
get: function
|
21
|
+
get: function () {
|
22
22
|
return _hub.default;
|
23
23
|
}
|
24
24
|
});
|
@@ -31,9 +31,9 @@ var visitors = _interopRequireWildcard(require("./visitors"));
|
|
31
31
|
exports.visitors = visitors;
|
32
32
|
|
33
33
|
function _includes() {
|
34
|
-
|
34
|
+
const data = _interopRequireDefault(require("lodash/includes"));
|
35
35
|
|
36
|
-
_includes = function
|
36
|
+
_includes = function () {
|
37
37
|
return data;
|
38
38
|
};
|
39
39
|
|
@@ -41,9 +41,9 @@ function _includes() {
|
|
41
41
|
}
|
42
42
|
|
43
43
|
function t() {
|
44
|
-
|
44
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
45
45
|
|
46
|
-
t = function
|
46
|
+
t = function () {
|
47
47
|
return data;
|
48
48
|
};
|
49
49
|
|
@@ -68,7 +68,7 @@ function traverse(parent, opts, scope, state, parentPath) {
|
|
68
68
|
|
69
69
|
if (!opts.noScope && !scope) {
|
70
70
|
if (parent.type !== "Program" && parent.type !== "File") {
|
71
|
-
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " +
|
71
|
+
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath.");
|
72
72
|
}
|
73
73
|
}
|
74
74
|
|
@@ -85,23 +85,11 @@ traverse.cheap = function (node, enter) {
|
|
85
85
|
};
|
86
86
|
|
87
87
|
traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
|
88
|
-
|
88
|
+
const keys = t().VISITOR_KEYS[node.type];
|
89
89
|
if (!keys) return;
|
90
|
-
|
91
|
-
|
92
|
-
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
93
|
-
var _ref;
|
94
|
-
|
95
|
-
if (_isArray) {
|
96
|
-
if (_i >= _iterator.length) break;
|
97
|
-
_ref = _iterator[_i++];
|
98
|
-
} else {
|
99
|
-
_i = _iterator.next();
|
100
|
-
if (_i.done) break;
|
101
|
-
_ref = _i.value;
|
102
|
-
}
|
90
|
+
const context = new _context.default(scope, opts, state, parentPath);
|
103
91
|
|
104
|
-
|
92
|
+
for (const key of keys) {
|
105
93
|
if (skipKeys && skipKeys[key]) continue;
|
106
94
|
if (context.visit(node, key)) return;
|
107
95
|
}
|
@@ -127,7 +115,7 @@ function hasBlacklistedType(path, state) {
|
|
127
115
|
traverse.hasType = function (tree, type, blacklistTypes) {
|
128
116
|
if ((0, _includes().default)(blacklistTypes, tree.type)) return false;
|
129
117
|
if (tree.type === type) return true;
|
130
|
-
|
118
|
+
const state = {
|
131
119
|
has: false,
|
132
120
|
type: type
|
133
121
|
};
|
package/lib/path/ancestry.js
CHANGED
@@ -15,9 +15,9 @@ exports.isDescendant = isDescendant;
|
|
15
15
|
exports.inType = inType;
|
16
16
|
|
17
17
|
function t() {
|
18
|
-
|
18
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
19
19
|
|
20
|
-
t = function
|
20
|
+
t = function () {
|
21
21
|
return data;
|
22
22
|
};
|
23
23
|
|
@@ -31,7 +31,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
31
31
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
32
32
|
|
33
33
|
function findParent(callback) {
|
34
|
-
|
34
|
+
let path = this;
|
35
35
|
|
36
36
|
while (path = path.parentPath) {
|
37
37
|
if (callback(path)) return path;
|
@@ -41,7 +41,7 @@ function findParent(callback) {
|
|
41
41
|
}
|
42
42
|
|
43
43
|
function find(callback) {
|
44
|
-
|
44
|
+
let path = this;
|
45
45
|
|
46
46
|
do {
|
47
47
|
if (callback(path)) return path;
|
@@ -51,13 +51,11 @@ function find(callback) {
|
|
51
51
|
}
|
52
52
|
|
53
53
|
function getFunctionParent() {
|
54
|
-
return this.findParent(
|
55
|
-
return p.isFunction();
|
56
|
-
});
|
54
|
+
return this.findParent(p => p.isFunction());
|
57
55
|
}
|
58
56
|
|
59
57
|
function getStatementParent() {
|
60
|
-
|
58
|
+
let path = this;
|
61
59
|
|
62
60
|
do {
|
63
61
|
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
@@ -76,13 +74,11 @@ function getStatementParent() {
|
|
76
74
|
|
77
75
|
function getEarliestCommonAncestorFrom(paths) {
|
78
76
|
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
|
79
|
-
|
80
|
-
|
81
|
-
var _arr = ancestries;
|
77
|
+
let earliest;
|
78
|
+
const keys = t().VISITOR_KEYS[deepest.type];
|
82
79
|
|
83
|
-
for (
|
84
|
-
|
85
|
-
var path = ancestry[i + 1];
|
80
|
+
for (const ancestry of ancestries) {
|
81
|
+
const path = ancestry[i + 1];
|
86
82
|
|
87
83
|
if (!earliest) {
|
88
84
|
earliest = path;
|
@@ -96,8 +92,8 @@ function getEarliestCommonAncestorFrom(paths) {
|
|
96
92
|
}
|
97
93
|
}
|
98
94
|
|
99
|
-
|
100
|
-
|
95
|
+
const earliestKeyIndex = keys.indexOf(earliest.parentKey);
|
96
|
+
const currentKeyIndex = keys.indexOf(path.parentKey);
|
101
97
|
|
102
98
|
if (earliestKeyIndex > currentKeyIndex) {
|
103
99
|
earliest = path;
|
@@ -109,8 +105,6 @@ function getEarliestCommonAncestorFrom(paths) {
|
|
109
105
|
}
|
110
106
|
|
111
107
|
function getDeepestCommonAncestorFrom(paths, filter) {
|
112
|
-
var _this = this;
|
113
|
-
|
114
108
|
if (!paths.length) {
|
115
109
|
return this;
|
116
110
|
}
|
@@ -119,14 +113,14 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
119
113
|
return paths[0];
|
120
114
|
}
|
121
115
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
116
|
+
let minDepth = Infinity;
|
117
|
+
let lastCommonIndex, lastCommon;
|
118
|
+
const ancestries = paths.map(path => {
|
119
|
+
const ancestry = [];
|
126
120
|
|
127
121
|
do {
|
128
122
|
ancestry.unshift(path);
|
129
|
-
} while ((path = path.parentPath) && path !==
|
123
|
+
} while ((path = path.parentPath) && path !== this);
|
130
124
|
|
131
125
|
if (ancestry.length < minDepth) {
|
132
126
|
minDepth = ancestry.length;
|
@@ -134,15 +128,12 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
134
128
|
|
135
129
|
return ancestry;
|
136
130
|
});
|
137
|
-
|
138
|
-
|
139
|
-
depthLoop: for (var i = 0; i < minDepth; i++) {
|
140
|
-
var shouldMatch = first[i];
|
141
|
-
var _arr2 = ancestries;
|
131
|
+
const first = ancestries[0];
|
142
132
|
|
143
|
-
|
144
|
-
|
133
|
+
depthLoop: for (let i = 0; i < minDepth; i++) {
|
134
|
+
const shouldMatch = first[i];
|
145
135
|
|
136
|
+
for (const ancestry of ancestries) {
|
146
137
|
if (ancestry[i] !== shouldMatch) {
|
147
138
|
break depthLoop;
|
148
139
|
}
|
@@ -164,8 +155,8 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
164
155
|
}
|
165
156
|
|
166
157
|
function getAncestry() {
|
167
|
-
|
168
|
-
|
158
|
+
let path = this;
|
159
|
+
const paths = [];
|
169
160
|
|
170
161
|
do {
|
171
162
|
paths.push(path);
|
@@ -179,19 +170,14 @@ function isAncestor(maybeDescendant) {
|
|
179
170
|
}
|
180
171
|
|
181
172
|
function isDescendant(maybeAncestor) {
|
182
|
-
return !!this.findParent(
|
183
|
-
return parent === maybeAncestor;
|
184
|
-
});
|
173
|
+
return !!this.findParent(parent => parent === maybeAncestor);
|
185
174
|
}
|
186
175
|
|
187
176
|
function inType() {
|
188
|
-
|
177
|
+
let path = this;
|
189
178
|
|
190
179
|
while (path) {
|
191
|
-
|
192
|
-
|
193
|
-
for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
|
194
|
-
var type = _arr3[_i3];
|
180
|
+
for (const type of arguments) {
|
195
181
|
if (path.node.type === type) return true;
|
196
182
|
}
|
197
183
|
|
package/lib/path/comments.js
CHANGED
@@ -8,9 +8,9 @@ exports.addComment = addComment;
|
|
8
8
|
exports.addComments = addComments;
|
9
9
|
|
10
10
|
function t() {
|
11
|
-
|
11
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
12
12
|
|
13
|
-
t = function
|
13
|
+
t = function () {
|
14
14
|
return data;
|
15
15
|
};
|
16
16
|
|
@@ -21,15 +21,15 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
21
21
|
|
22
22
|
function shareCommentsWithSiblings() {
|
23
23
|
if (typeof this.key === "string") return;
|
24
|
-
|
24
|
+
const node = this.node;
|
25
25
|
if (!node) return;
|
26
|
-
|
27
|
-
|
26
|
+
const trailing = node.trailingComments;
|
27
|
+
const leading = node.leadingComments;
|
28
28
|
if (!trailing && !leading) return;
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
const prev = this.getSibling(this.key - 1);
|
30
|
+
const next = this.getSibling(this.key + 1);
|
31
|
+
const hasPrev = Boolean(prev.node);
|
32
|
+
const hasNext = Boolean(next.node);
|
33
33
|
|
34
34
|
if (hasPrev && hasNext) {} else if (hasPrev) {
|
35
35
|
prev.addComments("trailing", trailing);
|
package/lib/path/context.js
CHANGED
@@ -29,7 +29,7 @@ var _index = _interopRequireDefault(require("../index"));
|
|
29
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
30
30
|
|
31
31
|
function call(key) {
|
32
|
-
|
32
|
+
const opts = this.opts;
|
33
33
|
this.debug(key);
|
34
34
|
|
35
35
|
if (this.node) {
|
@@ -46,30 +46,18 @@ function call(key) {
|
|
46
46
|
function _call(fns) {
|
47
47
|
if (!fns) return false;
|
48
48
|
|
49
|
-
for (
|
50
|
-
var _ref;
|
51
|
-
|
52
|
-
if (_isArray) {
|
53
|
-
if (_i >= _iterator.length) break;
|
54
|
-
_ref = _iterator[_i++];
|
55
|
-
} else {
|
56
|
-
_i = _iterator.next();
|
57
|
-
if (_i.done) break;
|
58
|
-
_ref = _i.value;
|
59
|
-
}
|
60
|
-
|
61
|
-
var fn = _ref;
|
49
|
+
for (const fn of fns) {
|
62
50
|
if (!fn) continue;
|
63
|
-
|
51
|
+
const node = this.node;
|
64
52
|
if (!node) return true;
|
65
|
-
|
53
|
+
const ret = fn.call(this.state, this, this.state);
|
66
54
|
|
67
55
|
if (ret && typeof ret === "object" && typeof ret.then === "function") {
|
68
|
-
throw new Error(
|
56
|
+
throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support.` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
|
69
57
|
}
|
70
58
|
|
71
59
|
if (ret) {
|
72
|
-
throw new Error(
|
60
|
+
throw new Error(`Unexpected return value from visitor method ${fn}`);
|
73
61
|
}
|
74
62
|
|
75
63
|
if (this.node !== node) return true;
|
@@ -80,7 +68,7 @@ function _call(fns) {
|
|
80
68
|
}
|
81
69
|
|
82
70
|
function isBlacklisted() {
|
83
|
-
|
71
|
+
const blacklist = this.opts.blacklist;
|
84
72
|
return blacklist && blacklist.indexOf(this.node.type) > -1;
|
85
73
|
}
|
86
74
|
|
@@ -125,8 +113,8 @@ function stop() {
|
|
125
113
|
|
126
114
|
function setScope() {
|
127
115
|
if (this.opts && this.opts.noScope) return;
|
128
|
-
|
129
|
-
|
116
|
+
let path = this.parentPath;
|
117
|
+
let target;
|
130
118
|
|
131
119
|
while (path && !target) {
|
132
120
|
if (path.opts && path.opts.noScope) return;
|
@@ -175,13 +163,13 @@ function _resyncKey() {
|
|
175
163
|
if (this.node === this.container[this.key]) return;
|
176
164
|
|
177
165
|
if (Array.isArray(this.container)) {
|
178
|
-
for (
|
166
|
+
for (let i = 0; i < this.container.length; i++) {
|
179
167
|
if (this.container[i] === this.node) {
|
180
168
|
return this.setKey(i);
|
181
169
|
}
|
182
170
|
}
|
183
171
|
} else {
|
184
|
-
for (
|
172
|
+
for (const key in this.container) {
|
185
173
|
if (this.container[key] === this.node) {
|
186
174
|
return this.setKey(key);
|
187
175
|
}
|
@@ -193,7 +181,7 @@ function _resyncKey() {
|
|
193
181
|
|
194
182
|
function _resyncList() {
|
195
183
|
if (!this.parent || !this.inList) return;
|
196
|
-
|
184
|
+
const newContainer = this.parent[this.listKey];
|
197
185
|
if (this.container === newContainer) return;
|
198
186
|
this.container = newContainer || null;
|
199
187
|
}
|
@@ -234,34 +222,18 @@ function setKey(key) {
|
|
234
222
|
this.type = this.node && this.node.type;
|
235
223
|
}
|
236
224
|
|
237
|
-
function requeue(pathToQueue) {
|
238
|
-
if (pathToQueue === void 0) {
|
239
|
-
pathToQueue = this;
|
240
|
-
}
|
241
|
-
|
225
|
+
function requeue(pathToQueue = this) {
|
242
226
|
if (pathToQueue.removed) return;
|
243
|
-
|
244
|
-
|
245
|
-
for (var _iterator2 = contexts, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
246
|
-
var _ref2;
|
247
|
-
|
248
|
-
if (_isArray2) {
|
249
|
-
if (_i2 >= _iterator2.length) break;
|
250
|
-
_ref2 = _iterator2[_i2++];
|
251
|
-
} else {
|
252
|
-
_i2 = _iterator2.next();
|
253
|
-
if (_i2.done) break;
|
254
|
-
_ref2 = _i2.value;
|
255
|
-
}
|
227
|
+
const contexts = this.contexts;
|
256
228
|
|
257
|
-
|
229
|
+
for (const context of contexts) {
|
258
230
|
context.maybeQueue(pathToQueue);
|
259
231
|
}
|
260
232
|
}
|
261
233
|
|
262
234
|
function _getQueueContexts() {
|
263
|
-
|
264
|
-
|
235
|
+
let path = this;
|
236
|
+
let contexts = this.contexts;
|
265
237
|
|
266
238
|
while (!contexts.length) {
|
267
239
|
path = path.parentPath;
|