@babel/traverse 7.6.2 → 7.6.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 +2 -10
- package/lib/index.js +7 -23
- package/lib/path/ancestry.js +2 -10
- package/lib/path/comments.js +3 -11
- package/lib/path/conversion.js +37 -53
- package/lib/path/family.js +4 -12
- package/lib/path/index.js +9 -33
- package/lib/path/inference/index.js +18 -26
- package/lib/path/inference/inferer-reference.js +8 -16
- package/lib/path/inference/inferers.js +37 -45
- package/lib/path/introspection.js +10 -26
- package/lib/path/lib/hoister.js +17 -14
- package/lib/path/lib/virtual-types.js +20 -28
- package/lib/path/modification.js +6 -14
- package/lib/path/replacement.js +25 -49
- package/lib/scope/index.js +59 -99
- package/lib/scope/lib/renamer.js +8 -24
- package/lib/visitors.js +6 -22
- package/package.json +5 -5
@@ -5,15 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = _default;
|
7
7
|
|
8
|
-
|
9
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
10
|
-
|
11
|
-
t = function () {
|
12
|
-
return data;
|
13
|
-
};
|
14
|
-
|
15
|
-
return data;
|
16
|
-
}
|
8
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
17
9
|
|
18
10
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
19
11
|
|
@@ -32,9 +24,9 @@ function _default(node) {
|
|
32
24
|
}
|
33
25
|
|
34
26
|
if (node.name === "undefined") {
|
35
|
-
return t
|
27
|
+
return t.voidTypeAnnotation();
|
36
28
|
} else if (node.name === "NaN" || node.name === "Infinity") {
|
37
|
-
return t
|
29
|
+
return t.numberTypeAnnotation();
|
38
30
|
} else if (node.name === "arguments") {}
|
39
31
|
}
|
40
32
|
|
@@ -59,7 +51,7 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
|
59
51
|
}
|
60
52
|
|
61
53
|
if (types.length) {
|
62
|
-
return t
|
54
|
+
return t.createUnionTypeAnnotation(types);
|
63
55
|
}
|
64
56
|
}
|
65
57
|
|
@@ -97,8 +89,8 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
97
89
|
return target.getTypeAnnotation();
|
98
90
|
}
|
99
91
|
|
100
|
-
if (t
|
101
|
-
return t
|
92
|
+
if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
93
|
+
return t.numberTypeAnnotation();
|
102
94
|
}
|
103
95
|
|
104
96
|
return;
|
@@ -128,7 +120,7 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
128
120
|
if (!typePath.isLiteral()) return;
|
129
121
|
const typeValue = typePath.node.value;
|
130
122
|
if (typeof typeValue !== "string") return;
|
131
|
-
return t
|
123
|
+
return t.createTypeAnnotationBasedOnTypeof(typeValue);
|
132
124
|
}
|
133
125
|
|
134
126
|
function getParentConditionalPath(binding, path, name) {
|
@@ -174,7 +166,7 @@ function getConditionalAnnotation(binding, path, name) {
|
|
174
166
|
|
175
167
|
if (types.length) {
|
176
168
|
return {
|
177
|
-
typeAnnotation: t
|
169
|
+
typeAnnotation: t.createUnionTypeAnnotation(types),
|
178
170
|
ifStatement
|
179
171
|
};
|
180
172
|
}
|
@@ -33,15 +33,7 @@ Object.defineProperty(exports, "Identifier", {
|
|
33
33
|
}
|
34
34
|
});
|
35
35
|
|
36
|
-
|
37
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
38
|
-
|
39
|
-
t = function () {
|
40
|
-
return data;
|
41
|
-
};
|
42
|
-
|
43
|
-
return data;
|
44
|
-
}
|
36
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
45
37
|
|
46
38
|
var _infererReference = _interopRequireDefault(require("./inferer-reference"));
|
47
39
|
|
@@ -76,55 +68,55 @@ TypeCastExpression.validParent = true;
|
|
76
68
|
|
77
69
|
function NewExpression(node) {
|
78
70
|
if (this.get("callee").isIdentifier()) {
|
79
|
-
return t
|
71
|
+
return t.genericTypeAnnotation(node.callee);
|
80
72
|
}
|
81
73
|
}
|
82
74
|
|
83
75
|
function TemplateLiteral() {
|
84
|
-
return t
|
76
|
+
return t.stringTypeAnnotation();
|
85
77
|
}
|
86
78
|
|
87
79
|
function UnaryExpression(node) {
|
88
80
|
const operator = node.operator;
|
89
81
|
|
90
82
|
if (operator === "void") {
|
91
|
-
return t
|
92
|
-
} else if (t
|
93
|
-
return t
|
94
|
-
} else if (t
|
95
|
-
return t
|
96
|
-
} else if (t
|
97
|
-
return t
|
83
|
+
return t.voidTypeAnnotation();
|
84
|
+
} else if (t.NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
85
|
+
return t.numberTypeAnnotation();
|
86
|
+
} else if (t.STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
87
|
+
return t.stringTypeAnnotation();
|
88
|
+
} else if (t.BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
89
|
+
return t.booleanTypeAnnotation();
|
98
90
|
}
|
99
91
|
}
|
100
92
|
|
101
93
|
function BinaryExpression(node) {
|
102
94
|
const operator = node.operator;
|
103
95
|
|
104
|
-
if (t
|
105
|
-
return t
|
106
|
-
} else if (t
|
107
|
-
return t
|
96
|
+
if (t.NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
97
|
+
return t.numberTypeAnnotation();
|
98
|
+
} else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
99
|
+
return t.booleanTypeAnnotation();
|
108
100
|
} else if (operator === "+") {
|
109
101
|
const right = this.get("right");
|
110
102
|
const left = this.get("left");
|
111
103
|
|
112
104
|
if (left.isBaseType("number") && right.isBaseType("number")) {
|
113
|
-
return t
|
105
|
+
return t.numberTypeAnnotation();
|
114
106
|
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
115
|
-
return t
|
107
|
+
return t.stringTypeAnnotation();
|
116
108
|
}
|
117
109
|
|
118
|
-
return t
|
110
|
+
return t.unionTypeAnnotation([t.stringTypeAnnotation(), t.numberTypeAnnotation()]);
|
119
111
|
}
|
120
112
|
}
|
121
113
|
|
122
114
|
function LogicalExpression() {
|
123
|
-
return t
|
115
|
+
return t.createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]);
|
124
116
|
}
|
125
117
|
|
126
118
|
function ConditionalExpression() {
|
127
|
-
return t
|
119
|
+
return t.createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]);
|
128
120
|
}
|
129
121
|
|
130
122
|
function SequenceExpression() {
|
@@ -143,36 +135,36 @@ function UpdateExpression(node) {
|
|
143
135
|
const operator = node.operator;
|
144
136
|
|
145
137
|
if (operator === "++" || operator === "--") {
|
146
|
-
return t
|
138
|
+
return t.numberTypeAnnotation();
|
147
139
|
}
|
148
140
|
}
|
149
141
|
|
150
142
|
function StringLiteral() {
|
151
|
-
return t
|
143
|
+
return t.stringTypeAnnotation();
|
152
144
|
}
|
153
145
|
|
154
146
|
function NumericLiteral() {
|
155
|
-
return t
|
147
|
+
return t.numberTypeAnnotation();
|
156
148
|
}
|
157
149
|
|
158
150
|
function BooleanLiteral() {
|
159
|
-
return t
|
151
|
+
return t.booleanTypeAnnotation();
|
160
152
|
}
|
161
153
|
|
162
154
|
function NullLiteral() {
|
163
|
-
return t
|
155
|
+
return t.nullLiteralTypeAnnotation();
|
164
156
|
}
|
165
157
|
|
166
158
|
function RegExpLiteral() {
|
167
|
-
return t
|
159
|
+
return t.genericTypeAnnotation(t.identifier("RegExp"));
|
168
160
|
}
|
169
161
|
|
170
162
|
function ObjectExpression() {
|
171
|
-
return t
|
163
|
+
return t.genericTypeAnnotation(t.identifier("Object"));
|
172
164
|
}
|
173
165
|
|
174
166
|
function ArrayExpression() {
|
175
|
-
return t
|
167
|
+
return t.genericTypeAnnotation(t.identifier("Array"));
|
176
168
|
}
|
177
169
|
|
178
170
|
function RestElement() {
|
@@ -182,13 +174,13 @@ function RestElement() {
|
|
182
174
|
RestElement.validParent = true;
|
183
175
|
|
184
176
|
function Func() {
|
185
|
-
return t
|
177
|
+
return t.genericTypeAnnotation(t.identifier("Function"));
|
186
178
|
}
|
187
179
|
|
188
|
-
const isArrayFrom = t
|
189
|
-
const isObjectKeys = t
|
190
|
-
const isObjectValues = t
|
191
|
-
const isObjectEntries = t
|
180
|
+
const isArrayFrom = t.buildMatchMemberExpression("Array.from");
|
181
|
+
const isObjectKeys = t.buildMatchMemberExpression("Object.keys");
|
182
|
+
const isObjectValues = t.buildMatchMemberExpression("Object.values");
|
183
|
+
const isObjectEntries = t.buildMatchMemberExpression("Object.entries");
|
192
184
|
|
193
185
|
function CallExpression() {
|
194
186
|
const {
|
@@ -196,11 +188,11 @@ function CallExpression() {
|
|
196
188
|
} = this.node;
|
197
189
|
|
198
190
|
if (isObjectKeys(callee)) {
|
199
|
-
return t
|
191
|
+
return t.arrayTypeAnnotation(t.stringTypeAnnotation());
|
200
192
|
} else if (isArrayFrom(callee) || isObjectValues(callee)) {
|
201
|
-
return t
|
193
|
+
return t.arrayTypeAnnotation(t.anyTypeAnnotation());
|
202
194
|
} else if (isObjectEntries(callee)) {
|
203
|
-
return t
|
195
|
+
return t.arrayTypeAnnotation(t.tupleTypeAnnotation([t.stringTypeAnnotation(), t.anyTypeAnnotation()]));
|
204
196
|
}
|
205
197
|
|
206
198
|
return resolveCall(this.get("callee"));
|
@@ -216,9 +208,9 @@ function resolveCall(callee) {
|
|
216
208
|
if (callee.isFunction()) {
|
217
209
|
if (callee.is("async")) {
|
218
210
|
if (callee.is("generator")) {
|
219
|
-
return t
|
211
|
+
return t.genericTypeAnnotation(t.identifier("AsyncIterator"));
|
220
212
|
} else {
|
221
|
-
return t
|
213
|
+
return t.genericTypeAnnotation(t.identifier("Promise"));
|
222
214
|
}
|
223
215
|
} else {
|
224
216
|
if (callee.node.returnType) {
|
@@ -24,25 +24,9 @@ exports.isConstantExpression = isConstantExpression;
|
|
24
24
|
exports.isInStrictMode = isInStrictMode;
|
25
25
|
exports.is = void 0;
|
26
26
|
|
27
|
-
|
28
|
-
const data = _interopRequireDefault(require("lodash/includes"));
|
27
|
+
var _includes = _interopRequireDefault(require("lodash/includes"));
|
29
28
|
|
30
|
-
|
31
|
-
return data;
|
32
|
-
};
|
33
|
-
|
34
|
-
return data;
|
35
|
-
}
|
36
|
-
|
37
|
-
function t() {
|
38
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
39
|
-
|
40
|
-
t = function () {
|
41
|
-
return data;
|
42
|
-
};
|
43
|
-
|
44
|
-
return data;
|
45
|
-
}
|
29
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
46
30
|
|
47
31
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
48
32
|
|
@@ -51,7 +35,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
51
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
52
36
|
|
53
37
|
function matchesPattern(pattern, allowPartial) {
|
54
|
-
return t
|
38
|
+
return t.matchesPattern(this.node, pattern, allowPartial);
|
55
39
|
}
|
56
40
|
|
57
41
|
function has(key) {
|
@@ -80,7 +64,7 @@ function equals(key, value) {
|
|
80
64
|
}
|
81
65
|
|
82
66
|
function isNodeType(type) {
|
83
|
-
return t
|
67
|
+
return t.isType(this.type, type);
|
84
68
|
}
|
85
69
|
|
86
70
|
function canHaveVariableDeclarationOrExpression() {
|
@@ -93,9 +77,9 @@ function canSwapBetweenExpressionAndStatement(replacement) {
|
|
93
77
|
}
|
94
78
|
|
95
79
|
if (this.isExpression()) {
|
96
|
-
return t
|
80
|
+
return t.isBlockStatement(replacement);
|
97
81
|
} else if (this.isBlockStatement()) {
|
98
|
-
return t
|
82
|
+
return t.isExpression(replacement);
|
99
83
|
}
|
100
84
|
|
101
85
|
return false;
|
@@ -123,10 +107,10 @@ function isCompletionRecord(allowInsideFunction) {
|
|
123
107
|
}
|
124
108
|
|
125
109
|
function isStatementOrBlock() {
|
126
|
-
if (this.parentPath.isLabeledStatement() || t
|
110
|
+
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) {
|
127
111
|
return false;
|
128
112
|
} else {
|
129
|
-
return (0, _includes
|
113
|
+
return (0, _includes.default)(t.STATEMENT_OR_BLOCK_KEYS, this.key);
|
130
114
|
}
|
131
115
|
}
|
132
116
|
|
@@ -278,7 +262,7 @@ function _guessExecutionStatusRelativeTo(target) {
|
|
278
262
|
return divergence.target.key > divergence.this.key ? "before" : "after";
|
279
263
|
}
|
280
264
|
|
281
|
-
const keys = t
|
265
|
+
const keys = t.VISITOR_KEYS[commonPath.type];
|
282
266
|
const keyPosition = {
|
283
267
|
this: keys.indexOf(divergence.this.parentKey),
|
284
268
|
target: keys.indexOf(divergence.target.parentKey)
|
@@ -351,7 +335,7 @@ function _resolve(dangerous, resolved) {
|
|
351
335
|
return this.get("expression").resolve(dangerous, resolved);
|
352
336
|
} else if (dangerous && this.isMemberExpression()) {
|
353
337
|
const targetKey = this.toComputedKey();
|
354
|
-
if (!t
|
338
|
+
if (!t.isLiteral(targetKey)) return;
|
355
339
|
const targetName = targetKey.value;
|
356
340
|
const target = this.get("object").resolve(dangerous, resolved);
|
357
341
|
|
package/lib/path/lib/hoister.js
CHANGED
@@ -5,15 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
|
9
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
10
|
-
|
11
|
-
t = function () {
|
12
|
-
return data;
|
13
|
-
};
|
14
|
-
|
15
|
-
return data;
|
16
|
-
}
|
8
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
17
9
|
|
18
10
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
19
11
|
|
@@ -21,7 +13,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
21
13
|
|
22
14
|
const referenceVisitor = {
|
23
15
|
ReferencedIdentifier(path, state) {
|
24
|
-
if (path.isJSXIdentifier() && t
|
16
|
+
if (path.isJSXIdentifier() && t.react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
25
17
|
return;
|
26
18
|
}
|
27
19
|
|
@@ -39,6 +31,15 @@ const referenceVisitor = {
|
|
39
31
|
|
40
32
|
const binding = path.scope.getBinding(path.node.name);
|
41
33
|
if (!binding) return;
|
34
|
+
|
35
|
+
for (const violation of binding.constantViolations) {
|
36
|
+
if (violation.scope !== binding.path.scope) {
|
37
|
+
state.mutableBinding = true;
|
38
|
+
path.stop();
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
42
43
|
if (binding !== state.scope.getBinding(path.node.name)) return;
|
43
44
|
state.bindings[path.node.name] = binding;
|
44
45
|
}
|
@@ -49,6 +50,7 @@ class PathHoister {
|
|
49
50
|
constructor(path, scope) {
|
50
51
|
this.breakOnScopePaths = [];
|
51
52
|
this.bindings = {};
|
53
|
+
this.mutableBinding = false;
|
52
54
|
this.scopes = [];
|
53
55
|
this.scope = scope;
|
54
56
|
this.path = path;
|
@@ -167,21 +169,22 @@ class PathHoister {
|
|
167
169
|
|
168
170
|
run() {
|
169
171
|
this.path.traverse(referenceVisitor, this);
|
172
|
+
if (this.mutableBinding) return;
|
170
173
|
this.getCompatibleScopes();
|
171
174
|
const attachTo = this.getAttachmentPath();
|
172
175
|
if (!attachTo) return;
|
173
176
|
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
174
177
|
let uid = attachTo.scope.generateUidIdentifier("ref");
|
175
|
-
const declarator = t
|
178
|
+
const declarator = t.variableDeclarator(uid, this.path.node);
|
176
179
|
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
177
|
-
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t
|
180
|
+
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator])]);
|
178
181
|
const parent = this.path.parentPath;
|
179
182
|
|
180
183
|
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
181
|
-
uid = t
|
184
|
+
uid = t.JSXExpressionContainer(uid);
|
182
185
|
}
|
183
186
|
|
184
|
-
this.path.replaceWith(t
|
187
|
+
this.path.replaceWith(t.cloneNode(uid));
|
185
188
|
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
186
189
|
}
|
187
190
|
|
@@ -5,15 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
|
7
7
|
|
8
|
-
|
9
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
10
|
-
|
11
|
-
t = function () {
|
12
|
-
return data;
|
13
|
-
};
|
14
|
-
|
15
|
-
return data;
|
16
|
-
}
|
8
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
17
9
|
|
18
10
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
19
11
|
|
@@ -28,15 +20,15 @@ const ReferencedIdentifier = {
|
|
28
20
|
parent
|
29
21
|
} = path;
|
30
22
|
|
31
|
-
if (!t
|
32
|
-
if (t
|
33
|
-
if (t
|
23
|
+
if (!t.isIdentifier(node, opts) && !t.isJSXMemberExpression(parent, opts)) {
|
24
|
+
if (t.isJSXIdentifier(node, opts)) {
|
25
|
+
if (t.react.isCompatTag(node.name)) return false;
|
34
26
|
} else {
|
35
27
|
return false;
|
36
28
|
}
|
37
29
|
}
|
38
30
|
|
39
|
-
return t
|
31
|
+
return t.isReferenced(node, parent, path.parentPath.parent);
|
40
32
|
}
|
41
33
|
|
42
34
|
};
|
@@ -48,7 +40,7 @@ const ReferencedMemberExpression = {
|
|
48
40
|
node,
|
49
41
|
parent
|
50
42
|
}) {
|
51
|
-
return t
|
43
|
+
return t.isMemberExpression(node) && t.isReferenced(node, parent);
|
52
44
|
}
|
53
45
|
|
54
46
|
};
|
@@ -62,7 +54,7 @@ const BindingIdentifier = {
|
|
62
54
|
parent
|
63
55
|
} = path;
|
64
56
|
const grandparent = path.parentPath.parent;
|
65
|
-
return t
|
57
|
+
return t.isIdentifier(node) && t.isBinding(node, parent, grandparent);
|
66
58
|
}
|
67
59
|
|
68
60
|
};
|
@@ -74,12 +66,12 @@ const Statement = {
|
|
74
66
|
node,
|
75
67
|
parent
|
76
68
|
}) {
|
77
|
-
if (t
|
78
|
-
if (t
|
79
|
-
if (t
|
69
|
+
if (t.isStatement(node)) {
|
70
|
+
if (t.isVariableDeclaration(node)) {
|
71
|
+
if (t.isForXStatement(parent, {
|
80
72
|
left: node
|
81
73
|
})) return false;
|
82
|
-
if (t
|
74
|
+
if (t.isForStatement(parent, {
|
83
75
|
init: node
|
84
76
|
})) return false;
|
85
77
|
}
|
@@ -99,7 +91,7 @@ const Expression = {
|
|
99
91
|
if (path.isIdentifier()) {
|
100
92
|
return path.isReferencedIdentifier();
|
101
93
|
} else {
|
102
|
-
return t
|
94
|
+
return t.isExpression(path.node);
|
103
95
|
}
|
104
96
|
}
|
105
97
|
|
@@ -109,21 +101,21 @@ const Scope = {
|
|
109
101
|
types: ["Scopable"],
|
110
102
|
|
111
103
|
checkPath(path) {
|
112
|
-
return t
|
104
|
+
return t.isScope(path.node, path.parent);
|
113
105
|
}
|
114
106
|
|
115
107
|
};
|
116
108
|
exports.Scope = Scope;
|
117
109
|
const Referenced = {
|
118
110
|
checkPath(path) {
|
119
|
-
return t
|
111
|
+
return t.isReferenced(path.node, path.parent);
|
120
112
|
}
|
121
113
|
|
122
114
|
};
|
123
115
|
exports.Referenced = Referenced;
|
124
116
|
const BlockScoped = {
|
125
117
|
checkPath(path) {
|
126
|
-
return t
|
118
|
+
return t.isBlockScoped(path.node);
|
127
119
|
}
|
128
120
|
|
129
121
|
};
|
@@ -132,7 +124,7 @@ const Var = {
|
|
132
124
|
types: ["VariableDeclaration"],
|
133
125
|
|
134
126
|
checkPath(path) {
|
135
|
-
return t
|
127
|
+
return t.isVar(path.node);
|
136
128
|
}
|
137
129
|
|
138
130
|
};
|
@@ -164,13 +156,13 @@ const Flow = {
|
|
164
156
|
checkPath({
|
165
157
|
node
|
166
158
|
}) {
|
167
|
-
if (t
|
159
|
+
if (t.isFlow(node)) {
|
168
160
|
return true;
|
169
|
-
} else if (t
|
161
|
+
} else if (t.isImportDeclaration(node)) {
|
170
162
|
return node.importKind === "type" || node.importKind === "typeof";
|
171
|
-
} else if (t
|
163
|
+
} else if (t.isExportDeclaration(node)) {
|
172
164
|
return node.exportKind === "type";
|
173
|
-
} else if (t
|
165
|
+
} else if (t.isImportSpecifier(node)) {
|
174
166
|
return node.importKind === "type" || node.importKind === "typeof";
|
175
167
|
} else {
|
176
168
|
return false;
|
package/lib/path/modification.js
CHANGED
@@ -20,15 +20,7 @@ var _hoister = _interopRequireDefault(require("./lib/hoister"));
|
|
20
20
|
|
21
21
|
var _index = _interopRequireDefault(require("./index"));
|
22
22
|
|
23
|
-
|
24
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
25
|
-
|
26
|
-
t = function () {
|
27
|
-
return data;
|
28
|
-
};
|
29
|
-
|
30
|
-
return data;
|
31
|
-
}
|
23
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
32
24
|
|
33
25
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
34
26
|
|
@@ -53,7 +45,7 @@ function insertBefore(nodes) {
|
|
53
45
|
return this._containerInsertBefore(nodes);
|
54
46
|
} else if (this.isStatementOrBlock()) {
|
55
47
|
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
|
56
|
-
this.replaceWith(t
|
48
|
+
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : []));
|
57
49
|
return this.unshiftContainer("body", nodes);
|
58
50
|
} else {
|
59
51
|
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
@@ -107,7 +99,7 @@ function insertAfter(nodes) {
|
|
107
99
|
|
108
100
|
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
109
101
|
return parentPath.insertAfter(nodes.map(node => {
|
110
|
-
return t
|
102
|
+
return t.isExpression(node) ? t.expressionStatement(node) : node;
|
111
103
|
}));
|
112
104
|
} else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
113
105
|
if (this.node) {
|
@@ -123,8 +115,8 @@ function insertAfter(nodes) {
|
|
123
115
|
}
|
124
116
|
|
125
117
|
const temp = scope.generateDeclaredUidIdentifier();
|
126
|
-
nodes.unshift(t
|
127
|
-
nodes.push(t
|
118
|
+
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), this.node)));
|
119
|
+
nodes.push(t.expressionStatement(t.cloneNode(temp)));
|
128
120
|
}
|
129
121
|
|
130
122
|
return this.replaceExpressionWithStatements(nodes);
|
@@ -132,7 +124,7 @@ function insertAfter(nodes) {
|
|
132
124
|
return this._containerInsertAfter(nodes);
|
133
125
|
} else if (this.isStatementOrBlock()) {
|
134
126
|
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
|
135
|
-
this.replaceWith(t
|
127
|
+
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : []));
|
136
128
|
return this.pushContainer("body", nodes);
|
137
129
|
} else {
|
138
130
|
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|