hermes-parser 0.31.2 → 0.32.1

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 (30) hide show
  1. package/README.md +3 -0
  2. package/dist/HermesASTAdapter.js +2 -2
  3. package/dist/HermesASTAdapter.js.flow +2 -2
  4. package/dist/HermesParserDeserializer.js +0 -1
  5. package/dist/HermesParserDeserializer.js.flow +0 -1
  6. package/dist/HermesParserWASM.js +1 -1
  7. package/dist/ParserOptions.js +1 -1
  8. package/dist/ParserOptions.js.flow +8 -0
  9. package/dist/babel/TransformESTreeToBabel.js +11 -8
  10. package/dist/babel/TransformESTreeToBabel.js.flow +11 -8
  11. package/dist/estree/{StripComponentSyntax.js → TransformComponentSyntax.js} +2 -2
  12. package/dist/estree/{StripComponentSyntax.js.flow → TransformComponentSyntax.js.flow} +2 -2
  13. package/dist/estree/TransformEnumSyntax.js +106 -0
  14. package/dist/estree/TransformEnumSyntax.js.flow +125 -0
  15. package/dist/index.js +6 -3
  16. package/dist/index.js.flow +6 -3
  17. package/dist/src/HermesASTAdapter.js +2 -2
  18. package/dist/src/HermesParserDeserializer.js +0 -1
  19. package/dist/src/ParserOptions.js +1 -1
  20. package/dist/src/babel/TransformESTreeToBabel.js +11 -8
  21. package/dist/src/estree/{StripComponentSyntax.js → TransformComponentSyntax.js} +2 -2
  22. package/dist/src/estree/TransformEnumSyntax.js +106 -0
  23. package/dist/src/index.js +6 -3
  24. package/dist/src/transform/SimpleTransform.js +20 -4
  25. package/dist/src/transform/astNodeMutationHelpers.js +7 -2
  26. package/dist/transform/SimpleTransform.js +20 -4
  27. package/dist/transform/SimpleTransform.js.flow +34 -8
  28. package/dist/transform/astNodeMutationHelpers.js +7 -2
  29. package/dist/transform/astNodeMutationHelpers.js.flow +10 -2
  30. package/package.json +2 -2
@@ -14,5 +14,5 @@ exports.ParserOptionsKeys = void 0;
14
14
  *
15
15
  * @format
16
16
  */
17
- const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens']);
17
+ const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens', 'transformOptions']);
18
18
  exports.ParserOptionsKeys = ParserOptionsKeys;
@@ -8,6 +8,8 @@
8
8
  * @format
9
9
  */
10
10
 
11
+ import type {Expression} from 'hermes-estree';
12
+
11
13
  export type ParserOptions = {
12
14
  allowReturnOutsideFunction?: boolean,
13
15
  babel?: boolean,
@@ -18,6 +20,11 @@ export type ParserOptions = {
18
20
  sourceFilename?: string,
19
21
  sourceType?: 'module' | 'script' | 'unambiguous',
20
22
  tokens?: boolean,
23
+ transformOptions?: {
24
+ +TransformEnumSyntax?: {
25
+ +getRuntime: () => Expression,
26
+ },
27
+ },
21
28
  };
22
29
 
23
30
  export const ParserOptionsKeys: $ReadOnlySet<$Keys<ParserOptions>> = new Set([
@@ -30,4 +37,5 @@ export const ParserOptionsKeys: $ReadOnlySet<$Keys<ParserOptions>> = new Set([
30
37
  'sourceFilename',
31
38
  'sourceType',
32
39
  'tokens',
40
+ 'transformOptions',
33
41
  ]);
@@ -126,7 +126,7 @@ function mapNodeWithDirectives(node) {
126
126
  break;
127
127
  }
128
128
  } // Move directives from body to new directives array
129
- // $FlowExpectedError[incompatible-call] We are adding properties for babel that don't exist in the ESTree types.
129
+ // $FlowExpectedError[incompatible-type] We are adding properties for babel that don't exist in the ESTree types.
130
130
 
131
131
 
132
132
  return nodeWith(node, {
@@ -189,7 +189,7 @@ function mapProgram(node) {
189
189
 
190
190
  return {
191
191
  type: 'File',
192
- // $FlowExpectedError[prop-missing] Comments, docblock and tokens are purposely missing to match the Babel AST.
192
+ // $FlowExpectedError[incompatible-type] Comments, docblock and tokens are purposely missing to match the Babel AST.
193
193
  program: {
194
194
  type: 'Program',
195
195
  body: program.body,
@@ -280,7 +280,7 @@ function mapProperty(node) {
280
280
  type: 'ObjectProperty',
281
281
  computed: node.computed,
282
282
  key: node.key,
283
- // $FlowExpectedError[incompatible-cast]
283
+ // $FlowExpectedError[incompatible-type]
284
284
  value: node.value,
285
285
  method: node.method,
286
286
  shorthand: node.shorthand,
@@ -398,10 +398,10 @@ function mapRestElement(node) {
398
398
  function mapImportExpression(node) {
399
399
  // Babel expects ImportExpression to be structured as a regular
400
400
  // CallExpression where the callee is an Import node.
401
- // $FlowExpectedError[prop-missing] optional and typeArguments are missing to match existing output.
401
+ // $FlowExpectedError[incompatible-type] optional and typeArguments are missing to match existing output.
402
402
  return {
403
403
  type: 'CallExpression',
404
- // $FlowExpectedError[incompatible-return] This is a babel specific node
404
+ // $FlowExpectedError[incompatible-type] This is a babel specific node
405
405
  callee: {
406
406
  type: 'Import',
407
407
  loc: {
@@ -480,10 +480,11 @@ function mapPropertyDefinition(node) {
480
480
  function mapTypeofTypeAnnotation(node) {
481
481
  // $FlowExpectedError[cannot-write]
482
482
  delete node.typeArguments; // $FlowFixMe[incompatible-type]
483
+ // $FlowFixMe[invalid-compare]
483
484
 
484
485
  if (node.argument.type !== 'GenericTypeAnnotation') {
485
486
  return nodeWith(node, {
486
- // $FlowExpectedError[incompatible-call] Special override for Babel
487
+ // $FlowExpectedError[incompatible-type] Special override for Babel
487
488
  argument: {
488
489
  type: 'GenericTypeAnnotation',
489
490
  id: node.argument,
@@ -656,6 +657,7 @@ function transformNode(node) {
656
657
 
657
658
  // Check if we have already processed this node.
658
659
  // $FlowFixMe[incompatible-type]
660
+ // $FlowFixMe[invalid-compare]
659
661
  if (((_node$parent = node.parent) == null ? void 0 : _node$parent.type) === 'File') {
660
662
  return node;
661
663
  }
@@ -1093,12 +1095,12 @@ function transformProgram(program, options) {
1093
1095
 
1094
1096
  const resultNode = _SimpleTransform.SimpleTransform.transform(program, {
1095
1097
  transform(node) {
1096
- // $FlowExpectedError[incompatible-call] We override the type to support the additional Babel types
1098
+ // $FlowExpectedError[incompatible-type] We override the type to support the additional Babel types
1097
1099
  return transformNode(node);
1098
1100
  },
1099
1101
 
1100
1102
  visitorKeys: FlowESTreeAndBabelVisitorKeys
1101
- }); // $FlowExpectedError[incompatible-call] We override the type to support the additional Babel types
1103
+ }); // $FlowExpectedError[incompatible-type] We override the type to support the additional Babel types
1102
1104
 
1103
1105
 
1104
1106
  _SimpleTraverser.SimpleTraverser.traverse(resultNode, {
@@ -1110,6 +1112,7 @@ function transformProgram(program, options) {
1110
1112
 
1111
1113
  visitorKeys: FlowESTreeAndBabelVisitorKeys
1112
1114
  }); // $FlowFixMe[incompatible-type]
1115
+ // $FlowFixMe[invalid-compare]
1113
1116
 
1114
1117
 
1115
1118
  if ((resultNode == null ? void 0 : resultNode.type) === 'File') {
@@ -374,7 +374,7 @@ function mapNodeWithDirectives<T: Program | BlockStatement>(node: T): T {
374
374
  }
375
375
 
376
376
  // Move directives from body to new directives array
377
- // $FlowExpectedError[incompatible-call] We are adding properties for babel that don't exist in the ESTree types.
377
+ // $FlowExpectedError[incompatible-type] We are adding properties for babel that don't exist in the ESTree types.
378
378
  return nodeWith(node, {
379
379
  directives,
380
380
  body:
@@ -432,7 +432,7 @@ function mapProgram(node: Program): BabelFile {
432
432
  // Rename root node to File node and move Program node under program property
433
433
  return {
434
434
  type: 'File',
435
- // $FlowExpectedError[prop-missing] Comments, docblock and tokens are purposely missing to match the Babel AST.
435
+ // $FlowExpectedError[incompatible-type] Comments, docblock and tokens are purposely missing to match the Babel AST.
436
436
  program: {
437
437
  type: 'Program',
438
438
  body: program.body,
@@ -532,7 +532,7 @@ function mapProperty(node: Property): BabelObjectMethod | BabelObjectProperty {
532
532
  type: 'ObjectProperty',
533
533
  computed: node.computed,
534
534
  key: node.key,
535
- // $FlowExpectedError[incompatible-cast]
535
+ // $FlowExpectedError[incompatible-type]
536
536
  value: (node.value: Expression),
537
537
  method: node.method,
538
538
  shorthand: node.shorthand,
@@ -666,10 +666,10 @@ function mapImportExpression(node: ImportExpression): CallExpression {
666
666
  // Babel expects ImportExpression to be structured as a regular
667
667
  // CallExpression where the callee is an Import node.
668
668
 
669
- // $FlowExpectedError[prop-missing] optional and typeArguments are missing to match existing output.
669
+ // $FlowExpectedError[incompatible-type] optional and typeArguments are missing to match existing output.
670
670
  return {
671
671
  type: 'CallExpression',
672
- // $FlowExpectedError[incompatible-return] This is a babel specific node
672
+ // $FlowExpectedError[incompatible-type] This is a babel specific node
673
673
  callee: {
674
674
  type: 'Import',
675
675
  loc: {
@@ -753,9 +753,10 @@ function mapTypeofTypeAnnotation(
753
753
  // $FlowExpectedError[cannot-write]
754
754
  delete node.typeArguments;
755
755
  // $FlowFixMe[incompatible-type]
756
+ // $FlowFixMe[invalid-compare]
756
757
  if (node.argument.type !== 'GenericTypeAnnotation') {
757
758
  return nodeWith(node, {
758
- // $FlowExpectedError[incompatible-call] Special override for Babel
759
+ // $FlowExpectedError[incompatible-type] Special override for Babel
759
760
  argument: {
760
761
  type: 'GenericTypeAnnotation',
761
762
  id: node.argument,
@@ -920,6 +921,7 @@ function transformNode(node: ESNodeOrBabelNode): ESNodeOrBabelNode | null {
920
921
  case 'Program': {
921
922
  // Check if we have already processed this node.
922
923
  // $FlowFixMe[incompatible-type]
924
+ // $FlowFixMe[invalid-compare]
923
925
  if (node.parent?.type === 'File') {
924
926
  return node;
925
927
  }
@@ -1247,13 +1249,13 @@ export function transformProgram(
1247
1249
  ): BabelFile {
1248
1250
  const resultNode = SimpleTransform.transform(program, {
1249
1251
  transform(node) {
1250
- // $FlowExpectedError[incompatible-call] We override the type to support the additional Babel types
1252
+ // $FlowExpectedError[incompatible-type] We override the type to support the additional Babel types
1251
1253
  return transformNode(node);
1252
1254
  },
1253
1255
  visitorKeys: FlowESTreeAndBabelVisitorKeys,
1254
1256
  });
1255
1257
 
1256
- // $FlowExpectedError[incompatible-call] We override the type to support the additional Babel types
1258
+ // $FlowExpectedError[incompatible-type] We override the type to support the additional Babel types
1257
1259
  SimpleTraverser.traverse(resultNode, {
1258
1260
  enter(node) {
1259
1261
  fixSourceLocation(node, options);
@@ -1263,6 +1265,7 @@ export function transformProgram(
1263
1265
  });
1264
1266
 
1265
1267
  // $FlowFixMe[incompatible-type]
1268
+ // $FlowFixMe[invalid-compare]
1266
1269
  if (resultNode?.type === 'File') {
1267
1270
  return resultNode;
1268
1271
  }
@@ -191,7 +191,7 @@ function mapComponentParameters(params, options) {
191
191
 
192
192
  if (propsProperties.length === 0) {
193
193
  if (refParam == null) {
194
- throw new Error('StripComponentSyntax: Invalid state, ref should always be set at this point if props are empty');
194
+ throw new Error('TransformComponentSyntax: Invalid state, ref should always be set at this point if props are empty');
195
195
  }
196
196
 
197
197
  const emptyParamsLoc = {
@@ -757,7 +757,7 @@ function transformProgram(program, options) {
757
757
  {
758
758
  const consequent = mapStatementList(node.consequent, options);
759
759
  return nodeWith(node, {
760
- /* $FlowExpectedError[incompatible-call] We know `mapStatementList` will
760
+ /* $FlowExpectedError[incompatible-type] We know `mapStatementList` will
761
761
  not return `ModuleDeclaration` nodes if it is not passed any */
762
762
  consequent
763
763
  });
@@ -243,7 +243,7 @@ function mapComponentParameters(
243
243
  if (propsProperties.length === 0) {
244
244
  if (refParam == null) {
245
245
  throw new Error(
246
- 'StripComponentSyntax: Invalid state, ref should always be set at this point if props are empty',
246
+ 'TransformComponentSyntax: Invalid state, ref should always be set at this point if props are empty',
247
247
  );
248
248
  }
249
249
  const emptyParamsLoc = {
@@ -836,7 +836,7 @@ export function transformProgram(
836
836
  case 'SwitchCase': {
837
837
  const consequent = mapStatementList(node.consequent, options);
838
838
  return nodeWith(node, {
839
- /* $FlowExpectedError[incompatible-call] We know `mapStatementList` will
839
+ /* $FlowExpectedError[incompatible-type] We know `mapStatementList` will
840
840
  not return `ModuleDeclaration` nodes if it is not passed any */
841
841
  consequent,
842
842
  });
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ 'use strict';
11
+ /**
12
+ * Transform Flow Enum declarations (https://flow.org/en/docs/enums/).
13
+ */
14
+
15
+ Object.defineProperty(exports, "__esModule", {
16
+ value: true
17
+ });
18
+ exports.transformProgram = transformProgram;
19
+
20
+ var _hermesEstree = require("hermes-estree");
21
+
22
+ var _SimpleTransform = require("../transform/SimpleTransform");
23
+
24
+ var _Builders = require("../utils/Builders");
25
+
26
+ function mapEnumDeclaration(node, options) {
27
+ var _options$transformOpt, _options$transformOpt2;
28
+
29
+ const {
30
+ body
31
+ } = node;
32
+ const {
33
+ members
34
+ } = body;
35
+ const getRuntime = (_options$transformOpt = options.transformOptions) == null ? void 0 : (_options$transformOpt2 = _options$transformOpt.TransformEnumSyntax) == null ? void 0 : _options$transformOpt2.getRuntime;
36
+ const enumModule = typeof getRuntime === 'function' ? getRuntime() : (0, _Builders.callExpression)((0, _Builders.ident)('require'), [(0, _Builders.stringLiteral)('flow-enums-runtime')]);
37
+ const mirrored = body.type === 'EnumStringBody' && (!members.length || members[0].type === 'EnumDefaultedMember');
38
+ const enumExpression = mirrored ? (0, _Builders.callExpression)({
39
+ type: 'MemberExpression',
40
+ object: enumModule,
41
+ property: (0, _Builders.ident)('Mirrored'),
42
+ computed: false,
43
+ optional: false,
44
+ ...(0, _Builders.etc)()
45
+ }, [{
46
+ type: 'ArrayExpression',
47
+ elements: members.map(member => (0, _Builders.stringLiteral)(member.id.name)),
48
+ trailingComma: false,
49
+ ...(0, _Builders.etc)()
50
+ }]) : (0, _Builders.callExpression)(enumModule, [{
51
+ type: 'ObjectExpression',
52
+ properties: members.map(member => ({
53
+ type: 'Property',
54
+ key: member.id,
55
+ value: // String enums with `EnumDefaultedMember` are handled above by
56
+ // calculation of `mirrored`.
57
+ member.type === 'EnumDefaultedMember' ? (0, _Builders.callExpression)((0, _Builders.ident)('Symbol'), [(0, _Builders.stringLiteral)(member.id.name)]) : member.init,
58
+ kind: 'init',
59
+ method: false,
60
+ shorthand: false,
61
+ computed: false,
62
+ ...(0, _Builders.etc)(),
63
+ parent: _Builders.EMPTY_PARENT
64
+ })),
65
+ ...(0, _Builders.etc)()
66
+ }]);
67
+ return (0, _Builders.variableDeclaration)('const', node.id, enumExpression);
68
+ }
69
+
70
+ function transformProgram(program, options) {
71
+ return _SimpleTransform.SimpleTransform.transformProgram(program, {
72
+ transform(node) {
73
+ switch (node.type) {
74
+ case 'EnumDeclaration':
75
+ {
76
+ return mapEnumDeclaration(node, options);
77
+ }
78
+
79
+ case 'ExportDefaultDeclaration':
80
+ {
81
+ const {
82
+ declaration
83
+ } = node;
84
+
85
+ if ((0, _hermesEstree.isEnumDeclaration)(declaration)) {
86
+ const enumDeclaration = mapEnumDeclaration(declaration, options);
87
+
88
+ const exportDefault = _SimpleTransform.SimpleTransform.nodeWith(node, {
89
+ declaration: (0, _Builders.ident)(declaration.id.name)
90
+ });
91
+
92
+ return [enumDeclaration, exportDefault];
93
+ } else {
94
+ return node;
95
+ }
96
+ }
97
+
98
+ default:
99
+ {
100
+ return node;
101
+ }
102
+ }
103
+ }
104
+
105
+ });
106
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ /**
14
+ * Transform Flow Enum declarations (https://flow.org/en/docs/enums/).
15
+ */
16
+
17
+ import type {ParserOptions} from '../ParserOptions';
18
+ import type {
19
+ ESNode,
20
+ EnumDeclaration,
21
+ ExportDefaultDeclaration,
22
+ ObjectPropertyWithNonShorthandStaticName,
23
+ Program,
24
+ } from 'hermes-estree';
25
+
26
+ import {isEnumDeclaration} from 'hermes-estree';
27
+ import {SimpleTransform} from '../transform/SimpleTransform';
28
+ import {
29
+ EMPTY_PARENT,
30
+ callExpression,
31
+ etc,
32
+ ident,
33
+ stringLiteral,
34
+ variableDeclaration,
35
+ } from '../utils/Builders';
36
+
37
+ function mapEnumDeclaration(node: EnumDeclaration, options: ParserOptions) {
38
+ const {body} = node;
39
+ const {members} = body;
40
+ const getRuntime = options.transformOptions?.TransformEnumSyntax?.getRuntime;
41
+ const enumModule =
42
+ typeof getRuntime === 'function'
43
+ ? getRuntime()
44
+ : callExpression(ident('require'), [stringLiteral('flow-enums-runtime')]);
45
+ const mirrored =
46
+ body.type === 'EnumStringBody' &&
47
+ (!members.length || members[0].type === 'EnumDefaultedMember');
48
+ const enumExpression = mirrored
49
+ ? callExpression(
50
+ {
51
+ type: 'MemberExpression',
52
+ object: enumModule,
53
+ property: ident('Mirrored'),
54
+ computed: false,
55
+ optional: false,
56
+ ...etc(),
57
+ },
58
+ [
59
+ {
60
+ type: 'ArrayExpression',
61
+ elements: members.map(member => stringLiteral(member.id.name)),
62
+ trailingComma: false,
63
+ ...etc(),
64
+ },
65
+ ],
66
+ )
67
+ : callExpression(enumModule, [
68
+ {
69
+ type: 'ObjectExpression',
70
+ properties: members.map(
71
+ (member): ObjectPropertyWithNonShorthandStaticName => ({
72
+ type: 'Property',
73
+ key: member.id,
74
+ value:
75
+ // String enums with `EnumDefaultedMember` are handled above by
76
+ // calculation of `mirrored`.
77
+ member.type === 'EnumDefaultedMember'
78
+ ? callExpression(ident('Symbol'), [
79
+ stringLiteral(member.id.name),
80
+ ])
81
+ : member.init,
82
+ kind: 'init',
83
+ method: false,
84
+ shorthand: false,
85
+ computed: false,
86
+ ...etc(),
87
+ parent: EMPTY_PARENT,
88
+ }),
89
+ ),
90
+ ...etc(),
91
+ },
92
+ ]);
93
+ return variableDeclaration('const', node.id, enumExpression);
94
+ }
95
+
96
+ export function transformProgram(
97
+ program: Program,
98
+ options: ParserOptions,
99
+ ): Program {
100
+ return SimpleTransform.transformProgram(program, {
101
+ transform(node: ESNode): ESNode | $ReadOnlyArray<ESNode> {
102
+ switch (node.type) {
103
+ case 'EnumDeclaration': {
104
+ return mapEnumDeclaration(node, options);
105
+ }
106
+ case 'ExportDefaultDeclaration': {
107
+ const {declaration} = node;
108
+ if (isEnumDeclaration(declaration)) {
109
+ const enumDeclaration = mapEnumDeclaration(declaration, options);
110
+ const exportDefault: ExportDefaultDeclaration =
111
+ SimpleTransform.nodeWith(node, {
112
+ declaration: ident(declaration.id.name),
113
+ });
114
+ return [enumDeclaration, exportDefault];
115
+ } else {
116
+ return node;
117
+ }
118
+ }
119
+ default: {
120
+ return node;
121
+ }
122
+ }
123
+ },
124
+ });
125
+ }
package/dist/index.js CHANGED
@@ -31,7 +31,9 @@ var _ESTreeVisitorKeys = _interopRequireDefault(require("./generated/ESTreeVisit
31
31
 
32
32
  exports.FlowVisitorKeys = _ESTreeVisitorKeys.default;
33
33
 
34
- var StripComponentSyntax = _interopRequireWildcard(require("./estree/StripComponentSyntax"));
34
+ var TransformComponentSyntax = _interopRequireWildcard(require("./estree/TransformComponentSyntax"));
35
+
36
+ var TransformEnumSyntax = _interopRequireWildcard(require("./estree/TransformEnumSyntax"));
35
37
 
36
38
  var TransformMatchSyntax = _interopRequireWildcard(require("./estree/TransformMatchSyntax"));
37
39
 
@@ -140,13 +142,14 @@ function parse(code, opts) {
140
142
  return estreeAST;
141
143
  }
142
144
 
143
- const loweredESTreeAST = [TransformMatchSyntax.transformProgram, StripComponentSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => transform(ast, options), estreeAST);
145
+ const loweredESTreeAST = [TransformEnumSyntax.transformProgram, TransformMatchSyntax.transformProgram, TransformComponentSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => transform(ast, options), estreeAST);
144
146
  return TransformESTreeToBabel.transformProgram(loweredESTreeAST, options);
145
147
  }
146
148
 
147
149
  const Transforms = {
150
+ transformEnumSyntax: TransformEnumSyntax.transformProgram,
148
151
  transformMatchSyntax: TransformMatchSyntax.transformProgram,
149
- stripComponentSyntax: StripComponentSyntax.transformProgram,
152
+ transformComponentSyntax: TransformComponentSyntax.transformProgram,
150
153
  stripFlowTypesForBabel: StripFlowTypesForBabel.transformProgram,
151
154
  stripFlowTypes: StripFlowTypes.transformProgram
152
155
  };
@@ -17,7 +17,8 @@ import type {BabelFile} from './babel/TransformESTreeToBabel';
17
17
  import * as HermesParser from './HermesParser';
18
18
  import HermesToESTreeAdapter from './HermesToESTreeAdapter';
19
19
  import FlowVisitorKeys from './generated/ESTreeVisitorKeys';
20
- import * as StripComponentSyntax from './estree/StripComponentSyntax';
20
+ import * as TransformComponentSyntax from './estree/TransformComponentSyntax';
21
+ import * as TransformEnumSyntax from './estree/TransformEnumSyntax';
21
22
  import * as TransformMatchSyntax from './estree/TransformMatchSyntax';
22
23
  import * as StripFlowTypesForBabel from './estree/StripFlowTypesForBabel';
23
24
  import * as TransformESTreeToBabel from './babel/TransformESTreeToBabel';
@@ -92,8 +93,9 @@ export function parse(
92
93
  }
93
94
 
94
95
  const loweredESTreeAST = [
96
+ TransformEnumSyntax.transformProgram,
95
97
  TransformMatchSyntax.transformProgram,
96
- StripComponentSyntax.transformProgram,
98
+ TransformComponentSyntax.transformProgram,
97
99
  StripFlowTypesForBabel.transformProgram,
98
100
  ].reduce((ast, transform) => transform(ast, options), estreeAST);
99
101
 
@@ -111,8 +113,9 @@ export * as astNodeMutationHelpers from './transform/astNodeMutationHelpers';
111
113
  export {default as mutateESTreeASTForPrettier} from './utils/mutateESTreeASTForPrettier';
112
114
 
113
115
  const Transforms = {
116
+ transformEnumSyntax: TransformEnumSyntax.transformProgram,
114
117
  transformMatchSyntax: TransformMatchSyntax.transformProgram,
115
- stripComponentSyntax: StripComponentSyntax.transformProgram,
118
+ transformComponentSyntax: TransformComponentSyntax.transformProgram,
116
119
  stripFlowTypesForBabel: StripFlowTypesForBabel.transformProgram,
117
120
  stripFlowTypes: StripFlowTypes.transformProgram,
118
121
  };
@@ -59,7 +59,7 @@ class HermesASTAdapter {
59
59
 
60
60
  if (resultNode.type !== 'Program') {
61
61
  throw new Error(`HermesToESTreeAdapter: Must return a Program node, instead of "${resultNode.type}". `);
62
- } // $FlowExpectedError[incompatible-return] We know this is a program at this point.
62
+ } // $FlowExpectedError[incompatible-type] We know this is a program at this point.
63
63
 
64
64
 
65
65
  return resultNode;
@@ -130,7 +130,7 @@ class HermesASTAdapter {
130
130
  }
131
131
 
132
132
  mapEmpty(_node) {
133
- // $FlowExpectedError
133
+ // $FlowExpectedError[incompatible-type]
134
134
  return null;
135
135
  }
136
136
 
@@ -201,7 +201,6 @@ class HermesParserDeserializer {
201
201
 
202
202
 
203
203
  addEmptyLoc() {
204
- // $FlowExpectedError
205
204
  const loc = {};
206
205
  this.locMap[this.next()] = loc;
207
206
  return loc;
@@ -14,5 +14,5 @@ exports.ParserOptionsKeys = void 0;
14
14
  *
15
15
  * @format
16
16
  */
17
- const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens']);
17
+ const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens', 'transformOptions']);
18
18
  exports.ParserOptionsKeys = ParserOptionsKeys;
@@ -126,7 +126,7 @@ function mapNodeWithDirectives(node) {
126
126
  break;
127
127
  }
128
128
  } // Move directives from body to new directives array
129
- // $FlowExpectedError[incompatible-call] We are adding properties for babel that don't exist in the ESTree types.
129
+ // $FlowExpectedError[incompatible-type] We are adding properties for babel that don't exist in the ESTree types.
130
130
 
131
131
 
132
132
  return nodeWith(node, {
@@ -189,7 +189,7 @@ function mapProgram(node) {
189
189
 
190
190
  return {
191
191
  type: 'File',
192
- // $FlowExpectedError[prop-missing] Comments, docblock and tokens are purposely missing to match the Babel AST.
192
+ // $FlowExpectedError[incompatible-type] Comments, docblock and tokens are purposely missing to match the Babel AST.
193
193
  program: {
194
194
  type: 'Program',
195
195
  body: program.body,
@@ -280,7 +280,7 @@ function mapProperty(node) {
280
280
  type: 'ObjectProperty',
281
281
  computed: node.computed,
282
282
  key: node.key,
283
- // $FlowExpectedError[incompatible-cast]
283
+ // $FlowExpectedError[incompatible-type]
284
284
  value: node.value,
285
285
  method: node.method,
286
286
  shorthand: node.shorthand,
@@ -398,10 +398,10 @@ function mapRestElement(node) {
398
398
  function mapImportExpression(node) {
399
399
  // Babel expects ImportExpression to be structured as a regular
400
400
  // CallExpression where the callee is an Import node.
401
- // $FlowExpectedError[prop-missing] optional and typeArguments are missing to match existing output.
401
+ // $FlowExpectedError[incompatible-type] optional and typeArguments are missing to match existing output.
402
402
  return {
403
403
  type: 'CallExpression',
404
- // $FlowExpectedError[incompatible-return] This is a babel specific node
404
+ // $FlowExpectedError[incompatible-type] This is a babel specific node
405
405
  callee: {
406
406
  type: 'Import',
407
407
  loc: {
@@ -480,10 +480,11 @@ function mapPropertyDefinition(node) {
480
480
  function mapTypeofTypeAnnotation(node) {
481
481
  // $FlowExpectedError[cannot-write]
482
482
  delete node.typeArguments; // $FlowFixMe[incompatible-type]
483
+ // $FlowFixMe[invalid-compare]
483
484
 
484
485
  if (node.argument.type !== 'GenericTypeAnnotation') {
485
486
  return nodeWith(node, {
486
- // $FlowExpectedError[incompatible-call] Special override for Babel
487
+ // $FlowExpectedError[incompatible-type] Special override for Babel
487
488
  argument: {
488
489
  type: 'GenericTypeAnnotation',
489
490
  id: node.argument,
@@ -656,6 +657,7 @@ function transformNode(node) {
656
657
 
657
658
  // Check if we have already processed this node.
658
659
  // $FlowFixMe[incompatible-type]
660
+ // $FlowFixMe[invalid-compare]
659
661
  if (((_node$parent = node.parent) == null ? void 0 : _node$parent.type) === 'File') {
660
662
  return node;
661
663
  }
@@ -1093,12 +1095,12 @@ function transformProgram(program, options) {
1093
1095
 
1094
1096
  const resultNode = _SimpleTransform.SimpleTransform.transform(program, {
1095
1097
  transform(node) {
1096
- // $FlowExpectedError[incompatible-call] We override the type to support the additional Babel types
1098
+ // $FlowExpectedError[incompatible-type] We override the type to support the additional Babel types
1097
1099
  return transformNode(node);
1098
1100
  },
1099
1101
 
1100
1102
  visitorKeys: FlowESTreeAndBabelVisitorKeys
1101
- }); // $FlowExpectedError[incompatible-call] We override the type to support the additional Babel types
1103
+ }); // $FlowExpectedError[incompatible-type] We override the type to support the additional Babel types
1102
1104
 
1103
1105
 
1104
1106
  _SimpleTraverser.SimpleTraverser.traverse(resultNode, {
@@ -1110,6 +1112,7 @@ function transformProgram(program, options) {
1110
1112
 
1111
1113
  visitorKeys: FlowESTreeAndBabelVisitorKeys
1112
1114
  }); // $FlowFixMe[incompatible-type]
1115
+ // $FlowFixMe[invalid-compare]
1113
1116
 
1114
1117
 
1115
1118
  if ((resultNode == null ? void 0 : resultNode.type) === 'File') {
@@ -191,7 +191,7 @@ function mapComponentParameters(params, options) {
191
191
 
192
192
  if (propsProperties.length === 0) {
193
193
  if (refParam == null) {
194
- throw new Error('StripComponentSyntax: Invalid state, ref should always be set at this point if props are empty');
194
+ throw new Error('TransformComponentSyntax: Invalid state, ref should always be set at this point if props are empty');
195
195
  }
196
196
 
197
197
  const emptyParamsLoc = {
@@ -757,7 +757,7 @@ function transformProgram(program, options) {
757
757
  {
758
758
  const consequent = mapStatementList(node.consequent, options);
759
759
  return nodeWith(node, {
760
- /* $FlowExpectedError[incompatible-call] We know `mapStatementList` will
760
+ /* $FlowExpectedError[incompatible-type] We know `mapStatementList` will
761
761
  not return `ModuleDeclaration` nodes if it is not passed any */
762
762
  consequent
763
763
  });