@babel/traverse 7.0.0-beta.46 → 7.0.0-beta.47
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/cache.js +2 -2
- package/lib/context.js +34 -38
- package/lib/hub.js +6 -3
- package/lib/index.js +7 -7
- package/lib/path/ancestry.js +25 -31
- package/lib/path/comments.js +8 -8
- package/lib/path/context.js +17 -21
- package/lib/path/conversion.js +119 -126
- package/lib/path/evaluation.js +87 -99
- package/lib/path/family.js +26 -36
- package/lib/path/index.js +59 -77
- package/lib/path/inference/index.js +11 -11
- package/lib/path/inference/inferer-reference.js +36 -38
- package/lib/path/inference/inferers.js +14 -14
- package/lib/path/introspection.js +51 -57
- package/lib/path/lib/hoister.js +48 -50
- package/lib/path/lib/removal-hooks.js +2 -2
- package/lib/path/lib/virtual-types.js +75 -45
- package/lib/path/modification.js +33 -42
- package/lib/path/removal.js +3 -7
- package/lib/path/replacement.js +29 -32
- package/lib/scope/binding.js +20 -22
- package/lib/scope/index.js +271 -284
- package/lib/scope/lib/renamer.js +31 -33
- package/lib/visitors.js +59 -73
- package/package.json +9 -9
package/lib/scope/lib/renamer.js
CHANGED
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
8
8
|
var _binding = _interopRequireDefault(require("../binding"));
|
9
9
|
|
10
10
|
function _helperSplitExportDeclaration() {
|
11
|
-
|
11
|
+
const data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
12
12
|
|
13
13
|
_helperSplitExportDeclaration = function _helperSplitExportDeclaration() {
|
14
14
|
return data;
|
@@ -18,7 +18,7 @@ function _helperSplitExportDeclaration() {
|
|
18
18
|
}
|
19
19
|
|
20
20
|
function t() {
|
21
|
-
|
21
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
22
22
|
|
23
23
|
t = function t() {
|
24
24
|
return data;
|
@@ -31,39 +31,40 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
31
31
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
33
|
|
34
|
-
|
35
|
-
ReferencedIdentifier
|
36
|
-
|
37
|
-
|
34
|
+
const renameVisitor = {
|
35
|
+
ReferencedIdentifier({
|
36
|
+
node
|
37
|
+
}, state) {
|
38
38
|
if (node.name === state.oldName) {
|
39
39
|
node.name = state.newName;
|
40
40
|
}
|
41
41
|
},
|
42
|
-
|
42
|
+
|
43
|
+
Scope(path, state) {
|
43
44
|
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
|
44
45
|
path.skip();
|
45
46
|
}
|
46
47
|
},
|
47
|
-
"AssignmentExpression|Declaration": function AssignmentExpressionDeclaration(path, state) {
|
48
|
-
var ids = path.getOuterBindingIdentifiers();
|
49
48
|
|
50
|
-
|
49
|
+
"AssignmentExpression|Declaration"(path, state) {
|
50
|
+
const ids = path.getOuterBindingIdentifiers();
|
51
|
+
|
52
|
+
for (const name in ids) {
|
51
53
|
if (name === state.oldName) ids[name].name = state.newName;
|
52
54
|
}
|
53
55
|
}
|
56
|
+
|
54
57
|
};
|
55
58
|
|
56
|
-
|
57
|
-
|
59
|
+
class Renamer {
|
60
|
+
constructor(binding, oldName, newName) {
|
58
61
|
this.newName = newName;
|
59
62
|
this.oldName = oldName;
|
60
63
|
this.binding = binding;
|
61
64
|
}
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
_proto.maybeConvertFromExportDeclaration = function maybeConvertFromExportDeclaration(parentDeclar) {
|
66
|
-
var maybeExportDeclar = parentDeclar.parentPath;
|
66
|
+
maybeConvertFromExportDeclaration(parentDeclar) {
|
67
|
+
const maybeExportDeclar = parentDeclar.parentPath;
|
67
68
|
|
68
69
|
if (!maybeExportDeclar.isExportDeclaration()) {
|
69
70
|
return;
|
@@ -74,18 +75,18 @@ var Renamer = function () {
|
|
74
75
|
}
|
75
76
|
|
76
77
|
(0, _helperSplitExportDeclaration().default)(maybeExportDeclar);
|
77
|
-
}
|
78
|
+
}
|
78
79
|
|
79
|
-
|
80
|
+
maybeConvertFromClassFunctionDeclaration(path) {
|
80
81
|
return;
|
81
82
|
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
|
82
83
|
if (this.binding.kind !== "hoisted") return;
|
83
84
|
path.node.id = t().identifier(this.oldName);
|
84
85
|
path.node._blockHoist = 3;
|
85
86
|
path.replaceWith(t().variableDeclaration("let", [t().variableDeclarator(t().identifier(this.newName), t().toExpression(path.node))]));
|
86
|
-
}
|
87
|
+
}
|
87
88
|
|
88
|
-
|
89
|
+
maybeConvertFromClassFunctionExpression(path) {
|
89
90
|
return;
|
90
91
|
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
|
91
92
|
if (this.binding.kind !== "local") return;
|
@@ -94,17 +95,15 @@ var Renamer = function () {
|
|
94
95
|
id: t().identifier(this.newName)
|
95
96
|
});
|
96
97
|
path.replaceWith(t().assignmentExpression("=", t().identifier(this.newName), path.node));
|
97
|
-
}
|
98
|
+
}
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
return path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression();
|
107
|
-
});
|
100
|
+
rename(block) {
|
101
|
+
const binding = this.binding,
|
102
|
+
oldName = this.oldName,
|
103
|
+
newName = this.newName;
|
104
|
+
const scope = binding.scope,
|
105
|
+
path = binding.path;
|
106
|
+
const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression());
|
108
107
|
|
109
108
|
if (parentDeclar) {
|
110
109
|
this.maybeConvertFromExportDeclaration(parentDeclar);
|
@@ -124,9 +123,8 @@ var Renamer = function () {
|
|
124
123
|
this.maybeConvertFromClassFunctionDeclaration(parentDeclar);
|
125
124
|
this.maybeConvertFromClassFunctionExpression(parentDeclar);
|
126
125
|
}
|
127
|
-
}
|
126
|
+
}
|
128
127
|
|
129
|
-
|
130
|
-
}();
|
128
|
+
}
|
131
129
|
|
132
130
|
exports.default = Renamer;
|
package/lib/visitors.js
CHANGED
@@ -10,7 +10,7 @@ exports.merge = merge;
|
|
10
10
|
var virtualTypes = _interopRequireWildcard(require("./path/lib/virtual-types"));
|
11
11
|
|
12
12
|
function t() {
|
13
|
-
|
13
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
14
14
|
|
15
15
|
t = function t() {
|
16
16
|
return data;
|
@@ -20,7 +20,7 @@ function t() {
|
|
20
20
|
}
|
21
21
|
|
22
22
|
function _clone() {
|
23
|
-
|
23
|
+
const data = _interopRequireDefault(require("lodash/clone"));
|
24
24
|
|
25
25
|
_clone = function _clone() {
|
26
26
|
return data;
|
@@ -37,11 +37,11 @@ function explode(visitor) {
|
|
37
37
|
if (visitor._exploded) return visitor;
|
38
38
|
visitor._exploded = true;
|
39
39
|
|
40
|
-
for (
|
40
|
+
for (const nodeType in visitor) {
|
41
41
|
if (shouldIgnoreKey(nodeType)) continue;
|
42
|
-
|
42
|
+
const parts = nodeType.split("|");
|
43
43
|
if (parts.length === 1) continue;
|
44
|
-
|
44
|
+
const fns = visitor[nodeType];
|
45
45
|
delete visitor[nodeType];
|
46
46
|
|
47
47
|
for (var _iterator = parts, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
@@ -56,7 +56,7 @@ function explode(visitor) {
|
|
56
56
|
_ref = _i.value;
|
57
57
|
}
|
58
58
|
|
59
|
-
|
59
|
+
const part = _ref;
|
60
60
|
visitor[part] = fns;
|
61
61
|
}
|
62
62
|
}
|
@@ -69,50 +69,48 @@ function explode(visitor) {
|
|
69
69
|
var _arr = Object.keys(visitor);
|
70
70
|
|
71
71
|
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
|
72
|
-
|
73
|
-
if (shouldIgnoreKey(
|
74
|
-
|
72
|
+
const nodeType = _arr[_i2];
|
73
|
+
if (shouldIgnoreKey(nodeType)) continue;
|
74
|
+
const wrapper = virtualTypes[nodeType];
|
75
75
|
if (!wrapper) continue;
|
76
|
-
|
76
|
+
const fns = visitor[nodeType];
|
77
77
|
|
78
|
-
for (
|
79
|
-
|
78
|
+
for (const type in fns) {
|
79
|
+
fns[type] = wrapCheck(wrapper, fns[type]);
|
80
80
|
}
|
81
81
|
|
82
|
-
delete visitor[
|
82
|
+
delete visitor[nodeType];
|
83
83
|
|
84
84
|
if (wrapper.types) {
|
85
85
|
var _arr2 = wrapper.types;
|
86
86
|
|
87
87
|
for (var _i4 = 0; _i4 < _arr2.length; _i4++) {
|
88
|
-
|
88
|
+
const type = _arr2[_i4];
|
89
89
|
|
90
|
-
if (visitor[
|
91
|
-
mergePair(visitor[
|
90
|
+
if (visitor[type]) {
|
91
|
+
mergePair(visitor[type], fns);
|
92
92
|
} else {
|
93
|
-
visitor[
|
93
|
+
visitor[type] = fns;
|
94
94
|
}
|
95
95
|
}
|
96
96
|
} else {
|
97
|
-
mergePair(visitor,
|
97
|
+
mergePair(visitor, fns);
|
98
98
|
}
|
99
99
|
}
|
100
100
|
|
101
|
-
for (
|
102
|
-
if (shouldIgnoreKey(
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
var deprecratedKey = t().DEPRECATED_KEYS[_nodeType];
|
101
|
+
for (const nodeType in visitor) {
|
102
|
+
if (shouldIgnoreKey(nodeType)) continue;
|
103
|
+
const fns = visitor[nodeType];
|
104
|
+
let aliases = t().FLIPPED_ALIAS_KEYS[nodeType];
|
105
|
+
const deprecratedKey = t().DEPRECATED_KEYS[nodeType];
|
108
106
|
|
109
107
|
if (deprecratedKey) {
|
110
|
-
console.trace(
|
108
|
+
console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecratedKey}`);
|
111
109
|
aliases = [deprecratedKey];
|
112
110
|
}
|
113
111
|
|
114
112
|
if (!aliases) continue;
|
115
|
-
delete visitor[
|
113
|
+
delete visitor[nodeType];
|
116
114
|
|
117
115
|
for (var _iterator2 = aliases, _isArray2 = Array.isArray(_iterator2), _i3 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
118
116
|
var _ref2;
|
@@ -126,20 +124,20 @@ function explode(visitor) {
|
|
126
124
|
_ref2 = _i3.value;
|
127
125
|
}
|
128
126
|
|
129
|
-
|
130
|
-
|
127
|
+
const alias = _ref2;
|
128
|
+
const existing = visitor[alias];
|
131
129
|
|
132
130
|
if (existing) {
|
133
|
-
mergePair(existing,
|
131
|
+
mergePair(existing, fns);
|
134
132
|
} else {
|
135
|
-
visitor[alias] = (0, _clone().default)(
|
133
|
+
visitor[alias] = (0, _clone().default)(fns);
|
136
134
|
}
|
137
135
|
}
|
138
136
|
}
|
139
137
|
|
140
|
-
for (
|
141
|
-
if (shouldIgnoreKey(
|
142
|
-
ensureCallbackArrays(visitor[
|
138
|
+
for (const nodeType in visitor) {
|
139
|
+
if (shouldIgnoreKey(nodeType)) continue;
|
140
|
+
ensureCallbackArrays(visitor[nodeType]);
|
143
141
|
}
|
144
142
|
|
145
143
|
return visitor;
|
@@ -152,7 +150,7 @@ function verify(visitor) {
|
|
152
150
|
throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
|
153
151
|
}
|
154
152
|
|
155
|
-
for (
|
153
|
+
for (const nodeType in visitor) {
|
156
154
|
if (nodeType === "enter" || nodeType === "exit") {
|
157
155
|
validateVisitorMethods(nodeType, visitor[nodeType]);
|
158
156
|
}
|
@@ -160,17 +158,17 @@ function verify(visitor) {
|
|
160
158
|
if (shouldIgnoreKey(nodeType)) continue;
|
161
159
|
|
162
160
|
if (t().TYPES.indexOf(nodeType) < 0) {
|
163
|
-
throw new Error(
|
161
|
+
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
|
164
162
|
}
|
165
163
|
|
166
|
-
|
164
|
+
const visitors = visitor[nodeType];
|
167
165
|
|
168
166
|
if (typeof visitors === "object") {
|
169
|
-
for (
|
167
|
+
for (const visitorKey in visitors) {
|
170
168
|
if (visitorKey === "enter" || visitorKey === "exit") {
|
171
|
-
validateVisitorMethods(nodeType
|
169
|
+
validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
|
172
170
|
} else {
|
173
|
-
throw new Error("You passed `traverse()` a visitor object with the property " +
|
171
|
+
throw new Error("You passed `traverse()` a visitor object with the property " + `${nodeType} that has the invalid property ${visitorKey}`);
|
174
172
|
}
|
175
173
|
}
|
176
174
|
}
|
@@ -180,7 +178,7 @@ function verify(visitor) {
|
|
180
178
|
}
|
181
179
|
|
182
180
|
function validateVisitorMethods(path, val) {
|
183
|
-
|
181
|
+
const fns = [].concat(val);
|
184
182
|
|
185
183
|
for (var _iterator3 = fns, _isArray3 = Array.isArray(_iterator3), _i5 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
186
184
|
var _ref3;
|
@@ -194,34 +192,30 @@ function validateVisitorMethods(path, val) {
|
|
194
192
|
_ref3 = _i5.value;
|
195
193
|
}
|
196
194
|
|
197
|
-
|
195
|
+
const fn = _ref3;
|
198
196
|
|
199
197
|
if (typeof fn !== "function") {
|
200
|
-
throw new TypeError(
|
198
|
+
throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`);
|
201
199
|
}
|
202
200
|
}
|
203
201
|
}
|
204
202
|
|
205
|
-
function merge(visitors, states, wrapper) {
|
206
|
-
|
207
|
-
states = [];
|
208
|
-
}
|
209
|
-
|
210
|
-
var rootVisitor = {};
|
203
|
+
function merge(visitors, states = [], wrapper) {
|
204
|
+
const rootVisitor = {};
|
211
205
|
|
212
|
-
for (
|
213
|
-
|
214
|
-
|
206
|
+
for (let i = 0; i < visitors.length; i++) {
|
207
|
+
const visitor = visitors[i];
|
208
|
+
const state = states[i];
|
215
209
|
explode(visitor);
|
216
210
|
|
217
|
-
for (
|
218
|
-
|
211
|
+
for (const type in visitor) {
|
212
|
+
let visitorType = visitor[type];
|
219
213
|
|
220
214
|
if (state || wrapper) {
|
221
215
|
visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
|
222
216
|
}
|
223
217
|
|
224
|
-
|
218
|
+
const nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
|
225
219
|
mergePair(nodeVisitor, visitorType);
|
226
220
|
}
|
227
221
|
}
|
@@ -230,13 +224,13 @@ function merge(visitors, states, wrapper) {
|
|
230
224
|
}
|
231
225
|
|
232
226
|
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
|
233
|
-
|
227
|
+
const newVisitor = {};
|
234
228
|
|
235
|
-
|
236
|
-
|
237
|
-
if (!Array.isArray(fns))
|
229
|
+
for (const key in oldVisitor) {
|
230
|
+
let fns = oldVisitor[key];
|
231
|
+
if (!Array.isArray(fns)) continue;
|
238
232
|
fns = fns.map(function (fn) {
|
239
|
-
|
233
|
+
let newFn = fn;
|
240
234
|
|
241
235
|
if (state) {
|
242
236
|
newFn = function newFn(path) {
|
@@ -251,21 +245,15 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
|
|
251
245
|
return newFn;
|
252
246
|
});
|
253
247
|
newVisitor[key] = fns;
|
254
|
-
};
|
255
|
-
|
256
|
-
for (var key in oldVisitor) {
|
257
|
-
var _ret = _loop(key);
|
258
|
-
|
259
|
-
if (_ret === "continue") continue;
|
260
248
|
}
|
261
249
|
|
262
250
|
return newVisitor;
|
263
251
|
}
|
264
252
|
|
265
253
|
function ensureEntranceObjects(obj) {
|
266
|
-
for (
|
254
|
+
for (const key in obj) {
|
267
255
|
if (shouldIgnoreKey(key)) continue;
|
268
|
-
|
256
|
+
const fns = obj[key];
|
269
257
|
|
270
258
|
if (typeof fns === "function") {
|
271
259
|
obj[key] = {
|
@@ -281,15 +269,13 @@ function ensureCallbackArrays(obj) {
|
|
281
269
|
}
|
282
270
|
|
283
271
|
function wrapCheck(wrapper, fn) {
|
284
|
-
|
272
|
+
const newFn = function newFn(path) {
|
285
273
|
if (wrapper.checkPath(path)) {
|
286
274
|
return fn.apply(this, arguments);
|
287
275
|
}
|
288
276
|
};
|
289
277
|
|
290
|
-
newFn.toString =
|
291
|
-
return fn.toString();
|
292
|
-
};
|
278
|
+
newFn.toString = () => fn.toString();
|
293
279
|
|
294
280
|
return newFn;
|
295
281
|
}
|
@@ -306,7 +292,7 @@ function shouldIgnoreKey(key) {
|
|
306
292
|
}
|
307
293
|
|
308
294
|
function mergePair(dest, src) {
|
309
|
-
for (
|
295
|
+
for (const key in src) {
|
310
296
|
dest[key] = [].concat(dest[key] || [], src[key]);
|
311
297
|
}
|
312
298
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.0.0-beta.
|
3
|
+
"version": "7.0.0-beta.47",
|
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/",
|
@@ -8,18 +8,18 @@
|
|
8
8
|
"repository": "https://github.com/babel/babel/tree/master/packages/babel-traverse",
|
9
9
|
"main": "lib/index.js",
|
10
10
|
"dependencies": {
|
11
|
-
"@babel/code-frame": "7.0.0-beta.
|
12
|
-
"@babel/generator": "7.0.0-beta.
|
13
|
-
"@babel/helper-function-name": "7.0.0-beta.
|
14
|
-
"@babel/helper-split-export-declaration": "7.0.0-beta.
|
15
|
-
"@babel/types": "7.0.0-beta.
|
16
|
-
"babylon": "7.0.0-beta.
|
11
|
+
"@babel/code-frame": "7.0.0-beta.47",
|
12
|
+
"@babel/generator": "7.0.0-beta.47",
|
13
|
+
"@babel/helper-function-name": "7.0.0-beta.47",
|
14
|
+
"@babel/helper-split-export-declaration": "7.0.0-beta.47",
|
15
|
+
"@babel/types": "7.0.0-beta.47",
|
16
|
+
"babylon": "7.0.0-beta.47",
|
17
17
|
"debug": "^3.1.0",
|
18
18
|
"globals": "^11.1.0",
|
19
19
|
"invariant": "^2.2.0",
|
20
|
-
"lodash": "^4.
|
20
|
+
"lodash": "^4.17.5"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
|
-
"@babel/helper-plugin-test-runner": "7.0.0-beta.
|
23
|
+
"@babel/helper-plugin-test-runner": "7.0.0-beta.47"
|
24
24
|
}
|
25
25
|
}
|