@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
@@ -14,7 +14,9 @@ import type {
14
14
  Nullable,
15
15
  BooleanTypeAnnotation,
16
16
  DoubleTypeAnnotation,
17
+ EventTypeAnnotation,
17
18
  Int32TypeAnnotation,
19
+ NamedShape,
18
20
  NativeModuleAliasMap,
19
21
  NativeModuleEnumMap,
20
22
  NativeModuleBaseTypeAnnotation,
@@ -95,6 +97,19 @@ function emitDouble(nullable: boolean): Nullable<DoubleTypeAnnotation> {
95
97
  });
96
98
  }
97
99
 
100
+ function emitDoubleProp(
101
+ name: string,
102
+ optional: boolean,
103
+ ): NamedShape<DoubleTypeAnnotation> {
104
+ return {
105
+ name,
106
+ optional,
107
+ typeAnnotation: {
108
+ type: 'DoubleTypeAnnotation',
109
+ },
110
+ };
111
+ }
112
+
98
113
  function emitVoid(nullable: boolean): Nullable<VoidTypeAnnotation> {
99
114
  return wrapNullable(nullable, {
100
115
  type: 'VoidTypeAnnotation',
@@ -148,6 +163,19 @@ function emitString(nullable: boolean): Nullable<StringTypeAnnotation> {
148
163
  });
149
164
  }
150
165
 
166
+ function emitStringProp(
167
+ name: string,
168
+ optional: boolean,
169
+ ): NamedShape<StringTypeAnnotation> {
170
+ return {
171
+ name,
172
+ optional,
173
+ typeAnnotation: {
174
+ type: 'StringTypeAnnotation',
175
+ },
176
+ };
177
+ }
178
+
151
179
  function typeAliasResolution(
152
180
  typeResolution: TypeResolutionStatus,
153
181
  objectTypeAnnotation: ObjectTypeAnnotation<
@@ -309,6 +337,16 @@ function emitGenericObject(
309
337
  });
310
338
  }
311
339
 
340
+ function emitDictionary(
341
+ nullable: boolean,
342
+ valueType: Nullable<NativeModuleTypeAnnotation>,
343
+ ): Nullable<NativeModuleGenericObjectTypeAnnotation> {
344
+ return wrapNullable(nullable, {
345
+ type: 'GenericObjectTypeAnnotation',
346
+ dictionaryValueType: valueType,
347
+ });
348
+ }
349
+
312
350
  function emitObject(
313
351
  nullable: boolean,
314
352
  properties: Array<$FlowFixMe>,
@@ -327,6 +365,19 @@ function emitFloat(
327
365
  });
328
366
  }
329
367
 
368
+ function emitFloatProp(
369
+ name: string,
370
+ optional: boolean,
371
+ ): NamedShape<EventTypeAnnotation> {
372
+ return {
373
+ name,
374
+ optional,
375
+ typeAnnotation: {
376
+ type: 'FloatTypeAnnotation',
377
+ },
378
+ };
379
+ }
380
+
330
381
  function emitUnion(
331
382
  nullable: boolean,
332
383
  hasteModuleName: string,
@@ -476,6 +527,7 @@ function Visitor(infoMap: {isComponent: boolean, isModule: boolean}): {
476
527
  }
477
528
 
478
529
  function emitPartial(
530
+ nullable: boolean,
479
531
  hasteModuleName: string,
480
532
  typeAnnotation: $FlowFixMe,
481
533
  types: TypeDeclarationMap,
@@ -483,7 +535,6 @@ function emitPartial(
483
535
  enumMap: {...NativeModuleEnumMap},
484
536
  tryParse: ParserErrorCapturer,
485
537
  cxxOnly: boolean,
486
- nullable: boolean,
487
538
  parser: Parser,
488
539
  ): Nullable<NativeModuleTypeAnnotation> {
489
540
  throwIfPartialWithMoreParameter(typeAnnotation);
@@ -521,61 +572,85 @@ function emitCommonTypes(
521
572
  nullable: boolean,
522
573
  parser: Parser,
523
574
  ): $FlowFixMe {
575
+ const typeMap = {
576
+ Stringish: emitStringish,
577
+ Int32: emitInt32,
578
+ Double: emitDouble,
579
+ Float: emitFloat,
580
+ UnsafeObject: emitGenericObject,
581
+ Object: emitGenericObject,
582
+ $Partial: emitPartial,
583
+ Partial: emitPartial,
584
+ BooleanTypeAnnotation: emitBoolean,
585
+ NumberTypeAnnotation: emitNumber,
586
+ VoidTypeAnnotation: emitVoid,
587
+ StringTypeAnnotation: emitString,
588
+ MixedTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject,
589
+ };
590
+
591
+ const typeAnnotationName = parser.convertKeywordToTypeAnnotation(
592
+ typeAnnotation.type,
593
+ );
594
+
595
+ const simpleEmitter = typeMap[typeAnnotationName];
596
+ if (simpleEmitter) {
597
+ return simpleEmitter(nullable);
598
+ }
599
+
524
600
  const genericTypeAnnotationName =
525
601
  parser.nameForGenericTypeAnnotation(typeAnnotation);
526
602
 
527
- switch (genericTypeAnnotationName) {
528
- case 'Stringish': {
529
- return emitStringish(nullable);
530
- }
531
- case 'Int32': {
532
- return emitInt32(nullable);
533
- }
534
- case 'Double': {
535
- return emitDouble(nullable);
536
- }
537
- case 'Float': {
538
- return emitFloat(nullable);
539
- }
540
- case 'UnsafeObject':
541
- case 'Object': {
542
- return emitGenericObject(nullable);
543
- }
544
- case '$Partial':
545
- case 'Partial': {
546
- return emitPartial(
547
- hasteModuleName,
548
- typeAnnotation,
549
- types,
550
- aliasMap,
551
- enumMap,
552
- tryParse,
553
- cxxOnly,
554
- nullable,
555
- parser,
556
- );
557
- }
558
- default: {
559
- return null;
560
- }
603
+ const emitter = typeMap[genericTypeAnnotationName];
604
+ if (!emitter) {
605
+ return null;
561
606
  }
607
+
608
+ return emitter(
609
+ nullable,
610
+ hasteModuleName,
611
+ typeAnnotation,
612
+ types,
613
+ aliasMap,
614
+ enumMap,
615
+ tryParse,
616
+ cxxOnly,
617
+ parser,
618
+ );
619
+ }
620
+
621
+ function emitBoolProp(
622
+ name: string,
623
+ optional: boolean,
624
+ ): NamedShape<EventTypeAnnotation> {
625
+ return {
626
+ name,
627
+ optional,
628
+ typeAnnotation: {
629
+ type: 'BooleanTypeAnnotation',
630
+ },
631
+ };
562
632
  }
563
633
 
564
634
  module.exports = {
565
635
  emitArrayType,
566
636
  emitBoolean,
637
+ emitBoolProp,
567
638
  emitDouble,
639
+ emitDoubleProp,
568
640
  emitFloat,
641
+ emitFloatProp,
569
642
  emitFunction,
570
643
  emitInt32,
571
644
  emitNumber,
572
645
  emitGenericObject,
646
+ emitDictionary,
573
647
  emitObject,
574
648
  emitPromise,
575
649
  emitRootTag,
576
650
  emitVoid,
577
651
  emitString,
578
652
  emitStringish,
653
+ emitStringProp,
579
654
  emitMixed,
580
655
  emitUnion,
581
656
  emitPartial,
@@ -84,6 +84,57 @@ const EVENT_DEFINITION = `
84
84
  object_readonly_optional_both?: Readonly<{
85
85
  int32_optional_both?: Int32 | null | undefined;
86
86
  }> | null | undefined;
87
+
88
+ boolean_array_required: boolean[];
89
+ boolean_array_optional_key?: boolean[];
90
+ boolean_array_optional_value: boolean[] | null | undefined;
91
+ boolean_array_optional_both?: boolean[] | null | undefined;
92
+
93
+ string_array_required: string[];
94
+ string_array_optional_key?: (string[]);
95
+ string_array_optional_value: (string[]) | null | undefined;
96
+ string_array_optional_both?: (string[] | null | undefined);
97
+
98
+ double_array_required: Double[];
99
+ double_array_optional_key?: Double[];
100
+ double_array_optional_value: Double[] | null | undefined;
101
+ double_array_optional_both?: Double[] | null | undefined;
102
+
103
+ float_array_required: Float[];
104
+ float_array_optional_key?: Float[];
105
+ float_array_optional_value: Float[] | null | undefined;
106
+ float_array_optional_both?: Float[] | null | undefined;
107
+
108
+ int32_array_required: Int32[];
109
+ int32_array_optional_key?: Int32[];
110
+ int32_array_optional_value: Int32[] | null | undefined;
111
+ int32_array_optional_both?: Int32[] | null | undefined;
112
+
113
+ enum_array_required: ('small' | 'large')[];
114
+ enum_array_optional_key?: ('small' | 'large')[];
115
+ enum_array_optional_value: ('small' | 'large')[] | null | undefined;
116
+ enum_array_optional_both?: ('small' | 'large')[] | null | undefined;
117
+
118
+ object_array_required: {
119
+ boolean_required: boolean;
120
+ }[];
121
+
122
+ object_array_optional_key?: {
123
+ string_optional_key?: string;
124
+ }[];
125
+
126
+ object_array_optional_value: {
127
+ float_optional_value: Float | null | undefined;
128
+ }[] | null | undefined;
129
+
130
+ object_array_optional_both?: {
131
+ int32_optional_both?: Int32 | null | undefined;
132
+ }[] | null | undefined;
133
+
134
+ int32_array_array_required: Int32[][];
135
+ int32_array_array_optional_key?: Int32[][];
136
+ int32_array_array_optional_value: Int32[][] | null | undefined;
137
+ int32_array_array_optional_both?: Int32[][] | null | undefined;
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 | null | undefined;
86
86
  }> | null | undefined;
87
+
88
+ boolean_array_required: boolean[];
89
+ boolean_array_optional_key?: boolean[];
90
+ boolean_array_optional_value: boolean[] | null | undefined;
91
+ boolean_array_optional_both?: boolean[] | null | undefined;
92
+
93
+ string_array_required: string[];
94
+ string_array_optional_key?: (string[]);
95
+ string_array_optional_value: (string[]) | null | undefined;
96
+ string_array_optional_both?: (string[] | null | undefined);
97
+
98
+ double_array_required: Double[];
99
+ double_array_optional_key?: Double[];
100
+ double_array_optional_value: Double[] | null | undefined;
101
+ double_array_optional_both?: Double[] | null | undefined;
102
+
103
+ float_array_required: Float[];
104
+ float_array_optional_key?: Float[];
105
+ float_array_optional_value: Float[] | null | undefined;
106
+ float_array_optional_both?: Float[] | null | undefined;
107
+
108
+ int32_array_required: Int32[];
109
+ int32_array_optional_key?: Int32[];
110
+ int32_array_optional_value: Int32[] | null | undefined;
111
+ int32_array_optional_both?: Int32[] | null | undefined;
112
+
113
+ enum_array_required: ('small' | 'large')[];
114
+ enum_array_optional_key?: ('small' | 'large')[];
115
+ enum_array_optional_value: ('small' | 'large')[] | null | undefined;
116
+ enum_array_optional_both?: ('small' | 'large')[] | null | undefined;
117
+
118
+ object_array_required: {
119
+ boolean_required: boolean;
120
+ }[];
121
+
122
+ object_array_optional_key?: {
123
+ string_optional_key?: string;
124
+ }[];
125
+
126
+ object_array_optional_value: {
127
+ float_optional_value: Float | null | undefined;
128
+ }[] | null | undefined;
129
+
130
+ object_array_optional_both?: {
131
+ int32_optional_both?: Int32 | null | undefined;
132
+ }[] | null | undefined;
133
+
134
+ int32_array_array_required: Int32[][];
135
+ int32_array_array_optional_key?: Int32[][];
136
+ int32_array_array_optional_value: Int32[][] | null | undefined;
137
+ int32_array_array_optional_both?: Int32[][] | null | undefined;
87
138
  `;
88
139
 
89
140
  const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
@@ -109,6 +109,7 @@ function detectArrayType(
109
109
  typeAnnotation,
110
110
  defaultValue,
111
111
  types,
112
+ parser,
112
113
  buildSchema,
113
114
  ) {
114
115
  // Covers: readonly T[]
@@ -124,6 +125,7 @@ function detectArrayType(
124
125
  typeAnnotation.typeAnnotation.elementType,
125
126
  defaultValue,
126
127
  types,
128
+ parser,
127
129
  buildSchema,
128
130
  ),
129
131
  };
@@ -138,6 +140,7 @@ function detectArrayType(
138
140
  typeAnnotation.elementType,
139
141
  defaultValue,
140
142
  types,
143
+ parser,
141
144
  buildSchema,
142
145
  ),
143
146
  };
@@ -156,16 +159,17 @@ function detectArrayType(
156
159
  typeAnnotation.typeParameters.params[0],
157
160
  defaultValue,
158
161
  types,
162
+ parser,
159
163
  buildSchema,
160
164
  ),
161
165
  };
162
166
  }
163
167
  return null;
164
168
  }
165
- function buildObjectType(rawProperties, types, buildSchema) {
169
+ function buildObjectType(rawProperties, types, parser, buildSchema) {
166
170
  const flattenedProperties = flattenProperties(rawProperties, types);
167
171
  const properties = flattenedProperties
168
- .map(prop => buildSchema(prop, types))
172
+ .map(prop => buildSchema(prop, types, parser))
169
173
  .filter(Boolean);
170
174
  return {
171
175
  type: 'ObjectTypeAnnotation',
@@ -179,17 +183,24 @@ function getCommonTypeAnnotation(
179
183
  typeAnnotation,
180
184
  defaultValue,
181
185
  types,
186
+ parser,
182
187
  buildSchema,
183
188
  ) {
184
189
  switch (type) {
185
190
  case 'TSTypeLiteral':
186
- return buildObjectType(typeAnnotation.members, types, buildSchema);
191
+ return buildObjectType(
192
+ typeAnnotation.members,
193
+ types,
194
+ parser,
195
+ buildSchema,
196
+ );
187
197
  case 'TSInterfaceDeclaration':
188
- return buildObjectType([typeAnnotation], types, buildSchema);
198
+ return buildObjectType([typeAnnotation], types, parser, buildSchema);
189
199
  case 'TSIntersectionType':
190
200
  return buildObjectType(
191
201
  flattenIntersectionType(typeAnnotation, types),
192
202
  types,
203
+ parser,
193
204
  buildSchema,
194
205
  );
195
206
  case 'ImageSource':
@@ -265,6 +276,7 @@ function getTypeAnnotationForArray(
265
276
  typeAnnotation,
266
277
  defaultValue,
267
278
  types,
279
+ parser,
268
280
  buildSchema,
269
281
  ) {
270
282
  var _extractedTypeAnnotat, _extractedTypeAnnotat2;
@@ -286,6 +298,7 @@ function getTypeAnnotationForArray(
286
298
  extractedTypeAnnotation,
287
299
  defaultValue,
288
300
  types,
301
+ parser,
289
302
  buildSchema,
290
303
  );
291
304
  if (arrayType) {
@@ -315,6 +328,7 @@ function getTypeAnnotationForArray(
315
328
  extractedTypeAnnotation,
316
329
  defaultValue,
317
330
  types,
331
+ parser,
318
332
  buildSchema,
319
333
  );
320
334
  if (common) {
@@ -348,7 +362,16 @@ function setDefaultValue(common, defaultValue) {
348
362
  break;
349
363
  }
350
364
  }
351
- function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
365
+ function getTypeAnnotation(
366
+ name,
367
+ annotation,
368
+ defaultValue,
369
+ withNullDefault,
370
+ // Just to make `getTypeAnnotation` signature match with the one from Flow
371
+ types,
372
+ parser,
373
+ buildSchema,
374
+ ) {
352
375
  // unpack WithDefault, (T) or T|U
353
376
  const topLevelType = parseTopLevelType(annotation, types);
354
377
  const typeAnnotation = topLevelType.type;
@@ -357,6 +380,7 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
357
380
  typeAnnotation,
358
381
  defaultValue,
359
382
  types,
383
+ parser,
360
384
  buildSchema,
361
385
  );
362
386
  if (arrayType) {
@@ -374,6 +398,7 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
374
398
  typeAnnotation,
375
399
  defaultValue,
376
400
  types,
401
+ parser,
377
402
  buildSchema,
378
403
  );
379
404
  if (common) {
@@ -419,11 +444,10 @@ function getSchemaInfo(property, types) {
419
444
  optional: property.optional || topLevelType.optional,
420
445
  typeAnnotation: topLevelType.type,
421
446
  defaultValue: topLevelType.defaultValue,
447
+ withNullDefault: false, // Just to make `getTypeAnnotation` signature match with the one from Flow
422
448
  };
423
449
  }
424
450
 
425
- // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
426
-
427
451
  function verifyPropNotAlreadyDefined(props, needleProp) {
428
452
  const propName = needleProp.key.name;
429
453
  const foundProp = props.some(prop => prop.key.name === propName);
@@ -9,13 +9,12 @@
9
9
  */
10
10
 
11
11
  'use strict';
12
- import type {ASTNode} from '../utils';
13
- import type {NamedShape} from '../../../CodegenSchema.js';
14
12
  const {
15
13
  parseTopLevelType,
16
14
  flattenIntersectionType,
17
15
  } = require('../parseTopLevelType');
18
- import type {TypeDeclarationMap} from '../../utils';
16
+ import type {TypeDeclarationMap, PropAST, ASTNode} from '../../utils';
17
+ import type {BuildSchemaFN, Parser} from '../../parser';
19
18
 
20
19
  function getProperties(
21
20
  typeName: string,
@@ -111,7 +110,8 @@ function detectArrayType<T>(
111
110
  typeAnnotation: $FlowFixMe | ASTNode,
112
111
  defaultValue: $FlowFixMe | void,
113
112
  types: TypeDeclarationMap,
114
- buildSchema: (property: PropAST, types: TypeDeclarationMap) => ?NamedShape<T>,
113
+ parser: Parser,
114
+ buildSchema: BuildSchemaFN<T>,
115
115
  ): $FlowFixMe {
116
116
  // Covers: readonly T[]
117
117
  if (
@@ -126,6 +126,7 @@ function detectArrayType<T>(
126
126
  typeAnnotation.typeAnnotation.elementType,
127
127
  defaultValue,
128
128
  types,
129
+ parser,
129
130
  buildSchema,
130
131
  ),
131
132
  };
@@ -140,6 +141,7 @@ function detectArrayType<T>(
140
141
  typeAnnotation.elementType,
141
142
  defaultValue,
142
143
  types,
144
+ parser,
143
145
  buildSchema,
144
146
  ),
145
147
  };
@@ -158,6 +160,7 @@ function detectArrayType<T>(
158
160
  typeAnnotation.typeParameters.params[0],
159
161
  defaultValue,
160
162
  types,
163
+ parser,
161
164
  buildSchema,
162
165
  ),
163
166
  };
@@ -169,11 +172,12 @@ function detectArrayType<T>(
169
172
  function buildObjectType<T>(
170
173
  rawProperties: Array<$FlowFixMe>,
171
174
  types: TypeDeclarationMap,
172
- buildSchema: (property: PropAST, types: TypeDeclarationMap) => ?NamedShape<T>,
175
+ parser: Parser,
176
+ buildSchema: BuildSchemaFN<T>,
173
177
  ): $FlowFixMe {
174
178
  const flattenedProperties = flattenProperties(rawProperties, types);
175
179
  const properties = flattenedProperties
176
- .map(prop => buildSchema(prop, types))
180
+ .map(prop => buildSchema(prop, types, parser))
177
181
  .filter(Boolean);
178
182
 
179
183
  return {
@@ -189,17 +193,24 @@ function getCommonTypeAnnotation<T>(
189
193
  typeAnnotation: $FlowFixMe,
190
194
  defaultValue: $FlowFixMe | void,
191
195
  types: TypeDeclarationMap,
192
- buildSchema: (property: PropAST, types: TypeDeclarationMap) => ?NamedShape<T>,
196
+ parser: Parser,
197
+ buildSchema: BuildSchemaFN<T>,
193
198
  ): $FlowFixMe {
194
199
  switch (type) {
195
200
  case 'TSTypeLiteral':
196
- return buildObjectType(typeAnnotation.members, types, buildSchema);
201
+ return buildObjectType(
202
+ typeAnnotation.members,
203
+ types,
204
+ parser,
205
+ buildSchema,
206
+ );
197
207
  case 'TSInterfaceDeclaration':
198
- return buildObjectType([typeAnnotation], types, buildSchema);
208
+ return buildObjectType([typeAnnotation], types, parser, buildSchema);
199
209
  case 'TSIntersectionType':
200
210
  return buildObjectType(
201
211
  flattenIntersectionType(typeAnnotation, types),
202
212
  types,
213
+ parser,
203
214
  buildSchema,
204
215
  );
205
216
  case 'ImageSource':
@@ -276,7 +287,8 @@ function getTypeAnnotationForArray<T>(
276
287
  typeAnnotation: $FlowFixMe,
277
288
  defaultValue: $FlowFixMe | void,
278
289
  types: TypeDeclarationMap,
279
- buildSchema: (property: PropAST, types: TypeDeclarationMap) => ?NamedShape<T>,
290
+ parser: Parser,
291
+ buildSchema: BuildSchemaFN<T>,
280
292
  ): $FlowFixMe {
281
293
  // unpack WithDefault, (T) or T|U
282
294
  const topLevelType = parseTopLevelType(typeAnnotation, types);
@@ -297,6 +309,7 @@ function getTypeAnnotationForArray<T>(
297
309
  extractedTypeAnnotation,
298
310
  defaultValue,
299
311
  types,
312
+ parser,
300
313
  buildSchema,
301
314
  );
302
315
  if (arrayType) {
@@ -322,6 +335,7 @@ function getTypeAnnotationForArray<T>(
322
335
  extractedTypeAnnotation,
323
336
  defaultValue,
324
337
  types,
338
+ parser,
325
339
  buildSchema,
326
340
  );
327
341
  if (common) {
@@ -370,8 +384,10 @@ function getTypeAnnotation<T>(
370
384
  name: string,
371
385
  annotation: $FlowFixMe | ASTNode,
372
386
  defaultValue: $FlowFixMe | void,
387
+ withNullDefault: boolean, // Just to make `getTypeAnnotation` signature match with the one from Flow
373
388
  types: TypeDeclarationMap,
374
- buildSchema: (property: PropAST, types: TypeDeclarationMap) => ?NamedShape<T>,
389
+ parser: Parser,
390
+ buildSchema: BuildSchemaFN<T>,
375
391
  ): $FlowFixMe {
376
392
  // unpack WithDefault, (T) or T|U
377
393
  const topLevelType = parseTopLevelType(annotation, types);
@@ -381,6 +397,7 @@ function getTypeAnnotation<T>(
381
397
  typeAnnotation,
382
398
  defaultValue,
383
399
  types,
400
+ parser,
384
401
  buildSchema,
385
402
  );
386
403
  if (arrayType) {
@@ -400,6 +417,7 @@ function getTypeAnnotation<T>(
400
417
  typeAnnotation,
401
418
  defaultValue,
402
419
  types,
420
+ parser,
403
421
  buildSchema,
404
422
  );
405
423
  if (common) {
@@ -435,6 +453,7 @@ type SchemaInfo = {
435
453
  optional: boolean,
436
454
  typeAnnotation: $FlowFixMe,
437
455
  defaultValue: $FlowFixMe,
456
+ withNullDefault: boolean, // Just to make `getTypeAnnotation` signature match with the one from Flow
438
457
  };
439
458
 
440
459
  function getSchemaInfo(
@@ -460,12 +479,10 @@ function getSchemaInfo(
460
479
  optional: property.optional || topLevelType.optional,
461
480
  typeAnnotation: topLevelType.type,
462
481
  defaultValue: topLevelType.defaultValue,
482
+ withNullDefault: false, // Just to make `getTypeAnnotation` signature match with the one from Flow
463
483
  };
464
484
  }
465
485
 
466
- // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
467
- type PropAST = Object;
468
-
469
486
  function verifyPropNotAlreadyDefined(
470
487
  props: $ReadOnlyArray<PropAST>,
471
488
  needleProp: PropAST,