@babel/traverse 7.18.9 → 7.18.13
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/conversion.js +8 -1
- package/lib/path/evaluation.js +5 -0
- package/lib/path/family.js +1 -1
- package/lib/path/generated/validators.js +0 -5
- package/lib/path/index.js +5 -6
- package/lib/path/lib/removal-hooks.js +1 -1
- package/lib/path/lib/virtual-types-validator.js +183 -0
- package/lib/path/lib/virtual-types.js +18 -206
- package/lib/types.js +1 -3
- package/lib/visitors.js +12 -8
- package/package.json +4 -4
- package/scripts/generators/validators.js +7 -27
- package/lib/path/generated/virtual-types.js +0 -3
- package/scripts/generators/virtual-types.js +0 -27
package/lib/path/conversion.js
CHANGED
@@ -119,6 +119,10 @@ function unwrapFunctionEnvironment() {
|
|
119
119
|
hoistFunctionEnvironment(this);
|
120
120
|
}
|
121
121
|
|
122
|
+
function setType(path, type) {
|
123
|
+
path.node.type = type;
|
124
|
+
}
|
125
|
+
|
122
126
|
function arrowFunctionToExpression({
|
123
127
|
allowInsertArrow = true,
|
124
128
|
specCompliant = false,
|
@@ -133,7 +137,7 @@ function arrowFunctionToExpression({
|
|
133
137
|
fnPath: fn
|
134
138
|
} = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
|
135
139
|
fn.ensureBlock();
|
136
|
-
fn
|
140
|
+
setType(fn, "FunctionExpression");
|
137
141
|
|
138
142
|
if (!noNewArrows) {
|
139
143
|
const checkBinding = thisBinding ? null : fn.scope.generateUidIdentifier("arrowCheckId");
|
@@ -147,7 +151,10 @@ function arrowFunctionToExpression({
|
|
147
151
|
|
148
152
|
fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
|
149
153
|
fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
|
154
|
+
return fn.get("callee.object");
|
150
155
|
}
|
156
|
+
|
157
|
+
return fn;
|
151
158
|
}
|
152
159
|
|
153
160
|
const getSuperCallsVisitor = (0, _visitors.merge)([{
|
package/lib/path/evaluation.js
CHANGED
@@ -267,6 +267,11 @@ function _evaluate(path, state) {
|
|
267
267
|
state.confident = leftConfident && (!left || rightConfident);
|
268
268
|
if (!state.confident) return;
|
269
269
|
return left && right;
|
270
|
+
|
271
|
+
case "??":
|
272
|
+
state.confident = leftConfident && (left != null || rightConfident);
|
273
|
+
if (!state.confident) return;
|
274
|
+
return left != null ? left : right;
|
270
275
|
}
|
271
276
|
}
|
272
277
|
|
package/lib/path/family.js
CHANGED
@@ -402,6 +402,6 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
|
|
402
402
|
return ids;
|
403
403
|
}
|
404
404
|
|
405
|
-
function getOuterBindingIdentifierPaths(duplicates) {
|
405
|
+
function getOuterBindingIdentifierPaths(duplicates = false) {
|
406
406
|
return this.getBindingIdentifierPaths(duplicates, true);
|
407
407
|
}
|
package/lib/path/index.js
CHANGED
@@ -43,6 +43,8 @@ var NodePath_family = require("./family");
|
|
43
43
|
|
44
44
|
var NodePath_comments = require("./comments");
|
45
45
|
|
46
|
+
var NodePath_virtual_types_validator = require("./lib/virtual-types-validator");
|
47
|
+
|
46
48
|
const {
|
47
49
|
validate
|
48
50
|
} = _t;
|
@@ -246,14 +248,11 @@ for (const type of t.TYPES) {
|
|
246
248
|
};
|
247
249
|
}
|
248
250
|
|
251
|
+
Object.assign(NodePath.prototype, NodePath_virtual_types_validator);
|
252
|
+
|
249
253
|
for (const type of Object.keys(virtualTypes)) {
|
250
254
|
if (type[0] === "_") continue;
|
251
|
-
if (t.TYPES.
|
252
|
-
const virtualType = virtualTypes[type];
|
253
|
-
|
254
|
-
NodePath.prototype[`is${type}`] = function (opts) {
|
255
|
-
return virtualType.checkPath(this, opts);
|
256
|
-
};
|
255
|
+
if (!t.TYPES.includes(type)) t.TYPES.push(type);
|
257
256
|
}
|
258
257
|
|
259
258
|
var _default = NodePath;
|
@@ -30,7 +30,7 @@ const hooks = [function (self, parent) {
|
|
30
30
|
return true;
|
31
31
|
}
|
32
32
|
}, function (self, parent) {
|
33
|
-
if (parent.isIfStatement() &&
|
33
|
+
if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
|
34
34
|
self.replaceWith({
|
35
35
|
type: "BlockStatement",
|
36
36
|
body: []
|
@@ -0,0 +1,183 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.isBindingIdentifier = isBindingIdentifier;
|
7
|
+
exports.isBlockScoped = isBlockScoped;
|
8
|
+
exports.isExistentialTypeParam = isExistentialTypeParam;
|
9
|
+
exports.isExpression = isExpression;
|
10
|
+
exports.isFlow = isFlow;
|
11
|
+
exports.isForAwaitStatement = isForAwaitStatement;
|
12
|
+
exports.isGenerated = isGenerated;
|
13
|
+
exports.isNumericLiteralTypeAnnotation = isNumericLiteralTypeAnnotation;
|
14
|
+
exports.isPure = isPure;
|
15
|
+
exports.isReferenced = isReferenced;
|
16
|
+
exports.isReferencedIdentifier = isReferencedIdentifier;
|
17
|
+
exports.isReferencedMemberExpression = isReferencedMemberExpression;
|
18
|
+
exports.isRestProperty = isRestProperty;
|
19
|
+
exports.isScope = isScope;
|
20
|
+
exports.isSpreadProperty = isSpreadProperty;
|
21
|
+
exports.isStatement = isStatement;
|
22
|
+
exports.isUser = isUser;
|
23
|
+
exports.isVar = isVar;
|
24
|
+
|
25
|
+
var _t = require("@babel/types");
|
26
|
+
|
27
|
+
const {
|
28
|
+
isBinding,
|
29
|
+
isBlockScoped: nodeIsBlockScoped,
|
30
|
+
isExportDeclaration,
|
31
|
+
isExpression: nodeIsExpression,
|
32
|
+
isFlow: nodeIsFlow,
|
33
|
+
isForStatement,
|
34
|
+
isForXStatement,
|
35
|
+
isIdentifier,
|
36
|
+
isImportDeclaration,
|
37
|
+
isImportSpecifier,
|
38
|
+
isJSXIdentifier,
|
39
|
+
isJSXMemberExpression,
|
40
|
+
isMemberExpression,
|
41
|
+
isRestElement: nodeIsRestElement,
|
42
|
+
isReferenced: nodeIsReferenced,
|
43
|
+
isScope: nodeIsScope,
|
44
|
+
isStatement: nodeIsStatement,
|
45
|
+
isVar: nodeIsVar,
|
46
|
+
isVariableDeclaration,
|
47
|
+
react
|
48
|
+
} = _t;
|
49
|
+
const {
|
50
|
+
isCompatTag
|
51
|
+
} = react;
|
52
|
+
|
53
|
+
function isReferencedIdentifier(opts) {
|
54
|
+
const {
|
55
|
+
node,
|
56
|
+
parent
|
57
|
+
} = this;
|
58
|
+
|
59
|
+
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
60
|
+
if (isJSXIdentifier(node, opts)) {
|
61
|
+
if (isCompatTag(node.name)) return false;
|
62
|
+
} else {
|
63
|
+
return false;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
68
|
+
}
|
69
|
+
|
70
|
+
function isReferencedMemberExpression() {
|
71
|
+
const {
|
72
|
+
node,
|
73
|
+
parent
|
74
|
+
} = this;
|
75
|
+
return isMemberExpression(node) && nodeIsReferenced(node, parent);
|
76
|
+
}
|
77
|
+
|
78
|
+
function isBindingIdentifier() {
|
79
|
+
const {
|
80
|
+
node,
|
81
|
+
parent
|
82
|
+
} = this;
|
83
|
+
const grandparent = this.parentPath.parent;
|
84
|
+
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
85
|
+
}
|
86
|
+
|
87
|
+
function isStatement() {
|
88
|
+
const {
|
89
|
+
node,
|
90
|
+
parent
|
91
|
+
} = this;
|
92
|
+
|
93
|
+
if (nodeIsStatement(node)) {
|
94
|
+
if (isVariableDeclaration(node)) {
|
95
|
+
if (isForXStatement(parent, {
|
96
|
+
left: node
|
97
|
+
})) return false;
|
98
|
+
if (isForStatement(parent, {
|
99
|
+
init: node
|
100
|
+
})) return false;
|
101
|
+
}
|
102
|
+
|
103
|
+
return true;
|
104
|
+
} else {
|
105
|
+
return false;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
function isExpression() {
|
110
|
+
if (this.isIdentifier()) {
|
111
|
+
return this.isReferencedIdentifier();
|
112
|
+
} else {
|
113
|
+
return nodeIsExpression(this.node);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
function isScope() {
|
118
|
+
return nodeIsScope(this.node, this.parent);
|
119
|
+
}
|
120
|
+
|
121
|
+
function isReferenced() {
|
122
|
+
return nodeIsReferenced(this.node, this.parent);
|
123
|
+
}
|
124
|
+
|
125
|
+
function isBlockScoped() {
|
126
|
+
return nodeIsBlockScoped(this.node);
|
127
|
+
}
|
128
|
+
|
129
|
+
function isVar() {
|
130
|
+
return nodeIsVar(this.node);
|
131
|
+
}
|
132
|
+
|
133
|
+
function isUser() {
|
134
|
+
return this.node && !!this.node.loc;
|
135
|
+
}
|
136
|
+
|
137
|
+
function isGenerated() {
|
138
|
+
return !this.isUser();
|
139
|
+
}
|
140
|
+
|
141
|
+
function isPure(constantsOnly) {
|
142
|
+
return this.scope.isPure(this.node, constantsOnly);
|
143
|
+
}
|
144
|
+
|
145
|
+
function isFlow() {
|
146
|
+
const {
|
147
|
+
node
|
148
|
+
} = this;
|
149
|
+
|
150
|
+
if (nodeIsFlow(node)) {
|
151
|
+
return true;
|
152
|
+
} else if (isImportDeclaration(node)) {
|
153
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
154
|
+
} else if (isExportDeclaration(node)) {
|
155
|
+
return node.exportKind === "type";
|
156
|
+
} else if (isImportSpecifier(node)) {
|
157
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
158
|
+
} else {
|
159
|
+
return false;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
function isRestProperty() {
|
164
|
+
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
|
165
|
+
}
|
166
|
+
|
167
|
+
function isSpreadProperty() {
|
168
|
+
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
|
169
|
+
}
|
170
|
+
|
171
|
+
function isForAwaitStatement() {
|
172
|
+
return isForStatement(this.node, {
|
173
|
+
await: true
|
174
|
+
});
|
175
|
+
}
|
176
|
+
|
177
|
+
function isExistentialTypeParam() {
|
178
|
+
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
|
179
|
+
}
|
180
|
+
|
181
|
+
function isNumericLiteralTypeAnnotation() {
|
182
|
+
throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");
|
183
|
+
}
|
@@ -4,227 +4,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.Var = exports.User = exports.Statement = exports.SpreadProperty = exports.Scope = exports.RestProperty = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = exports.Referenced = exports.Pure = exports.NumericLiteralTypeAnnotation = exports.Generated = exports.ForAwaitStatement = exports.Flow = exports.Expression = exports.ExistentialTypeParam = exports.BlockScoped = exports.BindingIdentifier = void 0;
|
7
|
-
|
8
|
-
var _t = require("@babel/types");
|
9
|
-
|
10
|
-
const {
|
11
|
-
isBinding,
|
12
|
-
isBlockScoped,
|
13
|
-
isExportDeclaration,
|
14
|
-
isExpression,
|
15
|
-
isFlow,
|
16
|
-
isForStatement,
|
17
|
-
isForXStatement,
|
18
|
-
isIdentifier,
|
19
|
-
isImportDeclaration,
|
20
|
-
isImportSpecifier,
|
21
|
-
isJSXIdentifier,
|
22
|
-
isJSXMemberExpression,
|
23
|
-
isMemberExpression,
|
24
|
-
isReferenced,
|
25
|
-
isScope,
|
26
|
-
isStatement,
|
27
|
-
isVar,
|
28
|
-
isVariableDeclaration,
|
29
|
-
react
|
30
|
-
} = _t;
|
31
|
-
const {
|
32
|
-
isCompatTag
|
33
|
-
} = react;
|
34
|
-
const ReferencedIdentifier = {
|
35
|
-
types: ["Identifier", "JSXIdentifier"],
|
36
|
-
|
37
|
-
checkPath(path, opts) {
|
38
|
-
const {
|
39
|
-
node,
|
40
|
-
parent
|
41
|
-
} = path;
|
42
|
-
|
43
|
-
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
44
|
-
if (isJSXIdentifier(node, opts)) {
|
45
|
-
if (isCompatTag(node.name)) return false;
|
46
|
-
} else {
|
47
|
-
return false;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
return isReferenced(node, parent, path.parentPath.parent);
|
52
|
-
}
|
53
|
-
|
54
|
-
};
|
7
|
+
const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
|
55
8
|
exports.ReferencedIdentifier = ReferencedIdentifier;
|
56
|
-
const ReferencedMemberExpression =
|
57
|
-
types: ["MemberExpression"],
|
58
|
-
|
59
|
-
checkPath({
|
60
|
-
node,
|
61
|
-
parent
|
62
|
-
}) {
|
63
|
-
return isMemberExpression(node) && isReferenced(node, parent);
|
64
|
-
}
|
65
|
-
|
66
|
-
};
|
9
|
+
const ReferencedMemberExpression = ["MemberExpression"];
|
67
10
|
exports.ReferencedMemberExpression = ReferencedMemberExpression;
|
68
|
-
const BindingIdentifier =
|
69
|
-
types: ["Identifier"],
|
70
|
-
|
71
|
-
checkPath(path) {
|
72
|
-
const {
|
73
|
-
node,
|
74
|
-
parent
|
75
|
-
} = path;
|
76
|
-
const grandparent = path.parentPath.parent;
|
77
|
-
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
78
|
-
}
|
79
|
-
|
80
|
-
};
|
11
|
+
const BindingIdentifier = ["Identifier"];
|
81
12
|
exports.BindingIdentifier = BindingIdentifier;
|
82
|
-
const Statement =
|
83
|
-
types: ["Statement"],
|
84
|
-
|
85
|
-
checkPath({
|
86
|
-
node,
|
87
|
-
parent
|
88
|
-
}) {
|
89
|
-
if (isStatement(node)) {
|
90
|
-
if (isVariableDeclaration(node)) {
|
91
|
-
if (isForXStatement(parent, {
|
92
|
-
left: node
|
93
|
-
})) return false;
|
94
|
-
if (isForStatement(parent, {
|
95
|
-
init: node
|
96
|
-
})) return false;
|
97
|
-
}
|
98
|
-
|
99
|
-
return true;
|
100
|
-
} else {
|
101
|
-
return false;
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
};
|
13
|
+
const Statement = ["Statement"];
|
106
14
|
exports.Statement = Statement;
|
107
|
-
const Expression =
|
108
|
-
types: ["Expression"],
|
109
|
-
|
110
|
-
checkPath(path) {
|
111
|
-
if (path.isIdentifier()) {
|
112
|
-
return path.isReferencedIdentifier();
|
113
|
-
} else {
|
114
|
-
return isExpression(path.node);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
};
|
15
|
+
const Expression = ["Expression"];
|
119
16
|
exports.Expression = Expression;
|
120
|
-
const Scope =
|
121
|
-
types: ["Scopable", "Pattern"],
|
122
|
-
|
123
|
-
checkPath(path) {
|
124
|
-
return isScope(path.node, path.parent);
|
125
|
-
}
|
126
|
-
|
127
|
-
};
|
17
|
+
const Scope = ["Scopable", "Pattern"];
|
128
18
|
exports.Scope = Scope;
|
129
|
-
const Referenced =
|
130
|
-
checkPath(path) {
|
131
|
-
return isReferenced(path.node, path.parent);
|
132
|
-
}
|
133
|
-
|
134
|
-
};
|
19
|
+
const Referenced = null;
|
135
20
|
exports.Referenced = Referenced;
|
136
|
-
const BlockScoped =
|
137
|
-
checkPath(path) {
|
138
|
-
return isBlockScoped(path.node);
|
139
|
-
}
|
140
|
-
|
141
|
-
};
|
21
|
+
const BlockScoped = null;
|
142
22
|
exports.BlockScoped = BlockScoped;
|
143
|
-
const Var =
|
144
|
-
types: ["VariableDeclaration"],
|
145
|
-
|
146
|
-
checkPath(path) {
|
147
|
-
return isVar(path.node);
|
148
|
-
}
|
149
|
-
|
150
|
-
};
|
23
|
+
const Var = ["VariableDeclaration"];
|
151
24
|
exports.Var = Var;
|
152
|
-
const User =
|
153
|
-
checkPath(path) {
|
154
|
-
return path.node && !!path.node.loc;
|
155
|
-
}
|
156
|
-
|
157
|
-
};
|
25
|
+
const User = null;
|
158
26
|
exports.User = User;
|
159
|
-
const Generated =
|
160
|
-
checkPath(path) {
|
161
|
-
return !path.isUser();
|
162
|
-
}
|
163
|
-
|
164
|
-
};
|
27
|
+
const Generated = null;
|
165
28
|
exports.Generated = Generated;
|
166
|
-
const Pure =
|
167
|
-
checkPath(path, constantsOnly) {
|
168
|
-
return path.scope.isPure(path.node, constantsOnly);
|
169
|
-
}
|
170
|
-
|
171
|
-
};
|
29
|
+
const Pure = null;
|
172
30
|
exports.Pure = Pure;
|
173
|
-
const Flow =
|
174
|
-
types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
|
175
|
-
|
176
|
-
checkPath({
|
177
|
-
node
|
178
|
-
}) {
|
179
|
-
if (isFlow(node)) {
|
180
|
-
return true;
|
181
|
-
} else if (isImportDeclaration(node)) {
|
182
|
-
return node.importKind === "type" || node.importKind === "typeof";
|
183
|
-
} else if (isExportDeclaration(node)) {
|
184
|
-
return node.exportKind === "type";
|
185
|
-
} else if (isImportSpecifier(node)) {
|
186
|
-
return node.importKind === "type" || node.importKind === "typeof";
|
187
|
-
} else {
|
188
|
-
return false;
|
189
|
-
}
|
190
|
-
}
|
191
|
-
|
192
|
-
};
|
31
|
+
const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
|
193
32
|
exports.Flow = Flow;
|
194
|
-
const RestProperty =
|
195
|
-
types: ["RestElement"],
|
196
|
-
|
197
|
-
checkPath(path) {
|
198
|
-
return path.parentPath && path.parentPath.isObjectPattern();
|
199
|
-
}
|
200
|
-
|
201
|
-
};
|
33
|
+
const RestProperty = ["RestElement"];
|
202
34
|
exports.RestProperty = RestProperty;
|
203
|
-
const SpreadProperty =
|
204
|
-
types: ["RestElement"],
|
205
|
-
|
206
|
-
checkPath(path) {
|
207
|
-
return path.parentPath && path.parentPath.isObjectExpression();
|
208
|
-
}
|
209
|
-
|
210
|
-
};
|
35
|
+
const SpreadProperty = ["RestElement"];
|
211
36
|
exports.SpreadProperty = SpreadProperty;
|
212
|
-
const ExistentialTypeParam =
|
213
|
-
types: ["ExistsTypeAnnotation"]
|
214
|
-
};
|
37
|
+
const ExistentialTypeParam = ["ExistsTypeAnnotation"];
|
215
38
|
exports.ExistentialTypeParam = ExistentialTypeParam;
|
216
|
-
const NumericLiteralTypeAnnotation =
|
217
|
-
types: ["NumberLiteralTypeAnnotation"]
|
218
|
-
};
|
39
|
+
const NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
|
219
40
|
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
|
220
|
-
const ForAwaitStatement =
|
221
|
-
types: ["ForOfStatement"],
|
222
|
-
|
223
|
-
checkPath({
|
224
|
-
node
|
225
|
-
}) {
|
226
|
-
return node.await === true;
|
227
|
-
}
|
228
|
-
|
229
|
-
};
|
41
|
+
const ForAwaitStatement = ["ForOfStatement"];
|
230
42
|
exports.ForAwaitStatement = ForAwaitStatement;
|
package/lib/types.js
CHANGED
package/lib/visitors.js
CHANGED
@@ -17,6 +17,10 @@ const {
|
|
17
17
|
TYPES
|
18
18
|
} = _t;
|
19
19
|
|
20
|
+
function isVirtualType(type) {
|
21
|
+
return type in virtualTypes;
|
22
|
+
}
|
23
|
+
|
20
24
|
function explode(visitor) {
|
21
25
|
if (visitor._exploded) return visitor;
|
22
26
|
visitor._exploded = true;
|
@@ -40,18 +44,18 @@ function explode(visitor) {
|
|
40
44
|
|
41
45
|
for (const nodeType of Object.keys(visitor)) {
|
42
46
|
if (shouldIgnoreKey(nodeType)) continue;
|
43
|
-
|
44
|
-
if (!wrapper) continue;
|
47
|
+
if (!isVirtualType(nodeType)) continue;
|
45
48
|
const fns = visitor[nodeType];
|
46
49
|
|
47
50
|
for (const type of Object.keys(fns)) {
|
48
|
-
fns[type] = wrapCheck(
|
51
|
+
fns[type] = wrapCheck(nodeType, fns[type]);
|
49
52
|
}
|
50
53
|
|
51
54
|
delete visitor[nodeType];
|
55
|
+
const types = virtualTypes[nodeType];
|
52
56
|
|
53
|
-
if (
|
54
|
-
for (const type of
|
57
|
+
if (types !== null) {
|
58
|
+
for (const type of types) {
|
55
59
|
if (visitor[type]) {
|
56
60
|
mergePair(visitor[type], fns);
|
57
61
|
} else {
|
@@ -155,7 +159,7 @@ function merge(visitors, states = [], wrapper) {
|
|
155
159
|
visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
|
156
160
|
}
|
157
161
|
|
158
|
-
const nodeVisitor = rootVisitor[type]
|
162
|
+
const nodeVisitor = rootVisitor[type] || (rootVisitor[type] = {});
|
159
163
|
mergePair(nodeVisitor, visitorType);
|
160
164
|
}
|
161
165
|
}
|
@@ -212,9 +216,9 @@ function ensureCallbackArrays(obj) {
|
|
212
216
|
if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
|
213
217
|
}
|
214
218
|
|
215
|
-
function wrapCheck(
|
219
|
+
function wrapCheck(nodeType, fn) {
|
216
220
|
const newFn = function (path) {
|
217
|
-
if (
|
221
|
+
if (path[`is${nodeType}`]()) {
|
218
222
|
return fn.apply(this, arguments);
|
219
223
|
}
|
220
224
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.18.
|
3
|
+
"version": "7.18.13",
|
4
4
|
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
|
5
5
|
"author": "The Babel Team (https://babel.dev/team)",
|
6
6
|
"homepage": "https://babel.dev/docs/en/next/babel-traverse",
|
@@ -17,13 +17,13 @@
|
|
17
17
|
"main": "./lib/index.js",
|
18
18
|
"dependencies": {
|
19
19
|
"@babel/code-frame": "^7.18.6",
|
20
|
-
"@babel/generator": "^7.18.
|
20
|
+
"@babel/generator": "^7.18.13",
|
21
21
|
"@babel/helper-environment-visitor": "^7.18.9",
|
22
22
|
"@babel/helper-function-name": "^7.18.9",
|
23
23
|
"@babel/helper-hoist-variables": "^7.18.6",
|
24
24
|
"@babel/helper-split-export-declaration": "^7.18.6",
|
25
|
-
"@babel/parser": "^7.18.
|
26
|
-
"@babel/types": "^7.18.
|
25
|
+
"@babel/parser": "^7.18.13",
|
26
|
+
"@babel/types": "^7.18.13",
|
27
27
|
"debug": "^4.1.0",
|
28
28
|
"globals": "^11.1.0"
|
29
29
|
},
|
@@ -1,46 +1,26 @@
|
|
1
1
|
import * as t from "@babel/types";
|
2
|
-
import * as virtualTypes from "../../lib/path/lib/virtual-types.js";
|
3
2
|
|
4
3
|
export default function generateValidators() {
|
5
4
|
let output = `/*
|
6
5
|
* This file is auto-generated! Do not modify it directly.
|
7
6
|
* To re-generate run 'make build'
|
8
7
|
*/
|
9
|
-
import * as t from "@babel/types";
|
10
|
-
import NodePath from "../index";
|
11
|
-
import type {
|
8
|
+
import type * as t from "@babel/types";
|
9
|
+
import type NodePath from "../index";
|
10
|
+
import type { VirtualTypeNodePathValidators } from "../lib/virtual-types-validator";
|
12
11
|
|
13
|
-
|
12
|
+
interface BaseNodePathValidators {
|
14
13
|
`;
|
15
14
|
|
16
15
|
for (const type of [...t.TYPES].sort()) {
|
17
16
|
output += `is${type}<T extends t.Node>(this: NodePath<T>, opts?: object): this is NodePath<T & t.${type}>;`;
|
18
17
|
}
|
19
18
|
|
20
|
-
for (const type of Object.keys(virtualTypes)) {
|
21
|
-
// TODO: Remove this check once we stop compiling to CJS
|
22
|
-
if (type === "default" || type === "__esModule") continue;
|
23
|
-
|
24
|
-
const { types } = virtualTypes[type];
|
25
|
-
if (type[0] === "_") continue;
|
26
|
-
if (t.NODE_FIELDS[type] || t.FLIPPED_ALIAS_KEYS[type]) {
|
27
|
-
output += `is${type}<T extends t.Node>(this: NodePath<T>, opts?: object): this is NodePath<T & t.${type}>;`;
|
28
|
-
} else if (types /* in VirtualTypeAliases */) {
|
29
|
-
output += `is${type}<T extends t.Node>(this: NodePath<T>, opts?: object): this is NodePath<T & VirtualTypeAliases["${type}"]>;`;
|
30
|
-
} else if (type === "Pure") {
|
31
|
-
output += `isPure(constantsOnly?: boolean): boolean;`;
|
32
|
-
} else {
|
33
|
-
// if it don't have types, then VirtualTypeAliases[type] is t.Node
|
34
|
-
// which TS marked as always true
|
35
|
-
// eg. if (path.isBlockScope()) return;
|
36
|
-
// path resolved to `never` here
|
37
|
-
// so we have to return boolean instead of this is NodePath<t.Node> here
|
38
|
-
output += `is${type}(opts?: object): boolean;`;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
19
|
output += `
|
43
20
|
}
|
21
|
+
|
22
|
+
export interface NodePathValidators
|
23
|
+
extends BaseNodePathValidators, VirtualTypeNodePathValidators {}
|
44
24
|
`;
|
45
25
|
|
46
26
|
return output;
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import * as virtualTypes from "../../lib/path/lib/virtual-types.js";
|
2
|
-
|
3
|
-
export default function generateValidators() {
|
4
|
-
let output = `/*
|
5
|
-
* This file is auto-generated! Do not modify it directly.
|
6
|
-
* To re-generate run 'make build'
|
7
|
-
*/
|
8
|
-
import * as t from "@babel/types";
|
9
|
-
|
10
|
-
export interface VirtualTypeAliases {
|
11
|
-
`;
|
12
|
-
|
13
|
-
for (const type of Object.keys(virtualTypes)) {
|
14
|
-
// TODO: Remove this check once we stop compiling to CJS
|
15
|
-
if (type === "default" || type === "__esModule") continue;
|
16
|
-
|
17
|
-
output += ` ${type}: ${(virtualTypes[type].types || ["Node"])
|
18
|
-
.map(t => `t.${t}`)
|
19
|
-
.join(" | ")};`;
|
20
|
-
}
|
21
|
-
|
22
|
-
output += `
|
23
|
-
}
|
24
|
-
`;
|
25
|
-
|
26
|
-
return output;
|
27
|
-
}
|