@babel/traverse 7.14.9 → 7.16.3
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/context.js +6 -2
- package/lib/index.js +18 -12
- package/lib/path/ancestry.js +11 -7
- package/lib/path/comments.js +9 -4
- package/lib/path/context.js +26 -14
- package/lib/path/conversion.js +98 -46
- package/lib/path/evaluation.js +1 -1
- package/lib/path/family.js +61 -38
- package/lib/path/index.js +9 -3
- package/lib/path/inference/index.js +39 -21
- package/lib/path/inference/inferer-reference.js +28 -17
- package/lib/path/inference/inferers.js +89 -65
- package/lib/path/introspection.js +37 -25
- package/lib/path/lib/hoister.js +17 -7
- package/lib/path/lib/virtual-types.js +47 -23
- package/lib/path/modification.js +25 -14
- package/lib/path/removal.js +4 -4
- package/lib/path/replacement.js +50 -27
- package/lib/scope/index.js +101 -55
- package/lib/scope/lib/renamer.js +16 -8
- package/lib/types.js +0 -2
- package/lib/visitors.js +11 -5
- package/package.json +9 -9
@@ -3,40 +3,64 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
7
|
-
exports.TypeCastExpression = TypeCastExpression;
|
8
|
-
exports.NewExpression = NewExpression;
|
9
|
-
exports.TemplateLiteral = TemplateLiteral;
|
10
|
-
exports.UnaryExpression = UnaryExpression;
|
11
|
-
exports.BinaryExpression = BinaryExpression;
|
12
|
-
exports.LogicalExpression = LogicalExpression;
|
13
|
-
exports.ConditionalExpression = ConditionalExpression;
|
14
|
-
exports.SequenceExpression = SequenceExpression;
|
15
|
-
exports.ParenthesizedExpression = ParenthesizedExpression;
|
6
|
+
exports.ArrayExpression = ArrayExpression;
|
16
7
|
exports.AssignmentExpression = AssignmentExpression;
|
17
|
-
exports.
|
18
|
-
exports.StringLiteral = StringLiteral;
|
19
|
-
exports.NumericLiteral = NumericLiteral;
|
8
|
+
exports.BinaryExpression = BinaryExpression;
|
20
9
|
exports.BooleanLiteral = BooleanLiteral;
|
21
|
-
exports.NullLiteral = NullLiteral;
|
22
|
-
exports.RegExpLiteral = RegExpLiteral;
|
23
|
-
exports.ObjectExpression = ObjectExpression;
|
24
|
-
exports.ArrayExpression = ArrayExpression;
|
25
|
-
exports.RestElement = RestElement;
|
26
|
-
exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
|
27
10
|
exports.CallExpression = CallExpression;
|
28
|
-
exports.
|
11
|
+
exports.ConditionalExpression = ConditionalExpression;
|
12
|
+
exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
|
29
13
|
Object.defineProperty(exports, "Identifier", {
|
30
14
|
enumerable: true,
|
31
15
|
get: function () {
|
32
16
|
return _infererReference.default;
|
33
17
|
}
|
34
18
|
});
|
19
|
+
exports.LogicalExpression = LogicalExpression;
|
20
|
+
exports.NewExpression = NewExpression;
|
21
|
+
exports.NullLiteral = NullLiteral;
|
22
|
+
exports.NumericLiteral = NumericLiteral;
|
23
|
+
exports.ObjectExpression = ObjectExpression;
|
24
|
+
exports.ParenthesizedExpression = ParenthesizedExpression;
|
25
|
+
exports.RegExpLiteral = RegExpLiteral;
|
26
|
+
exports.RestElement = RestElement;
|
27
|
+
exports.SequenceExpression = SequenceExpression;
|
28
|
+
exports.StringLiteral = StringLiteral;
|
29
|
+
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
30
|
+
exports.TemplateLiteral = TemplateLiteral;
|
31
|
+
exports.TypeCastExpression = TypeCastExpression;
|
32
|
+
exports.UnaryExpression = UnaryExpression;
|
33
|
+
exports.UpdateExpression = UpdateExpression;
|
34
|
+
exports.VariableDeclarator = VariableDeclarator;
|
35
35
|
|
36
|
-
var
|
36
|
+
var _t = require("@babel/types");
|
37
37
|
|
38
38
|
var _infererReference = require("./inferer-reference");
|
39
39
|
|
40
|
+
const {
|
41
|
+
BOOLEAN_BINARY_OPERATORS,
|
42
|
+
BOOLEAN_UNARY_OPERATORS,
|
43
|
+
NUMBER_BINARY_OPERATORS,
|
44
|
+
NUMBER_UNARY_OPERATORS,
|
45
|
+
STRING_UNARY_OPERATORS,
|
46
|
+
anyTypeAnnotation,
|
47
|
+
arrayTypeAnnotation,
|
48
|
+
booleanTypeAnnotation,
|
49
|
+
buildMatchMemberExpression,
|
50
|
+
createFlowUnionType,
|
51
|
+
createTSUnionType,
|
52
|
+
createUnionTypeAnnotation,
|
53
|
+
genericTypeAnnotation,
|
54
|
+
identifier,
|
55
|
+
isTSTypeAnnotation,
|
56
|
+
nullLiteralTypeAnnotation,
|
57
|
+
numberTypeAnnotation,
|
58
|
+
stringTypeAnnotation,
|
59
|
+
tupleTypeAnnotation,
|
60
|
+
unionTypeAnnotation,
|
61
|
+
voidTypeAnnotation
|
62
|
+
} = _t;
|
63
|
+
|
40
64
|
function VariableDeclarator() {
|
41
65
|
var _type;
|
42
66
|
|
@@ -64,75 +88,75 @@ TypeCastExpression.validParent = true;
|
|
64
88
|
|
65
89
|
function NewExpression(node) {
|
66
90
|
if (this.get("callee").isIdentifier()) {
|
67
|
-
return
|
91
|
+
return genericTypeAnnotation(node.callee);
|
68
92
|
}
|
69
93
|
}
|
70
94
|
|
71
95
|
function TemplateLiteral() {
|
72
|
-
return
|
96
|
+
return stringTypeAnnotation();
|
73
97
|
}
|
74
98
|
|
75
99
|
function UnaryExpression(node) {
|
76
100
|
const operator = node.operator;
|
77
101
|
|
78
102
|
if (operator === "void") {
|
79
|
-
return
|
80
|
-
} else if (
|
81
|
-
return
|
82
|
-
} else if (
|
83
|
-
return
|
84
|
-
} else if (
|
85
|
-
return
|
103
|
+
return voidTypeAnnotation();
|
104
|
+
} else if (NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
105
|
+
return numberTypeAnnotation();
|
106
|
+
} else if (STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
107
|
+
return stringTypeAnnotation();
|
108
|
+
} else if (BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
109
|
+
return booleanTypeAnnotation();
|
86
110
|
}
|
87
111
|
}
|
88
112
|
|
89
113
|
function BinaryExpression(node) {
|
90
114
|
const operator = node.operator;
|
91
115
|
|
92
|
-
if (
|
93
|
-
return
|
94
|
-
} else if (
|
95
|
-
return
|
116
|
+
if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
117
|
+
return numberTypeAnnotation();
|
118
|
+
} else if (BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
119
|
+
return booleanTypeAnnotation();
|
96
120
|
} else if (operator === "+") {
|
97
121
|
const right = this.get("right");
|
98
122
|
const left = this.get("left");
|
99
123
|
|
100
124
|
if (left.isBaseType("number") && right.isBaseType("number")) {
|
101
|
-
return
|
125
|
+
return numberTypeAnnotation();
|
102
126
|
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
103
|
-
return
|
127
|
+
return stringTypeAnnotation();
|
104
128
|
}
|
105
129
|
|
106
|
-
return
|
130
|
+
return unionTypeAnnotation([stringTypeAnnotation(), numberTypeAnnotation()]);
|
107
131
|
}
|
108
132
|
}
|
109
133
|
|
110
134
|
function LogicalExpression() {
|
111
135
|
const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
|
112
136
|
|
113
|
-
if (
|
114
|
-
return
|
137
|
+
if (isTSTypeAnnotation(argumentTypes[0]) && createTSUnionType) {
|
138
|
+
return createTSUnionType(argumentTypes);
|
115
139
|
}
|
116
140
|
|
117
|
-
if (
|
118
|
-
return
|
141
|
+
if (createFlowUnionType) {
|
142
|
+
return createFlowUnionType(argumentTypes);
|
119
143
|
}
|
120
144
|
|
121
|
-
return
|
145
|
+
return createUnionTypeAnnotation(argumentTypes);
|
122
146
|
}
|
123
147
|
|
124
148
|
function ConditionalExpression() {
|
125
149
|
const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
|
126
150
|
|
127
|
-
if (
|
128
|
-
return
|
151
|
+
if (isTSTypeAnnotation(argumentTypes[0]) && createTSUnionType) {
|
152
|
+
return createTSUnionType(argumentTypes);
|
129
153
|
}
|
130
154
|
|
131
|
-
if (
|
132
|
-
return
|
155
|
+
if (createFlowUnionType) {
|
156
|
+
return createFlowUnionType(argumentTypes);
|
133
157
|
}
|
134
158
|
|
135
|
-
return
|
159
|
+
return createUnionTypeAnnotation(argumentTypes);
|
136
160
|
}
|
137
161
|
|
138
162
|
function SequenceExpression() {
|
@@ -151,36 +175,36 @@ function UpdateExpression(node) {
|
|
151
175
|
const operator = node.operator;
|
152
176
|
|
153
177
|
if (operator === "++" || operator === "--") {
|
154
|
-
return
|
178
|
+
return numberTypeAnnotation();
|
155
179
|
}
|
156
180
|
}
|
157
181
|
|
158
182
|
function StringLiteral() {
|
159
|
-
return
|
183
|
+
return stringTypeAnnotation();
|
160
184
|
}
|
161
185
|
|
162
186
|
function NumericLiteral() {
|
163
|
-
return
|
187
|
+
return numberTypeAnnotation();
|
164
188
|
}
|
165
189
|
|
166
190
|
function BooleanLiteral() {
|
167
|
-
return
|
191
|
+
return booleanTypeAnnotation();
|
168
192
|
}
|
169
193
|
|
170
194
|
function NullLiteral() {
|
171
|
-
return
|
195
|
+
return nullLiteralTypeAnnotation();
|
172
196
|
}
|
173
197
|
|
174
198
|
function RegExpLiteral() {
|
175
|
-
return
|
199
|
+
return genericTypeAnnotation(identifier("RegExp"));
|
176
200
|
}
|
177
201
|
|
178
202
|
function ObjectExpression() {
|
179
|
-
return
|
203
|
+
return genericTypeAnnotation(identifier("Object"));
|
180
204
|
}
|
181
205
|
|
182
206
|
function ArrayExpression() {
|
183
|
-
return
|
207
|
+
return genericTypeAnnotation(identifier("Array"));
|
184
208
|
}
|
185
209
|
|
186
210
|
function RestElement() {
|
@@ -190,13 +214,13 @@ function RestElement() {
|
|
190
214
|
RestElement.validParent = true;
|
191
215
|
|
192
216
|
function Func() {
|
193
|
-
return
|
217
|
+
return genericTypeAnnotation(identifier("Function"));
|
194
218
|
}
|
195
219
|
|
196
|
-
const isArrayFrom =
|
197
|
-
const isObjectKeys =
|
198
|
-
const isObjectValues =
|
199
|
-
const isObjectEntries =
|
220
|
+
const isArrayFrom = buildMatchMemberExpression("Array.from");
|
221
|
+
const isObjectKeys = buildMatchMemberExpression("Object.keys");
|
222
|
+
const isObjectValues = buildMatchMemberExpression("Object.values");
|
223
|
+
const isObjectEntries = buildMatchMemberExpression("Object.entries");
|
200
224
|
|
201
225
|
function CallExpression() {
|
202
226
|
const {
|
@@ -204,11 +228,11 @@ function CallExpression() {
|
|
204
228
|
} = this.node;
|
205
229
|
|
206
230
|
if (isObjectKeys(callee)) {
|
207
|
-
return
|
231
|
+
return arrayTypeAnnotation(stringTypeAnnotation());
|
208
232
|
} else if (isArrayFrom(callee) || isObjectValues(callee)) {
|
209
|
-
return
|
233
|
+
return arrayTypeAnnotation(anyTypeAnnotation());
|
210
234
|
} else if (isObjectEntries(callee)) {
|
211
|
-
return
|
235
|
+
return arrayTypeAnnotation(tupleTypeAnnotation([stringTypeAnnotation(), anyTypeAnnotation()]));
|
212
236
|
}
|
213
237
|
|
214
238
|
return resolveCall(this.get("callee"));
|
@@ -224,9 +248,9 @@ function resolveCall(callee) {
|
|
224
248
|
if (callee.isFunction()) {
|
225
249
|
if (callee.is("async")) {
|
226
250
|
if (callee.is("generator")) {
|
227
|
-
return
|
251
|
+
return genericTypeAnnotation(identifier("AsyncIterator"));
|
228
252
|
} else {
|
229
|
-
return
|
253
|
+
return genericTypeAnnotation(identifier("Promise"));
|
230
254
|
}
|
231
255
|
} else {
|
232
256
|
if (callee.node.returnType) {
|
@@ -3,31 +3,43 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
7
|
-
exports.
|
8
|
-
exports.
|
9
|
-
exports.isnt = isnt;
|
10
|
-
exports.equals = equals;
|
11
|
-
exports.isNodeType = isNodeType;
|
6
|
+
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
|
7
|
+
exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
|
8
|
+
exports._resolve = _resolve;
|
12
9
|
exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
|
13
10
|
exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
|
11
|
+
exports.equals = equals;
|
12
|
+
exports.getSource = getSource;
|
13
|
+
exports.has = has;
|
14
|
+
exports.is = void 0;
|
14
15
|
exports.isCompletionRecord = isCompletionRecord;
|
16
|
+
exports.isConstantExpression = isConstantExpression;
|
17
|
+
exports.isInStrictMode = isInStrictMode;
|
18
|
+
exports.isNodeType = isNodeType;
|
15
19
|
exports.isStatementOrBlock = isStatementOrBlock;
|
20
|
+
exports.isStatic = isStatic;
|
21
|
+
exports.isnt = isnt;
|
22
|
+
exports.matchesPattern = matchesPattern;
|
16
23
|
exports.referencesImport = referencesImport;
|
17
|
-
exports.getSource = getSource;
|
18
|
-
exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
|
19
|
-
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
|
20
|
-
exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
|
21
24
|
exports.resolve = resolve;
|
22
|
-
exports.
|
23
|
-
|
24
|
-
|
25
|
-
exports.is = void 0;
|
25
|
+
exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
|
26
|
+
|
27
|
+
var _t = require("@babel/types");
|
26
28
|
|
27
|
-
|
29
|
+
const {
|
30
|
+
STATEMENT_OR_BLOCK_KEYS,
|
31
|
+
VISITOR_KEYS,
|
32
|
+
isBlockStatement,
|
33
|
+
isExpression,
|
34
|
+
isIdentifier,
|
35
|
+
isLiteral,
|
36
|
+
isStringLiteral,
|
37
|
+
isType,
|
38
|
+
matchesPattern: _matchesPattern
|
39
|
+
} = _t;
|
28
40
|
|
29
41
|
function matchesPattern(pattern, allowPartial) {
|
30
|
-
return
|
42
|
+
return _matchesPattern(this.node, pattern, allowPartial);
|
31
43
|
}
|
32
44
|
|
33
45
|
function has(key) {
|
@@ -56,7 +68,7 @@ function equals(key, value) {
|
|
56
68
|
}
|
57
69
|
|
58
70
|
function isNodeType(type) {
|
59
|
-
return
|
71
|
+
return isType(this.type, type);
|
60
72
|
}
|
61
73
|
|
62
74
|
function canHaveVariableDeclarationOrExpression() {
|
@@ -69,9 +81,9 @@ function canSwapBetweenExpressionAndStatement(replacement) {
|
|
69
81
|
}
|
70
82
|
|
71
83
|
if (this.isExpression()) {
|
72
|
-
return
|
84
|
+
return isBlockStatement(replacement);
|
73
85
|
} else if (this.isBlockStatement()) {
|
74
|
-
return
|
86
|
+
return isExpression(replacement);
|
75
87
|
}
|
76
88
|
|
77
89
|
return false;
|
@@ -99,16 +111,16 @@ function isCompletionRecord(allowInsideFunction) {
|
|
99
111
|
}
|
100
112
|
|
101
113
|
function isStatementOrBlock() {
|
102
|
-
if (this.parentPath.isLabeledStatement() ||
|
114
|
+
if (this.parentPath.isLabeledStatement() || isBlockStatement(this.container)) {
|
103
115
|
return false;
|
104
116
|
} else {
|
105
|
-
return
|
117
|
+
return STATEMENT_OR_BLOCK_KEYS.includes(this.key);
|
106
118
|
}
|
107
119
|
}
|
108
120
|
|
109
121
|
function referencesImport(moduleSource, importName) {
|
110
122
|
if (!this.isReferencedIdentifier()) {
|
111
|
-
if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ?
|
123
|
+
if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
|
112
124
|
value: importName
|
113
125
|
}) : this.node.property.name === importName)) {
|
114
126
|
const object = this.get("object");
|
@@ -138,7 +150,7 @@ function referencesImport(moduleSource, importName) {
|
|
138
150
|
return true;
|
139
151
|
}
|
140
152
|
|
141
|
-
if (path.isImportSpecifier() &&
|
153
|
+
if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
|
142
154
|
name: importName
|
143
155
|
})) {
|
144
156
|
return true;
|
@@ -266,7 +278,7 @@ function _guessExecutionStatusRelativeTo(target) {
|
|
266
278
|
return divergence.target.key > divergence.this.key ? "before" : "after";
|
267
279
|
}
|
268
280
|
|
269
|
-
const keys =
|
281
|
+
const keys = VISITOR_KEYS[commonPath.type];
|
270
282
|
const keyPosition = {
|
271
283
|
this: keys.indexOf(divergence.this.parentKey),
|
272
284
|
target: keys.indexOf(divergence.target.parentKey)
|
@@ -339,7 +351,7 @@ function _resolve(dangerous, resolved) {
|
|
339
351
|
return this.get("expression").resolve(dangerous, resolved);
|
340
352
|
} else if (dangerous && this.isMemberExpression()) {
|
341
353
|
const targetKey = this.toComputedKey();
|
342
|
-
if (!
|
354
|
+
if (!isLiteral(targetKey)) return;
|
343
355
|
const targetName = targetKey.value;
|
344
356
|
const target = this.get("object").resolve(dangerous, resolved);
|
345
357
|
|
package/lib/path/lib/hoister.js
CHANGED
@@ -5,11 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
var
|
9
|
-
|
8
|
+
var _t = require("@babel/types");
|
9
|
+
|
10
|
+
var _t2 = _t;
|
11
|
+
const {
|
12
|
+
react
|
13
|
+
} = _t;
|
14
|
+
const {
|
15
|
+
cloneNode,
|
16
|
+
jsxExpressionContainer,
|
17
|
+
variableDeclaration,
|
18
|
+
variableDeclarator
|
19
|
+
} = _t2;
|
10
20
|
const referenceVisitor = {
|
11
21
|
ReferencedIdentifier(path, state) {
|
12
|
-
if (path.isJSXIdentifier() &&
|
22
|
+
if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
13
23
|
return;
|
14
24
|
}
|
15
25
|
|
@@ -178,16 +188,16 @@ class PathHoister {
|
|
178
188
|
if (!attachTo) return;
|
179
189
|
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
180
190
|
let uid = attachTo.scope.generateUidIdentifier("ref");
|
181
|
-
const declarator =
|
191
|
+
const declarator = variableDeclarator(uid, this.path.node);
|
182
192
|
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
183
|
-
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator :
|
193
|
+
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : variableDeclaration("var", [declarator])]);
|
184
194
|
const parent = this.path.parentPath;
|
185
195
|
|
186
196
|
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
187
|
-
uid =
|
197
|
+
uid = jsxExpressionContainer(uid);
|
188
198
|
}
|
189
199
|
|
190
|
-
this.path.replaceWith(
|
200
|
+
this.path.replaceWith(cloneNode(uid));
|
191
201
|
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
192
202
|
}
|
193
203
|
|
@@ -3,10 +3,34 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
7
|
-
|
8
|
-
var
|
9
|
-
|
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;
|
10
34
|
const ReferencedIdentifier = {
|
11
35
|
types: ["Identifier", "JSXIdentifier"],
|
12
36
|
|
@@ -16,15 +40,15 @@ const ReferencedIdentifier = {
|
|
16
40
|
parent
|
17
41
|
} = path;
|
18
42
|
|
19
|
-
if (!
|
20
|
-
if (
|
21
|
-
if (
|
43
|
+
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
44
|
+
if (isJSXIdentifier(node, opts)) {
|
45
|
+
if (isCompatTag(node.name)) return false;
|
22
46
|
} else {
|
23
47
|
return false;
|
24
48
|
}
|
25
49
|
}
|
26
50
|
|
27
|
-
return
|
51
|
+
return isReferenced(node, parent, path.parentPath.parent);
|
28
52
|
}
|
29
53
|
|
30
54
|
};
|
@@ -36,7 +60,7 @@ const ReferencedMemberExpression = {
|
|
36
60
|
node,
|
37
61
|
parent
|
38
62
|
}) {
|
39
|
-
return
|
63
|
+
return isMemberExpression(node) && isReferenced(node, parent);
|
40
64
|
}
|
41
65
|
|
42
66
|
};
|
@@ -50,7 +74,7 @@ const BindingIdentifier = {
|
|
50
74
|
parent
|
51
75
|
} = path;
|
52
76
|
const grandparent = path.parentPath.parent;
|
53
|
-
return
|
77
|
+
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
54
78
|
}
|
55
79
|
|
56
80
|
};
|
@@ -62,12 +86,12 @@ const Statement = {
|
|
62
86
|
node,
|
63
87
|
parent
|
64
88
|
}) {
|
65
|
-
if (
|
66
|
-
if (
|
67
|
-
if (
|
89
|
+
if (isStatement(node)) {
|
90
|
+
if (isVariableDeclaration(node)) {
|
91
|
+
if (isForXStatement(parent, {
|
68
92
|
left: node
|
69
93
|
})) return false;
|
70
|
-
if (
|
94
|
+
if (isForStatement(parent, {
|
71
95
|
init: node
|
72
96
|
})) return false;
|
73
97
|
}
|
@@ -87,7 +111,7 @@ const Expression = {
|
|
87
111
|
if (path.isIdentifier()) {
|
88
112
|
return path.isReferencedIdentifier();
|
89
113
|
} else {
|
90
|
-
return
|
114
|
+
return isExpression(path.node);
|
91
115
|
}
|
92
116
|
}
|
93
117
|
|
@@ -97,21 +121,21 @@ const Scope = {
|
|
97
121
|
types: ["Scopable", "Pattern"],
|
98
122
|
|
99
123
|
checkPath(path) {
|
100
|
-
return
|
124
|
+
return isScope(path.node, path.parent);
|
101
125
|
}
|
102
126
|
|
103
127
|
};
|
104
128
|
exports.Scope = Scope;
|
105
129
|
const Referenced = {
|
106
130
|
checkPath(path) {
|
107
|
-
return
|
131
|
+
return isReferenced(path.node, path.parent);
|
108
132
|
}
|
109
133
|
|
110
134
|
};
|
111
135
|
exports.Referenced = Referenced;
|
112
136
|
const BlockScoped = {
|
113
137
|
checkPath(path) {
|
114
|
-
return
|
138
|
+
return isBlockScoped(path.node);
|
115
139
|
}
|
116
140
|
|
117
141
|
};
|
@@ -120,7 +144,7 @@ const Var = {
|
|
120
144
|
types: ["VariableDeclaration"],
|
121
145
|
|
122
146
|
checkPath(path) {
|
123
|
-
return
|
147
|
+
return isVar(path.node);
|
124
148
|
}
|
125
149
|
|
126
150
|
};
|
@@ -152,13 +176,13 @@ const Flow = {
|
|
152
176
|
checkPath({
|
153
177
|
node
|
154
178
|
}) {
|
155
|
-
if (
|
179
|
+
if (isFlow(node)) {
|
156
180
|
return true;
|
157
|
-
} else if (
|
181
|
+
} else if (isImportDeclaration(node)) {
|
158
182
|
return node.importKind === "type" || node.importKind === "typeof";
|
159
|
-
} else if (
|
183
|
+
} else if (isExportDeclaration(node)) {
|
160
184
|
return node.exportKind === "type";
|
161
|
-
} else if (
|
185
|
+
} else if (isImportSpecifier(node)) {
|
162
186
|
return node.importKind === "type" || node.importKind === "typeof";
|
163
187
|
} else {
|
164
188
|
return false;
|