@react-native/codegen 0.72.4 → 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 (74) 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/GenerateModuleH.js +1 -1
  23. package/lib/generators/modules/GenerateModuleH.js.flow +1 -1
  24. package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
  25. package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
  26. package/lib/parsers/error-utils.js +44 -0
  27. package/lib/parsers/error-utils.js.flow +59 -0
  28. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +51 -0
  29. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +51 -0
  30. package/lib/parsers/flow/components/componentsUtils.js +6 -6
  31. package/lib/parsers/flow/components/componentsUtils.js.flow +10 -10
  32. package/lib/parsers/flow/components/events.js +157 -78
  33. package/lib/parsers/flow/components/events.js.flow +158 -77
  34. package/lib/parsers/flow/components/index.js +28 -105
  35. package/lib/parsers/flow/components/index.js.flow +21 -110
  36. package/lib/parsers/flow/modules/index.js +39 -49
  37. package/lib/parsers/flow/modules/index.js.flow +22 -31
  38. package/lib/parsers/flow/parser.d.ts +9 -2
  39. package/lib/parsers/flow/parser.js +167 -16
  40. package/lib/parsers/flow/parser.js.flow +209 -6
  41. package/lib/parsers/flow/utils.js +0 -63
  42. package/lib/parsers/flow/utils.js.flow +1 -77
  43. package/lib/parsers/parser.js.flow +141 -1
  44. package/lib/parsers/parserMock.js +165 -2
  45. package/lib/parsers/parserMock.js.flow +216 -2
  46. package/lib/parsers/parsers-commons.js +128 -9
  47. package/lib/parsers/parsers-commons.js.flow +182 -12
  48. package/lib/parsers/parsers-primitives.js +84 -35
  49. package/lib/parsers/parsers-primitives.js.flow +110 -35
  50. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +51 -0
  51. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +51 -0
  52. package/lib/parsers/typescript/components/componentsUtils.js +31 -7
  53. package/lib/parsers/typescript/components/componentsUtils.js.flow +31 -14
  54. package/lib/parsers/typescript/components/events.js +142 -67
  55. package/lib/parsers/typescript/components/events.js.flow +149 -68
  56. package/lib/parsers/typescript/components/extends.js +2 -49
  57. package/lib/parsers/typescript/components/extends.js.flow +1 -55
  58. package/lib/parsers/typescript/components/index.js +29 -109
  59. package/lib/parsers/typescript/components/index.js.flow +21 -116
  60. package/lib/parsers/typescript/modules/index.js +41 -50
  61. package/lib/parsers/typescript/modules/index.js.flow +23 -31
  62. package/lib/parsers/typescript/parser.d.ts +9 -2
  63. package/lib/parsers/typescript/parser.js +193 -7
  64. package/lib/parsers/typescript/parser.js.flow +235 -6
  65. package/lib/parsers/utils.js.flow +6 -0
  66. package/package.json +26 -15
  67. package/lib/parsers/flow/components/extends.js +0 -52
  68. package/lib/parsers/flow/components/extends.js.flow +0 -66
  69. package/lib/parsers/flow/components/props.js +0 -47
  70. package/lib/parsers/flow/components/props.js.flow +0 -60
  71. package/lib/parsers/typescript/components/props.js +0 -39
  72. package/lib/parsers/typescript/components/props.js.flow +0 -48
  73. package/lib/parsers/typescript/utils.js +0 -90
  74. package/lib/parsers/typescript/utils.js.flow +0 -104
@@ -280,6 +280,44 @@ function throwIfMoreThanOneCodegenNativecommands(commandsTypeNames) {
280
280
  throw new Error('codegenNativeCommands may only be called once in a file');
281
281
  }
282
282
  }
283
+ function throwIfConfigNotfound(foundConfigs) {
284
+ if (foundConfigs.length === 0) {
285
+ throw new Error('Could not find component config for native component');
286
+ }
287
+ }
288
+ function throwIfMoreThanOneConfig(foundConfigs) {
289
+ if (foundConfigs.length > 1) {
290
+ throw new Error('Only one component is supported per file');
291
+ }
292
+ }
293
+ function throwIfEventHasNoName(typeAnnotation, parser) {
294
+ const name =
295
+ parser.language() === 'Flow' ? typeAnnotation.id : typeAnnotation.typeName;
296
+ if (!name) {
297
+ throw new Error("typeAnnotation of event doesn't have a name");
298
+ }
299
+ }
300
+ function throwIfBubblingTypeIsNull(bubblingType, eventName) {
301
+ if (!bubblingType) {
302
+ throw new Error(
303
+ `Unable to determine event bubbling type for "${eventName}"`,
304
+ );
305
+ }
306
+ return bubblingType;
307
+ }
308
+ function throwIfArgumentPropsAreNull(argumentProps, eventName) {
309
+ if (!argumentProps) {
310
+ throw new Error(`Unable to determine event arguments for "${eventName}"`);
311
+ }
312
+ return argumentProps;
313
+ }
314
+ function throwIfTypeAliasIsNotInterface(typeAlias, parser) {
315
+ if (typeAlias.type !== parser.interfaceDeclaration) {
316
+ throw new Error(
317
+ `The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
318
+ );
319
+ }
320
+ }
283
321
  module.exports = {
284
322
  throwIfModuleInterfaceIsMisnamed,
285
323
  throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
@@ -298,4 +336,10 @@ module.exports = {
298
336
  throwIfPartialNotAnnotatingTypeParameter,
299
337
  throwIfPartialWithMoreParameter,
300
338
  throwIfMoreThanOneCodegenNativecommands,
339
+ throwIfConfigNotfound,
340
+ throwIfMoreThanOneConfig,
341
+ throwIfEventHasNoName,
342
+ throwIfBubblingTypeIsNull,
343
+ throwIfArgumentPropsAreNull,
344
+ throwIfTypeAliasIsNotInterface,
301
345
  };
@@ -298,6 +298,59 @@ function throwIfMoreThanOneCodegenNativecommands(
298
298
  }
299
299
  }
300
300
 
301
+ function throwIfConfigNotfound(foundConfigs: Array<{[string]: string}>) {
302
+ if (foundConfigs.length === 0) {
303
+ throw new Error('Could not find component config for native component');
304
+ }
305
+ }
306
+
307
+ function throwIfMoreThanOneConfig(foundConfigs: Array<{[string]: string}>) {
308
+ if (foundConfigs.length > 1) {
309
+ throw new Error('Only one component is supported per file');
310
+ }
311
+ }
312
+
313
+ function throwIfEventHasNoName(typeAnnotation: $FlowFixMe, parser: Parser) {
314
+ const name =
315
+ parser.language() === 'Flow' ? typeAnnotation.id : typeAnnotation.typeName;
316
+
317
+ if (!name) {
318
+ throw new Error("typeAnnotation of event doesn't have a name");
319
+ }
320
+ }
321
+
322
+ function throwIfBubblingTypeIsNull(
323
+ bubblingType: ?('direct' | 'bubble'),
324
+ eventName: string,
325
+ ): 'direct' | 'bubble' {
326
+ if (!bubblingType) {
327
+ throw new Error(
328
+ `Unable to determine event bubbling type for "${eventName}"`,
329
+ );
330
+ }
331
+
332
+ return bubblingType;
333
+ }
334
+
335
+ function throwIfArgumentPropsAreNull(
336
+ argumentProps: ?$ReadOnlyArray<$FlowFixMe>,
337
+ eventName: string,
338
+ ): $ReadOnlyArray<$FlowFixMe> {
339
+ if (!argumentProps) {
340
+ throw new Error(`Unable to determine event arguments for "${eventName}"`);
341
+ }
342
+
343
+ return argumentProps;
344
+ }
345
+
346
+ function throwIfTypeAliasIsNotInterface(typeAlias: $FlowFixMe, parser: Parser) {
347
+ if (typeAlias.type !== parser.interfaceDeclaration) {
348
+ throw new Error(
349
+ `The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
350
+ );
351
+ }
352
+ }
353
+
301
354
  module.exports = {
302
355
  throwIfModuleInterfaceIsMisnamed,
303
356
  throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
@@ -316,4 +369,10 @@ module.exports = {
316
369
  throwIfPartialNotAnnotatingTypeParameter,
317
370
  throwIfPartialWithMoreParameter,
318
371
  throwIfMoreThanOneCodegenNativecommands,
372
+ throwIfConfigNotfound,
373
+ throwIfMoreThanOneConfig,
374
+ throwIfEventHasNoName,
375
+ throwIfBubblingTypeIsNull,
376
+ throwIfArgumentPropsAreNull,
377
+ throwIfTypeAliasIsNotInterface,
319
378
  };
@@ -84,6 +84,57 @@ const EVENT_DEFINITION = `
84
84
  object_readonly_optional_both?: ?$ReadOnly<{
85
85
  int32_optional_both?: ?Int32,
86
86
  }>,
87
+
88
+ boolean_array_required: $ReadOnlyArray<boolean>,
89
+ boolean_array_optional_key?: boolean[],
90
+ boolean_array_optional_value: ?$ReadOnlyArray<boolean>,
91
+ boolean_array_optional_both?: ?boolean[],
92
+
93
+ string_array_required: $ReadOnlyArray<string>,
94
+ string_array_optional_key?: string[],
95
+ string_array_optional_value: ?$ReadOnlyArray<string>,
96
+ string_array_optional_both?: ?string[],
97
+
98
+ double_array_required: $ReadOnlyArray<Double>,
99
+ double_array_optional_key?: Double[],
100
+ double_array_optional_value: ?$ReadOnlyArray<Double>,
101
+ double_array_optional_both?: ?Double[],
102
+
103
+ float_array_required: $ReadOnlyArray<Float>,
104
+ float_array_optional_key?: Float[],
105
+ float_array_optional_value: ?$ReadOnlyArray<Float>,
106
+ float_array_optional_both?: ?Float[],
107
+
108
+ int32_array_required: $ReadOnlyArray<Int32>,
109
+ int32_array_optional_key?: Int32[],
110
+ int32_array_optional_value: ?$ReadOnlyArray<Int32>,
111
+ int32_array_optional_both?: ?Int32[],
112
+
113
+ enum_array_required: $ReadOnlyArray<('small' | 'large')>,
114
+ enum_array_optional_key?: ('small' | 'large')[],
115
+ enum_array_optional_value: ?$ReadOnlyArray<('small' | 'large')>,
116
+ enum_array_optional_both?: ?('small' | 'large')[],
117
+
118
+ object_array_required: $ReadOnlyArray<{
119
+ boolean_required: boolean,
120
+ }>,
121
+
122
+ object_array_optional_key?: {
123
+ string_optional_key?: string,
124
+ }[],
125
+
126
+ object_array_optional_value: ?$ReadOnlyArray<{
127
+ float_optional_value: ?Float,
128
+ }>,
129
+
130
+ object_array_optional_both?: ?{
131
+ int32_optional_both?: ?Int32,
132
+ }[],
133
+
134
+ int32_array_array_required: $ReadOnlyArray<$ReadOnlyArray<Int32>>,
135
+ int32_array_array_optional_key?: Int32[][],
136
+ int32_array_array_optional_value: ?$ReadOnlyArray<$ReadOnlyArray<Int32>>,
137
+ int32_array_array_optional_both?: ?Int32[][],
87
138
  `;
88
139
  const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
89
140
  /**
@@ -84,6 +84,57 @@ const EVENT_DEFINITION = `
84
84
  object_readonly_optional_both?: ?$ReadOnly<{
85
85
  int32_optional_both?: ?Int32,
86
86
  }>,
87
+
88
+ boolean_array_required: $ReadOnlyArray<boolean>,
89
+ boolean_array_optional_key?: boolean[],
90
+ boolean_array_optional_value: ?$ReadOnlyArray<boolean>,
91
+ boolean_array_optional_both?: ?boolean[],
92
+
93
+ string_array_required: $ReadOnlyArray<string>,
94
+ string_array_optional_key?: string[],
95
+ string_array_optional_value: ?$ReadOnlyArray<string>,
96
+ string_array_optional_both?: ?string[],
97
+
98
+ double_array_required: $ReadOnlyArray<Double>,
99
+ double_array_optional_key?: Double[],
100
+ double_array_optional_value: ?$ReadOnlyArray<Double>,
101
+ double_array_optional_both?: ?Double[],
102
+
103
+ float_array_required: $ReadOnlyArray<Float>,
104
+ float_array_optional_key?: Float[],
105
+ float_array_optional_value: ?$ReadOnlyArray<Float>,
106
+ float_array_optional_both?: ?Float[],
107
+
108
+ int32_array_required: $ReadOnlyArray<Int32>,
109
+ int32_array_optional_key?: Int32[],
110
+ int32_array_optional_value: ?$ReadOnlyArray<Int32>,
111
+ int32_array_optional_both?: ?Int32[],
112
+
113
+ enum_array_required: $ReadOnlyArray<('small' | 'large')>,
114
+ enum_array_optional_key?: ('small' | 'large')[],
115
+ enum_array_optional_value: ?$ReadOnlyArray<('small' | 'large')>,
116
+ enum_array_optional_both?: ?('small' | 'large')[],
117
+
118
+ object_array_required: $ReadOnlyArray<{
119
+ boolean_required: boolean,
120
+ }>,
121
+
122
+ object_array_optional_key?: {
123
+ string_optional_key?: string,
124
+ }[],
125
+
126
+ object_array_optional_value: ?$ReadOnlyArray<{
127
+ float_optional_value: ?Float,
128
+ }>,
129
+
130
+ object_array_optional_both?: ?{
131
+ int32_optional_both?: ?Int32,
132
+ }[],
133
+
134
+ int32_array_array_required: $ReadOnlyArray<$ReadOnlyArray<Int32>>,
135
+ int32_array_array_optional_key?: Int32[][],
136
+ int32_array_array_optional_value: ?$ReadOnlyArray<$ReadOnlyArray<Int32>>,
137
+ int32_array_array_optional_both?: ?Int32[][],
87
138
  `;
88
139
 
89
140
  const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
@@ -27,6 +27,7 @@ function getTypeAnnotationForArray(
27
27
  typeAnnotation,
28
28
  defaultValue,
29
29
  types,
30
+ parser,
30
31
  buildSchema,
31
32
  ) {
32
33
  const extractedTypeAnnotation = getValueFromTypes(typeAnnotation, types);
@@ -53,7 +54,7 @@ function getTypeAnnotationForArray(
53
54
  objectType.typeParameters.params[0].properties,
54
55
  types,
55
56
  )
56
- .map(prop => buildSchema(prop, types))
57
+ .map(prop => buildSchema(prop, types, parser))
57
58
  .filter(Boolean),
58
59
  };
59
60
  }
@@ -72,7 +73,7 @@ function getTypeAnnotationForArray(
72
73
  nestedObjectType.typeParameters.params[0].properties,
73
74
  types,
74
75
  )
75
- .map(prop => buildSchema(prop, types))
76
+ .map(prop => buildSchema(prop, types, parser))
76
77
  .filter(Boolean),
77
78
  },
78
79
  };
@@ -208,6 +209,7 @@ function getTypeAnnotation(
208
209
  defaultValue,
209
210
  withNullDefault,
210
211
  types,
212
+ parser,
211
213
  buildSchema,
212
214
  ) {
213
215
  const typeAnnotation = getValueFromTypes(annotation, types);
@@ -222,6 +224,7 @@ function getTypeAnnotation(
222
224
  typeAnnotation.typeParameters.params[0],
223
225
  defaultValue,
224
226
  types,
227
+ parser,
225
228
  buildSchema,
226
229
  ),
227
230
  };
@@ -236,7 +239,7 @@ function getTypeAnnotation(
236
239
  typeAnnotation.typeParameters.params[0].properties,
237
240
  types,
238
241
  )
239
- .map(prop => buildSchema(prop, types))
242
+ .map(prop => buildSchema(prop, types, parser))
240
243
  .filter(Boolean),
241
244
  };
242
245
  }
@@ -449,9 +452,6 @@ function getSchemaInfo(property, types) {
449
452
  withNullDefault,
450
453
  };
451
454
  }
452
-
453
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
454
-
455
455
  module.exports = {
456
456
  getProperties,
457
457
  getSchemaInfo,
@@ -10,10 +10,10 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- import type {ASTNode} from '../utils';
14
13
  import type {NamedShape} from '../../../CodegenSchema.js';
15
14
  const {getValueFromTypes} = require('../utils.js');
16
- import type {TypeDeclarationMap} from '../../utils';
15
+ import type {TypeDeclarationMap, PropAST, ASTNode} from '../../utils';
16
+ import type {BuildSchemaFN, Parser} from '../../parser';
17
17
 
18
18
  function getProperties(
19
19
  typeName: string,
@@ -34,7 +34,8 @@ function getTypeAnnotationForArray<+T>(
34
34
  typeAnnotation: $FlowFixMe,
35
35
  defaultValue: $FlowFixMe | null,
36
36
  types: TypeDeclarationMap,
37
- buildSchema: (property: PropAST, types: TypeDeclarationMap) => ?NamedShape<T>,
37
+ parser: Parser,
38
+ buildSchema: BuildSchemaFN<T>,
38
39
  ): $FlowFixMe {
39
40
  const extractedTypeAnnotation = getValueFromTypes(typeAnnotation, types);
40
41
  if (extractedTypeAnnotation.type === 'NullableTypeAnnotation') {
@@ -63,7 +64,7 @@ function getTypeAnnotationForArray<+T>(
63
64
  objectType.typeParameters.params[0].properties,
64
65
  types,
65
66
  )
66
- .map(prop => buildSchema(prop, types))
67
+ .map(prop => buildSchema(prop, types, parser))
67
68
  .filter(Boolean),
68
69
  };
69
70
  }
@@ -84,7 +85,7 @@ function getTypeAnnotationForArray<+T>(
84
85
  nestedObjectType.typeParameters.params[0].properties,
85
86
  types,
86
87
  )
87
- .map(prop => buildSchema(prop, types))
88
+ .map(prop => buildSchema(prop, types, parser))
88
89
  .filter(Boolean),
89
90
  },
90
91
  };
@@ -233,7 +234,8 @@ function getTypeAnnotation<+T>(
233
234
  defaultValue: $FlowFixMe | null,
234
235
  withNullDefault: boolean,
235
236
  types: TypeDeclarationMap,
236
- buildSchema: (property: PropAST, types: TypeDeclarationMap) => ?NamedShape<T>,
237
+ parser: Parser,
238
+ buildSchema: BuildSchemaFN<T>,
237
239
  ): $FlowFixMe {
238
240
  const typeAnnotation = getValueFromTypes(annotation, types);
239
241
 
@@ -248,6 +250,7 @@ function getTypeAnnotation<+T>(
248
250
  typeAnnotation.typeParameters.params[0],
249
251
  defaultValue,
250
252
  types,
253
+ parser,
251
254
  buildSchema,
252
255
  ),
253
256
  };
@@ -263,7 +266,7 @@ function getTypeAnnotation<+T>(
263
266
  typeAnnotation.typeParameters.params[0].properties,
264
267
  types,
265
268
  )
266
- .map(prop => buildSchema(prop, types))
269
+ .map(prop => buildSchema(prop, types, parser))
267
270
  .filter(Boolean),
268
271
  };
269
272
  }
@@ -499,9 +502,6 @@ function getSchemaInfo(
499
502
  };
500
503
  }
501
504
 
502
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
503
- type PropAST = Object;
504
-
505
505
  module.exports = {
506
506
  getProperties,
507
507
  getSchemaInfo,