flow-remove-types 2.220.1 → 2.222.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.
Files changed (2) hide show
  1. package/index.js +13 -12
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * @format
8
8
  */
9
9
 
10
- var parse = require('flow-parser').parse;
10
+ var parse = require('hermes-parser').parse;
11
11
  var vlq = require('vlq');
12
12
 
13
13
  /**
@@ -57,16 +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, {
61
- esproposal_decorators: true,
62
- esproposal_class_instance_fields: true,
63
- esproposal_class_static_fields: true,
64
- esproposal_export_star_as: true,
65
- esproposal_optional_chaining: true,
66
- esproposal_nullish_coalescing: true,
67
- types: true,
68
- tokens: true,
69
- });
60
+ var ast = parse(source, {types: true, tokens: true});
70
61
 
71
62
  var removedNodes = [];
72
63
 
@@ -165,7 +156,7 @@ var removeFlowVisitor = {
165
156
  TypePredicate: removeNodeIfNotCommentType,
166
157
  TypeParameterDeclaration: removeNode,
167
158
  TypeParameterInstantiation: removeNode,
168
- InferredPredicate: removeNode,
159
+ InferredPredicate: removeInferredPredicateNode,
169
160
  OpaqueType: removeNode,
170
161
  DeclareOpaqueType: removeNode,
171
162
  DeclareExportDeclaration: removeNode,
@@ -369,6 +360,16 @@ function removeNodeIfNotCommentType(context, node) {
369
360
  return removeNode(context, node);
370
361
  }
371
362
 
363
+ function removeInferredPredicateNode(context, node) {
364
+ var tokens = context.ast.tokens;
365
+ var priorTokenIdx = findTokenIndexAtStartOfNode(tokens, node) - 1;
366
+ var token = tokens[priorTokenIdx];
367
+ if (token && token.type === 'Punctuator' && token.value === ':') {
368
+ removeNode(context, token);
369
+ }
370
+ return removeNode(context, node);
371
+ }
372
+
372
373
  function removeTrailingCommaNode(context, node) {
373
374
  var ast = context.ast;
374
375
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-remove-types",
3
- "version": "2.220.1",
3
+ "version": "2.222.0",
4
4
  "description": "Removes Flow type annotations from JavaScript files with speed and simplicity.",
5
5
  "author": {
6
6
  "name": "Flow Team",
@@ -44,7 +44,7 @@
44
44
  "es6"
45
45
  ],
46
46
  "dependencies": {
47
- "flow-parser": "^0.220.0",
47
+ "hermes-parser": "0.17.1",
48
48
  "pirates": "^3.0.2",
49
49
  "vlq": "^0.2.1"
50
50
  },