@babel/traverse 7.3.4 → 7.4.0
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/path/context.js +1 -1
- package/lib/path/index.js +1 -1
- package/lib/path/inference/inferers.js +5 -0
- package/lib/path/lib/hoister.js +3 -3
- package/lib/path/lib/virtual-types.js +14 -10
- package/lib/path/replacement.js +1 -1
- package/lib/scope/index.js +7 -9
- package/lib/visitors.js +10 -10
- package/package.json +6 -6
package/lib/path/context.js
CHANGED
package/lib/path/index.js
CHANGED
@@ -208,7 +208,7 @@ for (const type of t().TYPES) {
|
|
208
208
|
};
|
209
209
|
}
|
210
210
|
|
211
|
-
for (const type
|
211
|
+
for (const type of Object.keys(virtualTypes)) {
|
212
212
|
if (type[0] === "_") continue;
|
213
213
|
if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type);
|
214
214
|
const virtualType = virtualTypes[type];
|
@@ -12,6 +12,7 @@ exports.BinaryExpression = BinaryExpression;
|
|
12
12
|
exports.LogicalExpression = LogicalExpression;
|
13
13
|
exports.ConditionalExpression = ConditionalExpression;
|
14
14
|
exports.SequenceExpression = SequenceExpression;
|
15
|
+
exports.ParenthesizedExpression = ParenthesizedExpression;
|
15
16
|
exports.AssignmentExpression = AssignmentExpression;
|
16
17
|
exports.UpdateExpression = UpdateExpression;
|
17
18
|
exports.StringLiteral = StringLiteral;
|
@@ -128,6 +129,10 @@ function SequenceExpression() {
|
|
128
129
|
return this.get("expressions").pop().getTypeAnnotation();
|
129
130
|
}
|
130
131
|
|
132
|
+
function ParenthesizedExpression() {
|
133
|
+
return this.get("expression").getTypeAnnotation();
|
134
|
+
}
|
135
|
+
|
131
136
|
function AssignmentExpression() {
|
132
137
|
return this.get("right").getTypeAnnotation();
|
133
138
|
}
|
package/lib/path/lib/hoister.js
CHANGED
@@ -54,7 +54,7 @@ class PathHoister {
|
|
54
54
|
}
|
55
55
|
|
56
56
|
isCompatibleScope(scope) {
|
57
|
-
for (const key
|
57
|
+
for (const key of Object.keys(this.bindings)) {
|
58
58
|
const binding = this.bindings[key];
|
59
59
|
|
60
60
|
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
@@ -92,7 +92,7 @@ class PathHoister {
|
|
92
92
|
}
|
93
93
|
|
94
94
|
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
|
95
|
-
for (const name
|
95
|
+
for (const name of Object.keys(this.bindings)) {
|
96
96
|
if (!targetScope.hasOwnBinding(name)) continue;
|
97
97
|
const binding = this.bindings[name];
|
98
98
|
|
@@ -154,7 +154,7 @@ class PathHoister {
|
|
154
154
|
}
|
155
155
|
|
156
156
|
hasOwnParamBindings(scope) {
|
157
|
-
for (const name
|
157
|
+
for (const name of Object.keys(this.bindings)) {
|
158
158
|
if (!scope.hasOwnBinding(name)) continue;
|
159
159
|
const binding = this.bindings[name];
|
160
160
|
if (binding.kind === "param" && binding.constant) return true;
|
@@ -20,10 +20,12 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
20
20
|
const ReferencedIdentifier = {
|
21
21
|
types: ["Identifier", "JSXIdentifier"],
|
22
22
|
|
23
|
-
checkPath({
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
checkPath(path, opts) {
|
24
|
+
const {
|
25
|
+
node,
|
26
|
+
parent
|
27
|
+
} = path;
|
28
|
+
|
27
29
|
if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) {
|
28
30
|
if (t().isJSXIdentifier(node, opts)) {
|
29
31
|
if (t().react.isCompatTag(node.name)) return false;
|
@@ -32,7 +34,7 @@ const ReferencedIdentifier = {
|
|
32
34
|
}
|
33
35
|
}
|
34
36
|
|
35
|
-
return t().isReferenced(node, parent);
|
37
|
+
return t().isReferenced(node, parent, path.parentPath.parent);
|
36
38
|
}
|
37
39
|
|
38
40
|
};
|
@@ -52,11 +54,13 @@ exports.ReferencedMemberExpression = ReferencedMemberExpression;
|
|
52
54
|
const BindingIdentifier = {
|
53
55
|
types: ["Identifier"],
|
54
56
|
|
55
|
-
checkPath({
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
checkPath(path) {
|
58
|
+
const {
|
59
|
+
node,
|
60
|
+
parent
|
61
|
+
} = path;
|
62
|
+
const grandparent = path.parentPath.parent;
|
63
|
+
return t().isIdentifier(node) && t().isBinding(node, parent, grandparent);
|
60
64
|
}
|
61
65
|
|
62
66
|
};
|
package/lib/path/replacement.js
CHANGED
package/lib/scope/index.js
CHANGED
@@ -152,9 +152,7 @@ const collectorVisitor = {
|
|
152
152
|
if (binding) binding.reference(path);
|
153
153
|
} else if (t().isVariableDeclaration(declar)) {
|
154
154
|
for (const decl of declar.declarations) {
|
155
|
-
const
|
156
|
-
|
157
|
-
for (const name in ids) {
|
155
|
+
for (const name of Object.keys(t().getBindingIdentifiers(decl))) {
|
158
156
|
const binding = scope.getBinding(name);
|
159
157
|
if (binding) binding.reference(path);
|
160
158
|
}
|
@@ -371,7 +369,7 @@ class Scope {
|
|
371
369
|
do {
|
372
370
|
console.log("#", scope.block.type);
|
373
371
|
|
374
|
-
for (const name
|
372
|
+
for (const name of Object.keys(scope.bindings)) {
|
375
373
|
const binding = scope.bindings[name];
|
376
374
|
console.log(" -", name, {
|
377
375
|
constant: binding.constant,
|
@@ -472,7 +470,7 @@ class Scope {
|
|
472
470
|
registerConstantViolation(path) {
|
473
471
|
const ids = path.getBindingIdentifiers();
|
474
472
|
|
475
|
-
for (const name
|
473
|
+
for (const name of Object.keys(ids)) {
|
476
474
|
const binding = this.getBinding(name);
|
477
475
|
if (binding) binding.reassign(path);
|
478
476
|
}
|
@@ -492,9 +490,9 @@ class Scope {
|
|
492
490
|
}
|
493
491
|
|
494
492
|
const parent = this.getProgramParent();
|
495
|
-
const ids = path.
|
493
|
+
const ids = path.getOuterBindingIdentifiers(true);
|
496
494
|
|
497
|
-
for (const name
|
495
|
+
for (const name of Object.keys(ids)) {
|
498
496
|
for (const id of ids[name]) {
|
499
497
|
const local = this.getOwnBinding(name);
|
500
498
|
|
@@ -687,7 +685,7 @@ class Scope {
|
|
687
685
|
const ids = path.getBindingIdentifiers();
|
688
686
|
let programParent;
|
689
687
|
|
690
|
-
for (const name
|
688
|
+
for (const name of Object.keys(ids)) {
|
691
689
|
if (path.scope.getBinding(name)) continue;
|
692
690
|
programParent = programParent || path.scope.getProgramParent();
|
693
691
|
programParent.addGlobal(ids[name]);
|
@@ -800,7 +798,7 @@ class Scope {
|
|
800
798
|
let scope = this;
|
801
799
|
|
802
800
|
do {
|
803
|
-
for (const name
|
801
|
+
for (const name of Object.keys(scope.bindings)) {
|
804
802
|
const binding = scope.bindings[name];
|
805
803
|
if (binding.kind === kind) ids[name] = binding;
|
806
804
|
}
|
package/lib/visitors.js
CHANGED
@@ -37,7 +37,7 @@ function explode(visitor) {
|
|
37
37
|
if (visitor._exploded) return visitor;
|
38
38
|
visitor._exploded = true;
|
39
39
|
|
40
|
-
for (const nodeType
|
40
|
+
for (const nodeType of Object.keys(visitor)) {
|
41
41
|
if (shouldIgnoreKey(nodeType)) continue;
|
42
42
|
const parts = nodeType.split("|");
|
43
43
|
if (parts.length === 1) continue;
|
@@ -60,7 +60,7 @@ function explode(visitor) {
|
|
60
60
|
if (!wrapper) continue;
|
61
61
|
const fns = visitor[nodeType];
|
62
62
|
|
63
|
-
for (const type
|
63
|
+
for (const type of Object.keys(fns)) {
|
64
64
|
fns[type] = wrapCheck(wrapper, fns[type]);
|
65
65
|
}
|
66
66
|
|
@@ -79,7 +79,7 @@ function explode(visitor) {
|
|
79
79
|
}
|
80
80
|
}
|
81
81
|
|
82
|
-
for (const nodeType
|
82
|
+
for (const nodeType of Object.keys(visitor)) {
|
83
83
|
if (shouldIgnoreKey(nodeType)) continue;
|
84
84
|
const fns = visitor[nodeType];
|
85
85
|
let aliases = t().FLIPPED_ALIAS_KEYS[nodeType];
|
@@ -104,7 +104,7 @@ function explode(visitor) {
|
|
104
104
|
}
|
105
105
|
}
|
106
106
|
|
107
|
-
for (const nodeType
|
107
|
+
for (const nodeType of Object.keys(visitor)) {
|
108
108
|
if (shouldIgnoreKey(nodeType)) continue;
|
109
109
|
ensureCallbackArrays(visitor[nodeType]);
|
110
110
|
}
|
@@ -119,7 +119,7 @@ function verify(visitor) {
|
|
119
119
|
throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
|
120
120
|
}
|
121
121
|
|
122
|
-
for (const nodeType
|
122
|
+
for (const nodeType of Object.keys(visitor)) {
|
123
123
|
if (nodeType === "enter" || nodeType === "exit") {
|
124
124
|
validateVisitorMethods(nodeType, visitor[nodeType]);
|
125
125
|
}
|
@@ -133,7 +133,7 @@ function verify(visitor) {
|
|
133
133
|
const visitors = visitor[nodeType];
|
134
134
|
|
135
135
|
if (typeof visitors === "object") {
|
136
|
-
for (const visitorKey
|
136
|
+
for (const visitorKey of Object.keys(visitors)) {
|
137
137
|
if (visitorKey === "enter" || visitorKey === "exit") {
|
138
138
|
validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
|
139
139
|
} else {
|
@@ -164,7 +164,7 @@ function merge(visitors, states = [], wrapper) {
|
|
164
164
|
const state = states[i];
|
165
165
|
explode(visitor);
|
166
166
|
|
167
|
-
for (const type
|
167
|
+
for (const type of Object.keys(visitor)) {
|
168
168
|
let visitorType = visitor[type];
|
169
169
|
|
170
170
|
if (state || wrapper) {
|
@@ -182,7 +182,7 @@ function merge(visitors, states = [], wrapper) {
|
|
182
182
|
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
|
183
183
|
const newVisitor = {};
|
184
184
|
|
185
|
-
for (const key
|
185
|
+
for (const key of Object.keys(oldVisitor)) {
|
186
186
|
let fns = oldVisitor[key];
|
187
187
|
if (!Array.isArray(fns)) continue;
|
188
188
|
fns = fns.map(function (fn) {
|
@@ -207,7 +207,7 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
|
|
207
207
|
}
|
208
208
|
|
209
209
|
function ensureEntranceObjects(obj) {
|
210
|
-
for (const key
|
210
|
+
for (const key of Object.keys(obj)) {
|
211
211
|
if (shouldIgnoreKey(key)) continue;
|
212
212
|
const fns = obj[key];
|
213
213
|
|
@@ -248,7 +248,7 @@ function shouldIgnoreKey(key) {
|
|
248
248
|
}
|
249
249
|
|
250
250
|
function mergePair(dest, src) {
|
251
|
-
for (const key
|
251
|
+
for (const key of Object.keys(src)) {
|
252
252
|
dest[key] = [].concat(dest[key] || [], src[key]);
|
253
253
|
}
|
254
254
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.4.0",
|
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/",
|
@@ -12,11 +12,11 @@
|
|
12
12
|
"main": "lib/index.js",
|
13
13
|
"dependencies": {
|
14
14
|
"@babel/code-frame": "^7.0.0",
|
15
|
-
"@babel/generator": "^7.
|
15
|
+
"@babel/generator": "^7.4.0",
|
16
16
|
"@babel/helper-function-name": "^7.1.0",
|
17
|
-
"@babel/helper-split-export-declaration": "^7.
|
18
|
-
"@babel/parser": "^7.
|
19
|
-
"@babel/types": "^7.
|
17
|
+
"@babel/helper-split-export-declaration": "^7.4.0",
|
18
|
+
"@babel/parser": "^7.4.0",
|
19
|
+
"@babel/types": "^7.4.0",
|
20
20
|
"debug": "^4.1.0",
|
21
21
|
"globals": "^11.1.0",
|
22
22
|
"lodash": "^4.17.11"
|
@@ -24,5 +24,5 @@
|
|
24
24
|
"devDependencies": {
|
25
25
|
"@babel/helper-plugin-test-runner": "^7.0.0"
|
26
26
|
},
|
27
|
-
"gitHead": "
|
27
|
+
"gitHead": "f1328fb913b5a93d54dfc6e3728b1f56c8f4a804"
|
28
28
|
}
|