flow-remove-types 2.248.1 → 2.250.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.
- package/index.js +10 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -57,7 +57,7 @@ module.exports = function flowRemoveTypes(source, options) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// This parse configuration is intended to be as permissive as possible.
|
|
60
|
-
var ast = parse(source, {
|
|
60
|
+
var ast = parse(source, {flow: all ? 'all' : 'detect', tokens: true});
|
|
61
61
|
|
|
62
62
|
var removedNodes = [];
|
|
63
63
|
|
|
@@ -156,7 +156,6 @@ var removeFlowVisitor = {
|
|
|
156
156
|
TypeAnnotation: removeNodeIfNotCommentType,
|
|
157
157
|
TypePredicate: removeNodeIfNotCommentType,
|
|
158
158
|
TypeParameterDeclaration: removeNode,
|
|
159
|
-
TypeParameterInstantiation: removeNode,
|
|
160
159
|
InferredPredicate: removeInferredPredicateNode,
|
|
161
160
|
OpaqueType: removeNode,
|
|
162
161
|
DeclareOpaqueType: removeNode,
|
|
@@ -168,11 +167,7 @@ var removeFlowVisitor = {
|
|
|
168
167
|
AsExpression: function (context, node, ast) {
|
|
169
168
|
var typeIdx = findTokenIndexAtStartOfNode(ast.tokens, node.typeAnnotation);
|
|
170
169
|
removeNode(context, ast.tokens[typeIdx - 1]); // `as` token
|
|
171
|
-
|
|
172
|
-
removeNode(context, ast.tokens[typeIdx]);
|
|
173
|
-
} else {
|
|
174
|
-
removeNode(context, node.typeAnnotation);
|
|
175
|
-
}
|
|
170
|
+
removeNode(context, node.typeAnnotation);
|
|
176
171
|
},
|
|
177
172
|
|
|
178
173
|
AsConstExpression: function (context, node, ast) {
|
|
@@ -311,6 +306,13 @@ var removeFlowVisitor = {
|
|
|
311
306
|
}
|
|
312
307
|
}
|
|
313
308
|
},
|
|
309
|
+
|
|
310
|
+
TypeParameterInstantiation: function (context, node, ast, parent) {
|
|
311
|
+
// prevent interference with asExpression removal
|
|
312
|
+
if (parent.type !== 'GenericTypeAnnotation') {
|
|
313
|
+
removeNode(context, node);
|
|
314
|
+
}
|
|
315
|
+
},
|
|
314
316
|
};
|
|
315
317
|
|
|
316
318
|
// If this class declaration or expression implements interfaces, remove
|
|
@@ -561,7 +563,7 @@ function visit(ast, context, visitor) {
|
|
|
561
563
|
if (node && typeof node === 'object' && (node.type || node.length)) {
|
|
562
564
|
if (node.type) {
|
|
563
565
|
var visitFn = visitor[node.type];
|
|
564
|
-
if (visitFn && visitFn(context, node, ast) === false) {
|
|
566
|
+
if (visitFn && visitFn(context, node, ast, parent) === false) {
|
|
565
567
|
continue;
|
|
566
568
|
}
|
|
567
569
|
}
|