@react-native/codegen 0.72.5 → 0.73.0-nightly-20230603-fd9e295be

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 (72) hide show
  1. package/README.md +2 -2
  2. package/lib/CodegenSchema.d.ts +15 -4
  3. package/lib/CodegenSchema.js.flow +33 -21
  4. package/lib/generators/components/CppHelpers.js +39 -2
  5. package/lib/generators/components/CppHelpers.js.flow +54 -5
  6. package/lib/generators/components/GenerateEventEmitterCpp.js +238 -55
  7. package/lib/generators/components/GenerateEventEmitterCpp.js.flow +233 -55
  8. package/lib/generators/components/GenerateEventEmitterH.js +77 -28
  9. package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -32
  10. package/lib/generators/components/GeneratePropsH.js +1 -2
  11. package/lib/generators/components/GeneratePropsH.js.flow +1 -2
  12. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +0 -1
  13. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -5
  14. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +4 -0
  15. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +4 -0
  16. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +2 -0
  17. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +2 -0
  18. package/lib/generators/components/__test_fixtures__/fixtures.js +114 -1
  19. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +114 -1
  20. package/lib/generators/modules/GenerateModuleCpp.js +3 -3
  21. package/lib/generators/modules/GenerateModuleCpp.js.flow +3 -3
  22. package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
  23. package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
  24. package/lib/parsers/error-utils.js +44 -0
  25. package/lib/parsers/error-utils.js.flow +59 -0
  26. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +51 -0
  27. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +51 -0
  28. package/lib/parsers/flow/components/componentsUtils.js +6 -6
  29. package/lib/parsers/flow/components/componentsUtils.js.flow +10 -10
  30. package/lib/parsers/flow/components/events.js +157 -78
  31. package/lib/parsers/flow/components/events.js.flow +158 -77
  32. package/lib/parsers/flow/components/index.js +28 -105
  33. package/lib/parsers/flow/components/index.js.flow +21 -110
  34. package/lib/parsers/flow/modules/index.js +39 -49
  35. package/lib/parsers/flow/modules/index.js.flow +22 -31
  36. package/lib/parsers/flow/parser.d.ts +9 -2
  37. package/lib/parsers/flow/parser.js +167 -16
  38. package/lib/parsers/flow/parser.js.flow +209 -6
  39. package/lib/parsers/flow/utils.js +0 -63
  40. package/lib/parsers/flow/utils.js.flow +1 -77
  41. package/lib/parsers/parser.js.flow +141 -1
  42. package/lib/parsers/parserMock.js +165 -2
  43. package/lib/parsers/parserMock.js.flow +216 -2
  44. package/lib/parsers/parsers-commons.js +128 -9
  45. package/lib/parsers/parsers-commons.js.flow +182 -12
  46. package/lib/parsers/parsers-primitives.js +84 -35
  47. package/lib/parsers/parsers-primitives.js.flow +110 -35
  48. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +51 -0
  49. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +51 -0
  50. package/lib/parsers/typescript/components/componentsUtils.js +31 -7
  51. package/lib/parsers/typescript/components/componentsUtils.js.flow +31 -14
  52. package/lib/parsers/typescript/components/events.js +142 -67
  53. package/lib/parsers/typescript/components/events.js.flow +149 -68
  54. package/lib/parsers/typescript/components/extends.js +2 -49
  55. package/lib/parsers/typescript/components/extends.js.flow +1 -55
  56. package/lib/parsers/typescript/components/index.js +29 -109
  57. package/lib/parsers/typescript/components/index.js.flow +21 -116
  58. package/lib/parsers/typescript/modules/index.js +41 -50
  59. package/lib/parsers/typescript/modules/index.js.flow +23 -31
  60. package/lib/parsers/typescript/parser.d.ts +9 -2
  61. package/lib/parsers/typescript/parser.js +193 -7
  62. package/lib/parsers/typescript/parser.js.flow +235 -6
  63. package/lib/parsers/utils.js.flow +6 -0
  64. package/package.json +16 -5
  65. package/lib/parsers/flow/components/extends.js +0 -52
  66. package/lib/parsers/flow/components/extends.js.flow +0 -66
  67. package/lib/parsers/flow/components/props.js +0 -47
  68. package/lib/parsers/flow/components/props.js.flow +0 -60
  69. package/lib/parsers/typescript/components/props.js +0 -39
  70. package/lib/parsers/typescript/components/props.js.flow +0 -48
  71. package/lib/parsers/typescript/utils.js +0 -90
  72. package/lib/parsers/typescript/utils.js.flow +0 -104
@@ -14,103 +14,33 @@ const _require = require('./commands'),
14
14
  getCommands = _require.getCommands;
15
15
  const _require2 = require('./events'),
16
16
  getEvents = _require2.getEvents;
17
- const _require3 = require('./extends'),
18
- getExtendsProps = _require3.getExtendsProps,
19
- removeKnownExtends = _require3.removeKnownExtends;
20
- const _require4 = require('./props'),
21
- getProps = _require4.getProps;
22
- const _require5 = require('./componentsUtils.js'),
23
- getProperties = _require5.getProperties;
24
- const _require6 = require('../../error-utils'),
25
- throwIfMoreThanOneCodegenNativecommands =
26
- _require6.throwIfMoreThanOneCodegenNativecommands;
27
- const _require7 = require('../../parsers-commons'),
28
- createComponentConfig = _require7.createComponentConfig,
29
- findNativeComponentType = _require7.findNativeComponentType,
30
- getCommandOptions = _require7.getCommandOptions,
31
- getOptions = _require7.getOptions;
32
-
33
- // $FlowFixMe[signature-verification-failure] there's no flowtype for AST
34
- function findComponentConfig(ast, parser) {
35
- const foundConfigs = [];
36
- const defaultExports = ast.body.filter(
37
- node => node.type === 'ExportDefaultDeclaration',
38
- );
39
- defaultExports.forEach(statement => {
40
- findNativeComponentType(statement, foundConfigs, parser);
41
- });
42
- if (foundConfigs.length === 0) {
43
- throw new Error('Could not find component config for native component');
44
- }
45
- if (foundConfigs.length > 1) {
46
- throw new Error('Only one component is supported per file');
47
- }
48
- const foundConfig = foundConfigs[0];
49
- const namedExports = ast.body.filter(
50
- node => node.type === 'ExportNamedDeclaration',
51
- );
52
- const commandsTypeNames = namedExports
53
- .map(statement => {
54
- let callExpression;
55
- let calleeName;
56
- try {
57
- callExpression = statement.declaration.declarations[0].init;
58
- calleeName = callExpression.callee.name;
59
- } catch (e) {
60
- return;
61
- }
62
- if (calleeName !== 'codegenNativeCommands') {
63
- return;
64
- }
65
-
66
- // const statement.declaration.declarations[0].init
67
- if (callExpression.arguments.length !== 1) {
68
- throw new Error(
69
- 'codegenNativeCommands must be passed options including the supported commands',
70
- );
71
- }
72
- const typeArgumentParam = callExpression.typeArguments.params[0];
73
- if (typeArgumentParam.type !== 'GenericTypeAnnotation') {
74
- throw new Error(
75
- "codegenNativeCommands doesn't support inline definitions. Specify a file local type alias",
76
- );
77
- }
78
- return {
79
- commandTypeName: typeArgumentParam.id.name,
80
- commandOptionsExpression: callExpression.arguments[0],
81
- };
82
- })
83
- .filter(Boolean);
84
- throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
85
- return createComponentConfig(foundConfig, commandsTypeNames);
86
- }
87
- function getCommandProperties(
88
- /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
89
- * LTI update could not be added via codemod */
90
- commandTypeName,
91
- types,
92
- commandOptions,
93
- ) {
17
+ const _require3 = require('./componentsUtils.js'),
18
+ getProperties = _require3.getProperties;
19
+ const _require4 = require('../../error-utils'),
20
+ throwIfTypeAliasIsNotInterface = _require4.throwIfTypeAliasIsNotInterface;
21
+ const _require5 = require('../../parsers-commons'),
22
+ propertyNames = _require5.propertyNames,
23
+ getCommandOptions = _require5.getCommandOptions,
24
+ getOptions = _require5.getOptions,
25
+ findComponentConfig = _require5.findComponentConfig;
26
+ function getCommandProperties(ast, parser) {
27
+ const _findComponentConfig = findComponentConfig(ast, parser),
28
+ commandTypeName = _findComponentConfig.commandTypeName,
29
+ commandOptionsExpression = _findComponentConfig.commandOptionsExpression;
94
30
  if (commandTypeName == null) {
95
31
  return [];
96
32
  }
33
+ const types = parser.getTypes(ast);
97
34
  const typeAlias = types[commandTypeName];
98
- if (typeAlias.type !== 'InterfaceDeclaration') {
99
- throw new Error(
100
- `The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
101
- );
102
- }
103
- let properties;
104
- try {
105
- properties = typeAlias.body.properties;
106
- } catch (e) {
35
+ throwIfTypeAliasIsNotInterface(typeAlias, parser);
36
+ const properties = parser.bodyProperties(typeAlias);
37
+ if (!properties) {
107
38
  throw new Error(
108
39
  `Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
109
40
  );
110
41
  }
111
- const flowPropertyNames = properties
112
- .map(property => property && property.key && property.key.name)
113
- .filter(Boolean);
42
+ const flowPropertyNames = propertyNames(properties);
43
+ const commandOptions = getCommandOptions(commandOptionsExpression);
114
44
  if (commandOptions == null || commandOptions.supportedCommands == null) {
115
45
  throw new Error(
116
46
  'codegenNativeCommands must be given an options object with supportedCommands array',
@@ -133,25 +63,18 @@ function getCommandProperties(
133
63
 
134
64
  // $FlowFixMe[signature-verification-failure] there's no flowtype for AST
135
65
  function buildComponentSchema(ast, parser) {
136
- const _findComponentConfig = findComponentConfig(ast, parser),
137
- componentName = _findComponentConfig.componentName,
138
- propsTypeName = _findComponentConfig.propsTypeName,
139
- commandTypeName = _findComponentConfig.commandTypeName,
140
- commandOptionsExpression = _findComponentConfig.commandOptionsExpression,
141
- optionsExpression = _findComponentConfig.optionsExpression;
66
+ const _findComponentConfig2 = findComponentConfig(ast, parser),
67
+ componentName = _findComponentConfig2.componentName,
68
+ propsTypeName = _findComponentConfig2.propsTypeName,
69
+ optionsExpression = _findComponentConfig2.optionsExpression;
142
70
  const types = parser.getTypes(ast);
143
71
  const propProperties = getProperties(propsTypeName, types);
144
- const commandOptions = getCommandOptions(commandOptionsExpression);
145
- const commandProperties = getCommandProperties(
146
- commandTypeName,
147
- types,
148
- commandOptions,
149
- );
150
- const extendsProps = getExtendsProps(propProperties, types);
72
+ const commandProperties = getCommandProperties(ast, parser);
73
+ const _parser$getProps = parser.getProps(propProperties, types),
74
+ extendsProps = _parser$getProps.extendsProps,
75
+ props = _parser$getProps.props;
151
76
  const options = getOptions(optionsExpression);
152
- const nonExtendsProps = removeKnownExtends(propProperties, types);
153
- const props = getProps(nonExtendsProps, types);
154
- const events = getEvents(propProperties, types);
77
+ const events = getEvents(propProperties, types, parser);
155
78
  const commands = getCommands(commandProperties, types);
156
79
  return {
157
80
  filename: componentName,
@@ -10,121 +10,44 @@
10
10
 
11
11
  'use strict';
12
12
  import type {Parser} from '../../parser';
13
- import type {TypeDeclarationMap} from '../../utils';
14
- import type {CommandOptions} from '../../parsers-commons';
15
13
  import type {ComponentSchemaBuilderConfig} from '../../schema.js';
16
14
 
17
15
  const {getCommands} = require('./commands');
18
16
  const {getEvents} = require('./events');
19
- const {getExtendsProps, removeKnownExtends} = require('./extends');
20
- const {getProps} = require('./props');
21
17
  const {getProperties} = require('./componentsUtils.js');
22
- const {throwIfMoreThanOneCodegenNativecommands} = require('../../error-utils');
18
+ const {throwIfTypeAliasIsNotInterface} = require('../../error-utils');
23
19
  const {
24
- createComponentConfig,
25
- findNativeComponentType,
20
+ propertyNames,
26
21
  getCommandOptions,
27
22
  getOptions,
23
+ findComponentConfig,
28
24
  } = require('../../parsers-commons');
29
25
 
30
- // $FlowFixMe[signature-verification-failure] there's no flowtype for AST
31
- function findComponentConfig(ast: $FlowFixMe, parser: Parser) {
32
- const foundConfigs: Array<{[string]: string}> = [];
33
-
34
- const defaultExports = ast.body.filter(
35
- node => node.type === 'ExportDefaultDeclaration',
36
- );
37
-
38
- defaultExports.forEach(statement => {
39
- findNativeComponentType(statement, foundConfigs, parser);
40
- });
41
-
42
- if (foundConfigs.length === 0) {
43
- throw new Error('Could not find component config for native component');
44
- }
45
- if (foundConfigs.length > 1) {
46
- throw new Error('Only one component is supported per file');
47
- }
48
-
49
- const foundConfig = foundConfigs[0];
50
-
51
- const namedExports = ast.body.filter(
52
- node => node.type === 'ExportNamedDeclaration',
26
+ function getCommandProperties(ast: $FlowFixMe, parser: Parser) {
27
+ const {commandTypeName, commandOptionsExpression} = findComponentConfig(
28
+ ast,
29
+ parser,
53
30
  );
54
31
 
55
- const commandsTypeNames = namedExports
56
- .map(statement => {
57
- let callExpression;
58
- let calleeName;
59
- try {
60
- callExpression = statement.declaration.declarations[0].init;
61
- calleeName = callExpression.callee.name;
62
- } catch (e) {
63
- return;
64
- }
65
-
66
- if (calleeName !== 'codegenNativeCommands') {
67
- return;
68
- }
69
-
70
- // const statement.declaration.declarations[0].init
71
- if (callExpression.arguments.length !== 1) {
72
- throw new Error(
73
- 'codegenNativeCommands must be passed options including the supported commands',
74
- );
75
- }
76
-
77
- const typeArgumentParam = callExpression.typeArguments.params[0];
78
-
79
- if (typeArgumentParam.type !== 'GenericTypeAnnotation') {
80
- throw new Error(
81
- "codegenNativeCommands doesn't support inline definitions. Specify a file local type alias",
82
- );
83
- }
84
-
85
- return {
86
- commandTypeName: typeArgumentParam.id.name,
87
- commandOptionsExpression: callExpression.arguments[0],
88
- };
89
- })
90
- .filter(Boolean);
91
-
92
- throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
93
-
94
- return createComponentConfig(foundConfig, commandsTypeNames);
95
- }
96
-
97
- function getCommandProperties(
98
- /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
99
- * LTI update could not be added via codemod */
100
- commandTypeName,
101
- types: TypeDeclarationMap,
102
- commandOptions: ?CommandOptions,
103
- ) {
104
32
  if (commandTypeName == null) {
105
33
  return [];
106
34
  }
35
+ const types = parser.getTypes(ast);
107
36
 
108
37
  const typeAlias = types[commandTypeName];
109
38
 
110
- if (typeAlias.type !== 'InterfaceDeclaration') {
111
- throw new Error(
112
- `The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
113
- );
114
- }
39
+ throwIfTypeAliasIsNotInterface(typeAlias, parser);
115
40
 
116
- let properties;
117
- try {
118
- properties = typeAlias.body.properties;
119
- } catch (e) {
41
+ const properties = parser.bodyProperties(typeAlias);
42
+ if (!properties) {
120
43
  throw new Error(
121
44
  `Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
122
45
  );
123
46
  }
124
47
 
125
- const flowPropertyNames = properties
126
- .map(property => property && property.key && property.key.name)
127
- .filter(Boolean);
48
+ const flowPropertyNames = propertyNames(properties);
49
+
50
+ const commandOptions = getCommandOptions(commandOptionsExpression);
128
51
 
129
52
  if (commandOptions == null || commandOptions.supportedCommands == null) {
130
53
  throw new Error(
@@ -153,31 +76,19 @@ function buildComponentSchema(
153
76
  ast: $FlowFixMe,
154
77
  parser: Parser,
155
78
  ): ComponentSchemaBuilderConfig {
156
- const {
157
- componentName,
158
- propsTypeName,
159
- commandTypeName,
160
- commandOptionsExpression,
161
- optionsExpression,
162
- } = findComponentConfig(ast, parser);
79
+ const {componentName, propsTypeName, optionsExpression} = findComponentConfig(
80
+ ast,
81
+ parser,
82
+ );
163
83
 
164
84
  const types = parser.getTypes(ast);
165
85
 
166
86
  const propProperties = getProperties(propsTypeName, types);
167
- const commandOptions = getCommandOptions(commandOptionsExpression);
87
+ const commandProperties = getCommandProperties(ast, parser);
88
+ const {extendsProps, props} = parser.getProps(propProperties, types);
168
89
 
169
- const commandProperties = getCommandProperties(
170
- commandTypeName,
171
- types,
172
- commandOptions,
173
- );
174
-
175
- const extendsProps = getExtendsProps(propProperties, types);
176
90
  const options = getOptions(optionsExpression);
177
-
178
- const nonExtendsProps = removeKnownExtends(propProperties, types);
179
- const props = getProps(nonExtendsProps, types);
180
- const events = getEvents(propProperties, types);
91
+ const events = getEvents(propProperties, types, parser);
181
92
  const commands = getCommands(commandProperties, types);
182
93
 
183
94
  return {
@@ -78,33 +78,26 @@ function _iterableToArrayLimit(arr, i) {
78
78
  function _arrayWithHoles(arr) {
79
79
  if (Array.isArray(arr)) return arr;
80
80
  }
81
- const _require = require('../utils'),
82
- resolveTypeAnnotation = _require.resolveTypeAnnotation;
83
- const _require2 = require('../../parsers-commons'),
84
- unwrapNullable = _require2.unwrapNullable,
85
- wrapNullable = _require2.wrapNullable,
81
+ const _require = require('../../parsers-commons'),
82
+ unwrapNullable = _require.unwrapNullable,
83
+ wrapNullable = _require.wrapNullable,
86
84
  assertGenericTypeAnnotationHasExactlyOneTypeParameter =
87
- _require2.assertGenericTypeAnnotationHasExactlyOneTypeParameter,
88
- parseObjectProperty = _require2.parseObjectProperty;
89
- const _require3 = require('../../parsers-primitives'),
90
- emitArrayType = _require3.emitArrayType,
91
- emitBoolean = _require3.emitBoolean,
92
- emitFunction = _require3.emitFunction,
93
- emitNumber = _require3.emitNumber,
94
- emitGenericObject = _require3.emitGenericObject,
95
- emitPromise = _require3.emitPromise,
96
- emitRootTag = _require3.emitRootTag,
97
- emitVoid = _require3.emitVoid,
98
- emitString = _require3.emitString,
99
- emitMixed = _require3.emitMixed,
100
- emitUnion = _require3.emitUnion,
101
- emitCommonTypes = _require3.emitCommonTypes,
102
- typeAliasResolution = _require3.typeAliasResolution,
103
- typeEnumResolution = _require3.typeEnumResolution;
104
- const _require4 = require('../../errors'),
85
+ _require.assertGenericTypeAnnotationHasExactlyOneTypeParameter,
86
+ parseObjectProperty = _require.parseObjectProperty;
87
+ const _require2 = require('../../parsers-primitives'),
88
+ emitArrayType = _require2.emitArrayType,
89
+ emitFunction = _require2.emitFunction,
90
+ emitDictionary = _require2.emitDictionary,
91
+ emitPromise = _require2.emitPromise,
92
+ emitRootTag = _require2.emitRootTag,
93
+ emitUnion = _require2.emitUnion,
94
+ emitCommonTypes = _require2.emitCommonTypes,
95
+ typeAliasResolution = _require2.typeAliasResolution,
96
+ typeEnumResolution = _require2.typeEnumResolution;
97
+ const _require3 = require('../../errors'),
105
98
  UnsupportedTypeAnnotationParserError =
106
- _require4.UnsupportedTypeAnnotationParserError,
107
- UnsupportedGenericParserError = _require4.UnsupportedGenericParserError;
99
+ _require3.UnsupportedTypeAnnotationParserError,
100
+ UnsupportedGenericParserError = _require3.UnsupportedGenericParserError;
108
101
  function translateTypeAnnotation(
109
102
  hasteModuleName,
110
103
  /**
@@ -118,9 +111,11 @@ function translateTypeAnnotation(
118
111
  cxxOnly,
119
112
  parser,
120
113
  ) {
121
- const _resolveTypeAnnotatio = resolveTypeAnnotation(
114
+ const resolveTypeAnnotationFN = parser.getResolveTypeAnnotationFN();
115
+ const _resolveTypeAnnotatio = resolveTypeAnnotationFN(
122
116
  flowTypeAnnotation,
123
117
  types,
118
+ parser,
124
119
  ),
125
120
  nullable = _resolveTypeAnnotatio.nullable,
126
121
  typeAnnotation = _resolveTypeAnnotatio.typeAnnotation,
@@ -215,7 +210,7 @@ function translateTypeAnnotation(
215
210
  // check the property type to prevent developers from using unsupported types
216
211
  // the return value from `translateTypeAnnotation` is unused
217
212
  const propertyType = indexers[0].value;
218
- translateTypeAnnotation(
213
+ const valueType = translateTypeAnnotation(
219
214
  hasteModuleName,
220
215
  propertyType,
221
216
  types,
@@ -226,7 +221,7 @@ function translateTypeAnnotation(
226
221
  parser,
227
222
  );
228
223
  // no need to do further checking
229
- return emitGenericObject(nullable);
224
+ return emitDictionary(nullable, valueType);
230
225
  }
231
226
  }
232
227
  const objectTypeAnnotation = {
@@ -258,18 +253,6 @@ function translateTypeAnnotation(
258
253
  nullable,
259
254
  );
260
255
  }
261
- case 'BooleanTypeAnnotation': {
262
- return emitBoolean(nullable);
263
- }
264
- case 'NumberTypeAnnotation': {
265
- return emitNumber(nullable);
266
- }
267
- case 'VoidTypeAnnotation': {
268
- return emitVoid(nullable);
269
- }
270
- case 'StringTypeAnnotation': {
271
- return emitString(nullable);
272
- }
273
256
  case 'FunctionTypeAnnotation': {
274
257
  return emitFunction(
275
258
  nullable,
@@ -294,13 +277,6 @@ function translateTypeAnnotation(
294
277
  memberType: 'StringTypeAnnotation',
295
278
  });
296
279
  }
297
- case 'MixedTypeAnnotation': {
298
- if (cxxOnly) {
299
- return emitMixed(nullable);
300
- } else {
301
- return emitGenericObject(nullable);
302
- }
303
- }
304
280
  case 'EnumStringBody':
305
281
  case 'EnumNumberBody': {
306
282
  return typeEnumResolution(
@@ -313,11 +289,25 @@ function translateTypeAnnotation(
313
289
  );
314
290
  }
315
291
  default: {
316
- throw new UnsupportedTypeAnnotationParserError(
292
+ const commonType = emitCommonTypes(
317
293
  hasteModuleName,
294
+ types,
318
295
  typeAnnotation,
319
- parser.language(),
296
+ aliasMap,
297
+ enumMap,
298
+ tryParse,
299
+ cxxOnly,
300
+ nullable,
301
+ parser,
320
302
  );
303
+ if (!commonType) {
304
+ throw new UnsupportedTypeAnnotationParserError(
305
+ hasteModuleName,
306
+ typeAnnotation,
307
+ parser.language(),
308
+ );
309
+ }
310
+ return commonType;
321
311
  }
322
312
  }
323
313
  }
@@ -22,7 +22,6 @@ import type {
22
22
  import type {Parser} from '../../parser';
23
23
  import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
24
24
 
25
- const {resolveTypeAnnotation} = require('../utils');
26
25
  const {
27
26
  unwrapNullable,
28
27
  wrapNullable,
@@ -31,15 +30,10 @@ const {
31
30
  } = require('../../parsers-commons');
32
31
  const {
33
32
  emitArrayType,
34
- emitBoolean,
35
33
  emitFunction,
36
- emitNumber,
37
- emitGenericObject,
34
+ emitDictionary,
38
35
  emitPromise,
39
36
  emitRootTag,
40
- emitVoid,
41
- emitString,
42
- emitMixed,
43
37
  emitUnion,
44
38
  emitCommonTypes,
45
39
  typeAliasResolution,
@@ -64,8 +58,9 @@ function translateTypeAnnotation(
64
58
  cxxOnly: boolean,
65
59
  parser: Parser,
66
60
  ): Nullable<NativeModuleTypeAnnotation> {
61
+ const resolveTypeAnnotationFN = parser.getResolveTypeAnnotationFN();
67
62
  const {nullable, typeAnnotation, typeResolutionStatus} =
68
- resolveTypeAnnotation(flowTypeAnnotation, types);
63
+ resolveTypeAnnotationFN(flowTypeAnnotation, types, parser);
69
64
 
70
65
  switch (typeAnnotation.type) {
71
66
  case 'GenericTypeAnnotation': {
@@ -157,7 +152,7 @@ function translateTypeAnnotation(
157
152
  // check the property type to prevent developers from using unsupported types
158
153
  // the return value from `translateTypeAnnotation` is unused
159
154
  const propertyType = indexers[0].value;
160
- translateTypeAnnotation(
155
+ const valueType = translateTypeAnnotation(
161
156
  hasteModuleName,
162
157
  propertyType,
163
158
  types,
@@ -168,7 +163,7 @@ function translateTypeAnnotation(
168
163
  parser,
169
164
  );
170
165
  // no need to do further checking
171
- return emitGenericObject(nullable);
166
+ return emitDictionary(nullable, valueType);
172
167
  }
173
168
  }
174
169
 
@@ -207,18 +202,6 @@ function translateTypeAnnotation(
207
202
  nullable,
208
203
  );
209
204
  }
210
- case 'BooleanTypeAnnotation': {
211
- return emitBoolean(nullable);
212
- }
213
- case 'NumberTypeAnnotation': {
214
- return emitNumber(nullable);
215
- }
216
- case 'VoidTypeAnnotation': {
217
- return emitVoid(nullable);
218
- }
219
- case 'StringTypeAnnotation': {
220
- return emitString(nullable);
221
- }
222
205
  case 'FunctionTypeAnnotation': {
223
206
  return emitFunction(
224
207
  nullable,
@@ -243,13 +226,6 @@ function translateTypeAnnotation(
243
226
  memberType: 'StringTypeAnnotation',
244
227
  });
245
228
  }
246
- case 'MixedTypeAnnotation': {
247
- if (cxxOnly) {
248
- return emitMixed(nullable);
249
- } else {
250
- return emitGenericObject(nullable);
251
- }
252
- }
253
229
  case 'EnumStringBody':
254
230
  case 'EnumNumberBody': {
255
231
  return typeEnumResolution(
@@ -262,11 +238,26 @@ function translateTypeAnnotation(
262
238
  );
263
239
  }
264
240
  default: {
265
- throw new UnsupportedTypeAnnotationParserError(
241
+ const commonType = emitCommonTypes(
266
242
  hasteModuleName,
243
+ types,
267
244
  typeAnnotation,
268
- parser.language(),
245
+ aliasMap,
246
+ enumMap,
247
+ tryParse,
248
+ cxxOnly,
249
+ nullable,
250
+ parser,
269
251
  );
252
+
253
+ if (!commonType) {
254
+ throw new UnsupportedTypeAnnotationParserError(
255
+ hasteModuleName,
256
+ typeAnnotation,
257
+ parser.language(),
258
+ );
259
+ }
260
+ return commonType;
270
261
  }
271
262
  }
272
263
  }
@@ -5,6 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {Parser} from '../parser';
8
+ import type { Parser } from '../parser';
9
+ import type { SchemaType } from '../../CodegenSchema';
10
+ import type { ParserType } from '../errors';
9
11
 
10
- export declare class FlowParser implements Parser{}
12
+ export declare class FlowParser implements Parser {
13
+ language(): ParserType;
14
+ parseFile(filename: string): SchemaType;
15
+ parseString(contents: string, filename?: string): SchemaType;
16
+ parseModuleFixture(filename: string): SchemaType;
17
+ }