@babel/traverse 7.14.7 → 7.15.4
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 +12 -6
- package/lib/path/ancestry.js +6 -2
- package/lib/path/comments.js +8 -3
- package/lib/path/conversion.js +77 -31
- package/lib/path/family.js +59 -29
- package/lib/path/index.js +8 -2
- package/lib/path/inference/index.js +36 -18
- package/lib/path/inference/inferer-reference.js +28 -17
- package/lib/path/inference/inferers.js +69 -45
- package/lib/path/introspection.js +23 -11
- package/lib/path/lib/hoister.js +17 -7
- package/lib/path/lib/virtual-types.js +45 -21
- package/lib/path/modification.js +19 -8
- package/lib/path/replacement.js +47 -24
- package/lib/scope/index.js +103 -51
- package/lib/scope/lib/renamer.js +16 -8
- package/lib/types.js +0 -2
- package/lib/visitors.js +10 -4
- package/package.json +7 -7
- package/scripts/generators/validators.js +9 -0
@@ -12,12 +12,30 @@ exports.isGenericType = isGenericType;
|
|
12
12
|
|
13
13
|
var inferers = require("./inferers");
|
14
14
|
|
15
|
-
var
|
15
|
+
var _t = require("@babel/types");
|
16
|
+
|
17
|
+
const {
|
18
|
+
anyTypeAnnotation,
|
19
|
+
isAnyTypeAnnotation,
|
20
|
+
isBooleanTypeAnnotation,
|
21
|
+
isEmptyTypeAnnotation,
|
22
|
+
isFlowBaseAnnotation,
|
23
|
+
isGenericTypeAnnotation,
|
24
|
+
isIdentifier,
|
25
|
+
isMixedTypeAnnotation,
|
26
|
+
isNumberTypeAnnotation,
|
27
|
+
isStringTypeAnnotation,
|
28
|
+
isTypeAnnotation,
|
29
|
+
isUnionTypeAnnotation,
|
30
|
+
isVoidTypeAnnotation,
|
31
|
+
stringTypeAnnotation,
|
32
|
+
voidTypeAnnotation
|
33
|
+
} = _t;
|
16
34
|
|
17
35
|
function getTypeAnnotation() {
|
18
36
|
if (this.typeAnnotation) return this.typeAnnotation;
|
19
|
-
let type = this._getTypeAnnotation() ||
|
20
|
-
if (
|
37
|
+
let type = this._getTypeAnnotation() || anyTypeAnnotation();
|
38
|
+
if (isTypeAnnotation(type)) type = type.typeAnnotation;
|
21
39
|
return this.typeAnnotation = type;
|
22
40
|
}
|
23
41
|
|
@@ -32,14 +50,14 @@ function _getTypeAnnotation() {
|
|
32
50
|
const declarParent = declar.parentPath;
|
33
51
|
|
34
52
|
if (declar.key === "left" && declarParent.isForInStatement()) {
|
35
|
-
return
|
53
|
+
return stringTypeAnnotation();
|
36
54
|
}
|
37
55
|
|
38
56
|
if (declar.key === "left" && declarParent.isForOfStatement()) {
|
39
|
-
return
|
57
|
+
return anyTypeAnnotation();
|
40
58
|
}
|
41
59
|
|
42
|
-
return
|
60
|
+
return voidTypeAnnotation();
|
43
61
|
} else {
|
44
62
|
return;
|
45
63
|
}
|
@@ -80,19 +98,19 @@ function isBaseType(baseName, soft) {
|
|
80
98
|
|
81
99
|
function _isBaseType(baseName, type, soft) {
|
82
100
|
if (baseName === "string") {
|
83
|
-
return
|
101
|
+
return isStringTypeAnnotation(type);
|
84
102
|
} else if (baseName === "number") {
|
85
|
-
return
|
103
|
+
return isNumberTypeAnnotation(type);
|
86
104
|
} else if (baseName === "boolean") {
|
87
|
-
return
|
105
|
+
return isBooleanTypeAnnotation(type);
|
88
106
|
} else if (baseName === "any") {
|
89
|
-
return
|
107
|
+
return isAnyTypeAnnotation(type);
|
90
108
|
} else if (baseName === "mixed") {
|
91
|
-
return
|
109
|
+
return isMixedTypeAnnotation(type);
|
92
110
|
} else if (baseName === "empty") {
|
93
|
-
return
|
111
|
+
return isEmptyTypeAnnotation(type);
|
94
112
|
} else if (baseName === "void") {
|
95
|
-
return
|
113
|
+
return isVoidTypeAnnotation(type);
|
96
114
|
} else {
|
97
115
|
if (soft) {
|
98
116
|
return false;
|
@@ -104,11 +122,11 @@ function _isBaseType(baseName, type, soft) {
|
|
104
122
|
|
105
123
|
function couldBeBaseType(name) {
|
106
124
|
const type = this.getTypeAnnotation();
|
107
|
-
if (
|
125
|
+
if (isAnyTypeAnnotation(type)) return true;
|
108
126
|
|
109
|
-
if (
|
127
|
+
if (isUnionTypeAnnotation(type)) {
|
110
128
|
for (const type2 of type.types) {
|
111
|
-
if (
|
129
|
+
if (isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
|
112
130
|
return true;
|
113
131
|
}
|
114
132
|
}
|
@@ -123,7 +141,7 @@ function baseTypeStrictlyMatches(rightArg) {
|
|
123
141
|
const left = this.getTypeAnnotation();
|
124
142
|
const right = rightArg.getTypeAnnotation();
|
125
143
|
|
126
|
-
if (!
|
144
|
+
if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) {
|
127
145
|
return right.type === left.type;
|
128
146
|
}
|
129
147
|
|
@@ -132,7 +150,7 @@ function baseTypeStrictlyMatches(rightArg) {
|
|
132
150
|
|
133
151
|
function isGenericType(genericName) {
|
134
152
|
const type = this.getTypeAnnotation();
|
135
|
-
return
|
153
|
+
return isGenericTypeAnnotation(type) && isIdentifier(type.id, {
|
136
154
|
name: genericName
|
137
155
|
});
|
138
156
|
}
|
@@ -5,7 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = _default;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _t = require("@babel/types");
|
9
|
+
|
10
|
+
const {
|
11
|
+
BOOLEAN_NUMBER_BINARY_OPERATORS,
|
12
|
+
createFlowUnionType,
|
13
|
+
createTSUnionType,
|
14
|
+
createTypeAnnotationBasedOnTypeof,
|
15
|
+
createUnionTypeAnnotation,
|
16
|
+
isTSTypeAnnotation,
|
17
|
+
numberTypeAnnotation,
|
18
|
+
voidTypeAnnotation
|
19
|
+
} = _t;
|
9
20
|
|
10
21
|
function _default(node) {
|
11
22
|
if (!this.isReferenced()) return;
|
@@ -20,9 +31,9 @@ function _default(node) {
|
|
20
31
|
}
|
21
32
|
|
22
33
|
if (node.name === "undefined") {
|
23
|
-
return
|
34
|
+
return voidTypeAnnotation();
|
24
35
|
} else if (node.name === "NaN" || node.name === "Infinity") {
|
25
|
-
return
|
36
|
+
return numberTypeAnnotation();
|
26
37
|
} else if (node.name === "arguments") {}
|
27
38
|
}
|
28
39
|
|
@@ -39,7 +50,7 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
|
39
50
|
}
|
40
51
|
|
41
52
|
if (constantViolations.length) {
|
42
|
-
constantViolations
|
53
|
+
constantViolations.push(...functionConstantViolations);
|
43
54
|
|
44
55
|
for (const violation of constantViolations) {
|
45
56
|
types.push(violation.getTypeAnnotation());
|
@@ -50,15 +61,15 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
|
50
61
|
return;
|
51
62
|
}
|
52
63
|
|
53
|
-
if (
|
54
|
-
return
|
64
|
+
if (isTSTypeAnnotation(types[0]) && createTSUnionType) {
|
65
|
+
return createTSUnionType(types);
|
55
66
|
}
|
56
67
|
|
57
|
-
if (
|
58
|
-
return
|
68
|
+
if (createFlowUnionType) {
|
69
|
+
return createFlowUnionType(types);
|
59
70
|
}
|
60
71
|
|
61
|
-
return
|
72
|
+
return createUnionTypeAnnotation(types);
|
62
73
|
}
|
63
74
|
|
64
75
|
function getConstantViolationsBefore(binding, path, functions) {
|
@@ -95,8 +106,8 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
95
106
|
return target.getTypeAnnotation();
|
96
107
|
}
|
97
108
|
|
98
|
-
if (
|
99
|
-
return
|
109
|
+
if (BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
110
|
+
return numberTypeAnnotation();
|
100
111
|
}
|
101
112
|
|
102
113
|
return;
|
@@ -126,7 +137,7 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
126
137
|
if (!typePath.isLiteral()) return;
|
127
138
|
const typeValue = typePath.node.value;
|
128
139
|
if (typeof typeValue !== "string") return;
|
129
|
-
return
|
140
|
+
return createTypeAnnotationBasedOnTypeof(typeValue);
|
130
141
|
}
|
131
142
|
|
132
143
|
function getParentConditionalPath(binding, path, name) {
|
@@ -171,22 +182,22 @@ function getConditionalAnnotation(binding, path, name) {
|
|
171
182
|
}
|
172
183
|
|
173
184
|
if (types.length) {
|
174
|
-
if (
|
185
|
+
if (isTSTypeAnnotation(types[0]) && createTSUnionType) {
|
175
186
|
return {
|
176
|
-
typeAnnotation:
|
187
|
+
typeAnnotation: createTSUnionType(types),
|
177
188
|
ifStatement
|
178
189
|
};
|
179
190
|
}
|
180
191
|
|
181
|
-
if (
|
192
|
+
if (createFlowUnionType) {
|
182
193
|
return {
|
183
|
-
typeAnnotation:
|
194
|
+
typeAnnotation: createFlowUnionType(types),
|
184
195
|
ifStatement
|
185
196
|
};
|
186
197
|
}
|
187
198
|
|
188
199
|
return {
|
189
|
-
typeAnnotation:
|
200
|
+
typeAnnotation: createUnionTypeAnnotation(types),
|
190
201
|
ifStatement
|
191
202
|
};
|
192
203
|
}
|
@@ -33,10 +33,34 @@ Object.defineProperty(exports, "Identifier", {
|
|
33
33
|
}
|
34
34
|
});
|
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) {
|
@@ -24,10 +24,22 @@ exports.isConstantExpression = isConstantExpression;
|
|
24
24
|
exports.isInStrictMode = isInStrictMode;
|
25
25
|
exports.is = void 0;
|
26
26
|
|
27
|
-
var
|
27
|
+
var _t = require("@babel/types");
|
28
|
+
|
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
|
|