@react-native/codegen 0.72.1 → 0.72.2

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 (119) hide show
  1. package/lib/CodegenSchema.d.ts +348 -0
  2. package/lib/CodegenSchema.js.flow +31 -3
  3. package/lib/SchemaValidator.d.ts +11 -0
  4. package/lib/cli/combine/combine-js-to-schema.js +8 -8
  5. package/lib/cli/combine/combine-js-to-schema.js.flow +8 -7
  6. package/lib/cli/parser/parser.js +8 -15
  7. package/lib/cli/parser/parser.js.flow +8 -14
  8. package/lib/generators/Utils.js +16 -0
  9. package/lib/generators/Utils.js.flow +20 -0
  10. package/lib/generators/__test_fixtures__/fixtures.js +2 -1
  11. package/lib/generators/__test_fixtures__/fixtures.js.flow +2 -1
  12. package/lib/generators/components/ComponentsGeneratorUtils.js +10 -1
  13. package/lib/generators/components/ComponentsGeneratorUtils.js.flow +12 -2
  14. package/lib/generators/components/CppHelpers.js +8 -15
  15. package/lib/generators/components/CppHelpers.js.flow +8 -19
  16. package/lib/generators/components/GenerateEventEmitterCpp.js +7 -3
  17. package/lib/generators/components/GenerateEventEmitterCpp.js.flow +7 -3
  18. package/lib/generators/components/GenerateEventEmitterH.js +2 -2
  19. package/lib/generators/components/GenerateEventEmitterH.js.flow +1 -2
  20. package/lib/generators/components/GeneratePropsH.js +3 -4
  21. package/lib/generators/components/GeneratePropsH.js.flow +2 -4
  22. package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
  23. package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
  24. package/lib/generators/components/GeneratePropsJavaInterface.js +3 -0
  25. package/lib/generators/components/GeneratePropsJavaInterface.js.flow +3 -0
  26. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +8 -0
  27. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +12 -0
  28. package/lib/generators/components/GenerateTests.js +3 -2
  29. package/lib/generators/components/GenerateTests.js.flow +3 -1
  30. package/lib/generators/components/GenerateViewConfigJs.js +5 -2
  31. package/lib/generators/components/GenerateViewConfigJs.js.flow +5 -2
  32. package/lib/generators/components/JavaHelpers.js +9 -0
  33. package/lib/generators/components/JavaHelpers.js.flow +12 -1
  34. package/lib/generators/components/__test_fixtures__/fixtures.js +41 -0
  35. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +42 -0
  36. package/lib/generators/modules/GenerateModuleCpp.js +9 -4
  37. package/lib/generators/modules/GenerateModuleCpp.js.flow +11 -3
  38. package/lib/generators/modules/GenerateModuleH.js +185 -33
  39. package/lib/generators/modules/GenerateModuleH.js.flow +203 -25
  40. package/lib/generators/modules/GenerateModuleJavaSpec.js +2 -2
  41. package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +5 -5
  42. package/lib/generators/modules/GenerateModuleJniCpp.js +2 -2
  43. package/lib/generators/modules/GenerateModuleJniCpp.js.flow +5 -5
  44. package/lib/generators/modules/GenerateModuleObjCpp/index.js +2 -2
  45. package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +2 -2
  46. package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +2 -2
  47. package/lib/generators/modules/Utils.js +4 -0
  48. package/lib/generators/modules/Utils.js.flow +6 -0
  49. package/lib/generators/modules/__test_fixtures__/fixtures.js +152 -10
  50. package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +152 -10
  51. package/lib/parsers/error-utils.js +1 -19
  52. package/lib/parsers/error-utils.js.flow +1 -19
  53. package/lib/parsers/errors.d.ts +10 -0
  54. package/lib/parsers/errors.js +9 -29
  55. package/lib/parsers/errors.js.flow +2 -20
  56. package/lib/parsers/flow/Visitor.js +37 -0
  57. package/lib/parsers/flow/Visitor.js.flow +41 -0
  58. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +20 -2
  59. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +20 -2
  60. package/lib/parsers/flow/components/commands.js +3 -0
  61. package/lib/parsers/flow/components/commands.js.flow +2 -1
  62. package/lib/parsers/flow/components/componentsUtils.js +10 -0
  63. package/lib/parsers/flow/components/componentsUtils.js.flow +11 -1
  64. package/lib/parsers/flow/components/events.js.flow +1 -1
  65. package/lib/parsers/flow/components/extends.js.flow +1 -1
  66. package/lib/parsers/flow/components/index.js.flow +1 -1
  67. package/lib/parsers/flow/components/options.js.flow +1 -1
  68. package/lib/parsers/flow/components/props.js.flow +1 -1
  69. package/lib/parsers/flow/modules/__test_fixtures__/failures.js +54 -0
  70. package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +56 -0
  71. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +64 -1
  72. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +66 -1
  73. package/lib/parsers/flow/modules/index.js +99 -25
  74. package/lib/parsers/flow/modules/index.js.flow +106 -22
  75. package/lib/parsers/flow/parser.d.ts +10 -0
  76. package/lib/parsers/flow/parser.js +122 -32
  77. package/lib/parsers/flow/parser.js.flow +144 -24
  78. package/lib/parsers/flow/utils.js +33 -19
  79. package/lib/parsers/flow/utils.js.flow +37 -22
  80. package/lib/parsers/parser.d.ts +17 -0
  81. package/lib/parsers/parser.js.flow +102 -17
  82. package/lib/parsers/parserMock.js +87 -30
  83. package/lib/parsers/parserMock.js.flow +118 -24
  84. package/lib/parsers/parsers-commons.js +121 -119
  85. package/lib/parsers/parsers-commons.js.flow +130 -131
  86. package/lib/parsers/parsers-primitives.js +75 -12
  87. package/lib/parsers/parsers-primitives.js.flow +92 -13
  88. package/lib/parsers/schema/index.d.ts +10 -0
  89. package/lib/parsers/typescript/Visitor.js +42 -0
  90. package/lib/parsers/typescript/Visitor.js.flow +47 -0
  91. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +22 -0
  92. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +22 -0
  93. package/lib/parsers/typescript/components/commands.js +3 -0
  94. package/lib/parsers/typescript/components/commands.js.flow +2 -1
  95. package/lib/parsers/typescript/components/componentsUtils.js +5 -0
  96. package/lib/parsers/typescript/components/componentsUtils.js.flow +6 -1
  97. package/lib/parsers/typescript/components/events.js.flow +1 -1
  98. package/lib/parsers/typescript/components/extends.js.flow +1 -1
  99. package/lib/parsers/typescript/components/index.js.flow +1 -1
  100. package/lib/parsers/typescript/components/options.js.flow +1 -1
  101. package/lib/parsers/typescript/components/props.js.flow +1 -1
  102. package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +52 -0
  103. package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +54 -0
  104. package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +142 -0
  105. package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +146 -0
  106. package/lib/parsers/typescript/modules/index.js +266 -87
  107. package/lib/parsers/typescript/modules/index.js.flow +230 -48
  108. package/lib/parsers/typescript/parser.d.ts +10 -0
  109. package/lib/parsers/typescript/parser.js +131 -25
  110. package/lib/parsers/typescript/parser.js.flow +137 -26
  111. package/lib/parsers/typescript/utils.js +40 -20
  112. package/lib/parsers/typescript/utils.js.flow +44 -24
  113. package/lib/parsers/utils.js +0 -125
  114. package/lib/parsers/utils.js.flow +3 -70
  115. package/package.json +4 -1
  116. package/lib/parsers/flow/index.js +0 -80
  117. package/lib/parsers/flow/index.js.flow +0 -85
  118. package/lib/parsers/typescript/index.js +0 -85
  119. package/lib/parsers/typescript/index.js.flow +0 -94
@@ -0,0 +1,348 @@
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
+ export type PlatformType =
9
+ | 'iOS'
10
+ | 'android';
11
+
12
+ export interface SchemaType {
13
+ readonly modules: {
14
+ [hasteModuleName: string]: ComponentSchema | NativeModuleSchema;
15
+ };
16
+ }
17
+
18
+ export interface DoubleTypeAnnotation {
19
+ readonly type: 'DoubleTypeAnnotation';
20
+ }
21
+
22
+ export interface FloatTypeAnnotation {
23
+ readonly type: 'FloatTypeAnnotation';
24
+ }
25
+
26
+ export interface BooleanTypeAnnotation {
27
+ readonly type: 'BooleanTypeAnnotation';
28
+ }
29
+
30
+ export interface Int32TypeAnnotation {
31
+ readonly type: 'Int32TypeAnnotation';
32
+ }
33
+
34
+ export interface StringTypeAnnotation {
35
+ readonly type: 'StringTypeAnnotation';
36
+ }
37
+
38
+ export interface StringEnumTypeAnnotation {
39
+ readonly type: 'StringEnumTypeAnnotation';
40
+ readonly options: readonly string[];
41
+ }
42
+
43
+ export interface VoidTypeAnnotation {
44
+ readonly type: 'VoidTypeAnnotation';
45
+ }
46
+
47
+ export interface ObjectTypeAnnotation<T> {
48
+ readonly type: 'ObjectTypeAnnotation';
49
+ readonly properties: readonly NamedShape<T>[];
50
+ readonly baseTypes?: readonly string[];
51
+ }
52
+
53
+ export interface FunctionTypeAnnotation<P, R> {
54
+ readonly type: 'FunctionTypeAnnotation';
55
+ readonly params: readonly NamedShape<P>[];
56
+ readonly returnTypeAnnotation: R;
57
+ }
58
+
59
+ export interface NamedShape<T> {
60
+ readonly name: string;
61
+ readonly optional: boolean;
62
+ readonly typeAnnotation: T;
63
+ }
64
+
65
+ export interface ComponentSchema {
66
+ readonly type: 'Component';
67
+ readonly components: {
68
+ [componentName: string]: ComponentShape;
69
+ };
70
+ }
71
+
72
+ export interface ComponentShape extends OptionsShape {
73
+ readonly extendsProps: readonly ExtendsPropsShape[];
74
+ readonly events: readonly EventTypeShape[];
75
+ readonly props: readonly NamedShape<PropTypeAnnotation>[];
76
+ readonly commands: readonly NamedShape<CommandTypeAnnotation>[];
77
+ }
78
+
79
+ export interface OptionsShape {
80
+ readonly interfaceOnly?: boolean;
81
+ readonly paperComponentName?: string;
82
+ readonly excludedPlatforms?: readonly PlatformType[];
83
+ readonly paperComponentNameDeprecated?: string;
84
+ }
85
+
86
+ export interface ExtendsPropsShape {
87
+ readonly type: 'ReactNativeBuiltInType';
88
+ readonly knownTypeName: 'ReactNativeCoreViewProps';
89
+ }
90
+
91
+ export interface EventTypeShape {
92
+ readonly name: string;
93
+ readonly bubblingType:
94
+ | 'direct'
95
+ | 'bubble';
96
+ readonly optional: boolean;
97
+ readonly paperTopLevelNameDeprecated?: string;
98
+ readonly typeAnnotation: {
99
+ readonly type: 'EventTypeAnnotation';
100
+ readonly argument?: ObjectTypeAnnotation<EventTypeAnnotation>;
101
+ };
102
+ }
103
+
104
+ export type EventTypeAnnotation =
105
+ | BooleanTypeAnnotation
106
+ | StringTypeAnnotation
107
+ | DoubleTypeAnnotation
108
+ | FloatTypeAnnotation
109
+ | Int32TypeAnnotation
110
+ | StringEnumTypeAnnotation
111
+ | ObjectTypeAnnotation<EventTypeAnnotation>;
112
+
113
+ export type PropTypeAnnotation =
114
+ | {
115
+ readonly type: 'BooleanTypeAnnotation';
116
+ readonly default:
117
+ | boolean
118
+ | null;
119
+ }
120
+ | {
121
+ readonly type: 'StringTypeAnnotation';
122
+ readonly default:
123
+ | string
124
+ | null;
125
+ }
126
+ | {
127
+ readonly type: 'DoubleTypeAnnotation';
128
+ readonly default: number;
129
+ }
130
+ | {
131
+ readonly type: 'FloatTypeAnnotation';
132
+ readonly default:
133
+ | number
134
+ | null;
135
+ }
136
+ | {
137
+ readonly type: 'Int32TypeAnnotation';
138
+ readonly default: number;
139
+ }
140
+ | {
141
+ readonly type: 'StringEnumTypeAnnotation';
142
+ readonly default: string;
143
+ readonly options: readonly string[];
144
+ }
145
+ | {
146
+ readonly type: 'Int32EnumTypeAnnotation';
147
+ readonly default: number;
148
+ readonly options: readonly number[];
149
+ }
150
+ | ReservedPropTypeAnnotation
151
+ | ObjectTypeAnnotation<PropTypeAnnotation>
152
+ | {
153
+ readonly type: 'ArrayTypeAnnotation';
154
+ readonly elementType:
155
+ | BooleanTypeAnnotation
156
+ | StringTypeAnnotation
157
+ | DoubleTypeAnnotation
158
+ | FloatTypeAnnotation
159
+ | Int32TypeAnnotation
160
+ | {
161
+ readonly type: 'StringEnumTypeAnnotation';
162
+ readonly default: string;
163
+ readonly options: readonly string[];
164
+ }
165
+ | ObjectTypeAnnotation<PropTypeAnnotation>
166
+ | ReservedPropTypeAnnotation
167
+ | {
168
+ readonly type: 'ArrayTypeAnnotation';
169
+ readonly elementType: ObjectTypeAnnotation<PropTypeAnnotation>;
170
+ };
171
+ };
172
+
173
+ export interface ReservedPropTypeAnnotation {
174
+ readonly type: 'ReservedPropTypeAnnotation';
175
+ readonly name:
176
+ | 'ColorPrimitive'
177
+ | 'ImageSourcePrimitive'
178
+ | 'PointPrimitive'
179
+ | 'EdgeInsetsPrimitive'
180
+ | 'ImageRequestPrimitive'
181
+ | 'DimensionPrimitive';
182
+ }
183
+
184
+ export type CommandTypeAnnotation = FunctionTypeAnnotation<CommandParamTypeAnnotation, VoidTypeAnnotation>;
185
+
186
+ export type CommandParamTypeAnnotation =
187
+ | ReservedTypeAnnotation
188
+ | BooleanTypeAnnotation
189
+ | Int32TypeAnnotation
190
+ | DoubleTypeAnnotation
191
+ | FloatTypeAnnotation
192
+ | StringTypeAnnotation;
193
+
194
+ export interface ReservedTypeAnnotation {
195
+ readonly type: 'ReservedTypeAnnotation';
196
+ readonly name: 'RootTag';
197
+ }
198
+
199
+ export type Nullable<T extends NativeModuleTypeAnnotation> =
200
+ | NullableTypeAnnotation<T>
201
+ | T;
202
+
203
+ export interface NullableTypeAnnotation<T extends NativeModuleTypeAnnotation> {
204
+ readonly type: 'NullableTypeAnnotation';
205
+ readonly typeAnnotation: T;
206
+ }
207
+
208
+ export interface NativeModuleSchema {
209
+ readonly type: 'NativeModule';
210
+ readonly aliasMap: NativeModuleAliasMap;
211
+ readonly enumMap: NativeModuleEnumMap;
212
+ readonly spec: NativeModuleSpec;
213
+ readonly moduleName: string;
214
+ readonly excludedPlatforms?: readonly PlatformType[];
215
+ }
216
+
217
+ export interface NativeModuleSpec {
218
+ readonly properties: readonly NativeModulePropertyShape[];
219
+ }
220
+
221
+ export type NativeModulePropertyShape = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;
222
+
223
+ export interface NativeModuleEnumMap {
224
+ readonly [enumName: string]: NativeModuleEnumDeclarationWithMembers;
225
+ }
226
+
227
+ export interface NativeModuleAliasMap {
228
+ readonly [aliasName: string]: NativeModuleObjectTypeAnnotation;
229
+ }
230
+
231
+ export type NativeModuleFunctionTypeAnnotation = FunctionTypeAnnotation<Nullable<NativeModuleParamTypeAnnotation>, Nullable<NativeModuleReturnTypeAnnotation>>;
232
+
233
+ export type NativeModuleObjectTypeAnnotation = ObjectTypeAnnotation<Nullable<NativeModuleBaseTypeAnnotation>>;
234
+
235
+ export interface NativeModuleArrayTypeAnnotation<T extends Nullable<NativeModuleBaseTypeAnnotation>> {
236
+ readonly type: 'ArrayTypeAnnotation';
237
+ readonly elementType?: T;
238
+ }
239
+
240
+ export interface NativeModuleStringTypeAnnotation {
241
+ readonly type: 'StringTypeAnnotation';
242
+ }
243
+
244
+ export interface NativeModuleNumberTypeAnnotation {
245
+ readonly type: 'NumberTypeAnnotation';
246
+ }
247
+
248
+ export interface NativeModuleInt32TypeAnnotation {
249
+ readonly type: 'Int32TypeAnnotation';
250
+ }
251
+
252
+ export interface NativeModuleDoubleTypeAnnotation {
253
+ readonly type: 'DoubleTypeAnnotation';
254
+ }
255
+
256
+ export interface NativeModuleFloatTypeAnnotation {
257
+ readonly type: 'FloatTypeAnnotation';
258
+ }
259
+
260
+ export interface NativeModuleBooleanTypeAnnotation {
261
+ readonly type: 'BooleanTypeAnnotation';
262
+ }
263
+
264
+ export type NativeModuleEnumMembers = readonly {
265
+ readonly name: string;
266
+ readonly value: string;
267
+ }[];
268
+
269
+ export type NativeModuleEnumMemberType =
270
+ | 'NumberTypeAnnotation'
271
+ | 'StringTypeAnnotation';
272
+
273
+ export interface NativeModuleEnumDeclaration {
274
+ readonly name: string;
275
+ readonly type: 'EnumDeclaration';
276
+ readonly memberType: NativeModuleEnumMemberType;
277
+ }
278
+
279
+ export interface NativeModuleEnumDeclarationWithMembers {
280
+ name: string;
281
+ type: 'EnumDeclarationWithMembers';
282
+ memberType: NativeModuleEnumMemberType;
283
+ members: NativeModuleEnumMembers;
284
+ }
285
+
286
+ export interface NativeModuleGenericObjectTypeAnnotation {
287
+ readonly type: 'GenericObjectTypeAnnotation';
288
+ }
289
+
290
+ export interface NativeModuleTypeAliasTypeAnnotation {
291
+ readonly type: 'TypeAliasTypeAnnotation';
292
+ readonly name: string;
293
+ }
294
+
295
+ export interface NativeModulePromiseTypeAnnotation {
296
+ readonly type: 'PromiseTypeAnnotation';
297
+ readonly elementType?: Nullable<NativeModuleBaseTypeAnnotation>;
298
+ }
299
+
300
+ export type UnionTypeAnnotationMemberType =
301
+ | 'NumberTypeAnnotation'
302
+ | 'ObjectTypeAnnotation'
303
+ | 'StringTypeAnnotation';
304
+
305
+ export interface NativeModuleUnionTypeAnnotation {
306
+ readonly type: 'UnionTypeAnnotation';
307
+ readonly memberType: UnionTypeAnnotationMemberType;
308
+ }
309
+
310
+ export interface NativeModuleMixedTypeAnnotation {
311
+ readonly type: 'MixedTypeAnnotation';
312
+ }
313
+
314
+ export type NativeModuleBaseTypeAnnotation =
315
+ | NativeModuleStringTypeAnnotation
316
+ | NativeModuleNumberTypeAnnotation
317
+ | NativeModuleInt32TypeAnnotation
318
+ | NativeModuleDoubleTypeAnnotation
319
+ | NativeModuleFloatTypeAnnotation
320
+ | NativeModuleBooleanTypeAnnotation
321
+ | NativeModuleEnumDeclaration
322
+ | NativeModuleGenericObjectTypeAnnotation
323
+ | ReservedTypeAnnotation
324
+ | NativeModuleTypeAliasTypeAnnotation
325
+ | NativeModuleArrayTypeAnnotation<Nullable<NativeModuleBaseTypeAnnotation>>
326
+ | NativeModuleObjectTypeAnnotation
327
+ | NativeModuleUnionTypeAnnotation
328
+ | NativeModuleMixedTypeAnnotation;
329
+
330
+ export type NativeModuleParamTypeAnnotation =
331
+ | NativeModuleBaseTypeAnnotation
332
+ | NativeModuleParamOnlyTypeAnnotation;
333
+
334
+ export type NativeModuleReturnTypeAnnotation =
335
+ | NativeModuleBaseTypeAnnotation
336
+ | NativeModuleReturnOnlyTypeAnnotation;
337
+
338
+ export type NativeModuleTypeAnnotation =
339
+ | NativeModuleBaseTypeAnnotation
340
+ | NativeModuleParamOnlyTypeAnnotation
341
+ | NativeModuleReturnOnlyTypeAnnotation;
342
+
343
+ export type NativeModuleParamOnlyTypeAnnotation = NativeModuleFunctionTypeAnnotation;
344
+
345
+ export type NativeModuleReturnOnlyTypeAnnotation =
346
+ | NativeModulePromiseTypeAnnotation
347
+ | VoidTypeAnnotation;
348
+
@@ -53,6 +53,9 @@ export type VoidTypeAnnotation = $ReadOnly<{
53
53
  export type ObjectTypeAnnotation<+T> = $ReadOnly<{
54
54
  type: 'ObjectTypeAnnotation',
55
55
  properties: $ReadOnlyArray<NamedShape<T>>,
56
+
57
+ // metadata for objects that generated from interfaces
58
+ baseTypes?: $ReadOnlyArray<string>,
56
59
  }>;
57
60
 
58
61
  type FunctionTypeAnnotation<+P, +R> = $ReadOnly<{
@@ -183,7 +186,8 @@ export type ReservedPropTypeAnnotation = $ReadOnly<{
183
186
  | 'ImageSourcePrimitive'
184
187
  | 'PointPrimitive'
185
188
  | 'EdgeInsetsPrimitive'
186
- | 'ImageRequestPrimitive',
189
+ | 'ImageRequestPrimitive'
190
+ | 'DimensionPrimitive',
187
191
  }>;
188
192
 
189
193
  export type CommandTypeAnnotation = FunctionTypeAnnotation<
@@ -218,7 +222,8 @@ export type NullableTypeAnnotation<+T: NativeModuleTypeAnnotation> = $ReadOnly<{
218
222
 
219
223
  export type NativeModuleSchema = $ReadOnly<{
220
224
  type: 'NativeModule',
221
- aliases: NativeModuleAliasMap,
225
+ aliasMap: NativeModuleAliasMap,
226
+ enumMap: NativeModuleEnumMap,
222
227
  spec: NativeModuleSpec,
223
228
  moduleName: string,
224
229
  // Use for modules that are not used on other platforms.
@@ -235,6 +240,10 @@ export type NativeModulePropertyShape = NamedShape<
235
240
  Nullable<NativeModuleFunctionTypeAnnotation>,
236
241
  >;
237
242
 
243
+ export type NativeModuleEnumMap = $ReadOnly<{
244
+ [enumName: string]: NativeModuleEnumDeclarationWithMembers,
245
+ }>;
246
+
238
247
  export type NativeModuleAliasMap = $ReadOnly<{
239
248
  [aliasName: string]: NativeModuleObjectTypeAnnotation,
240
249
  }>;
@@ -283,11 +292,30 @@ export type NativeModuleBooleanTypeAnnotation = $ReadOnly<{
283
292
  type: 'BooleanTypeAnnotation',
284
293
  }>;
285
294
 
295
+ export type NativeModuleEnumMembers = $ReadOnlyArray<
296
+ $ReadOnly<{
297
+ name: string,
298
+ value: string,
299
+ }>,
300
+ >;
301
+
302
+ export type NativeModuleEnumMemberType =
303
+ | 'NumberTypeAnnotation'
304
+ | 'StringTypeAnnotation';
305
+
286
306
  export type NativeModuleEnumDeclaration = $ReadOnly<{
307
+ name: string,
287
308
  type: 'EnumDeclaration',
288
- memberType: 'NumberTypeAnnotation' | 'StringTypeAnnotation',
309
+ memberType: NativeModuleEnumMemberType,
289
310
  }>;
290
311
 
312
+ export type NativeModuleEnumDeclarationWithMembers = {
313
+ name: string,
314
+ type: 'EnumDeclarationWithMembers',
315
+ memberType: NativeModuleEnumMemberType,
316
+ members: NativeModuleEnumMembers,
317
+ };
318
+
291
319
  export type NativeModuleGenericObjectTypeAnnotation = $ReadOnly<{
292
320
  type: 'GenericObjectTypeAnnotation',
293
321
  }>;
@@ -0,0 +1,11 @@
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
+ import type { SchemaType } from "./CodegenSchema";
9
+
10
+ export declare function getErrors(schema: SchemaType): readonly string[];
11
+ export declare function validate(schema: SchemaType): void;
@@ -72,12 +72,14 @@ function _toPrimitive(input, hint) {
72
72
  }
73
73
  return (hint === 'string' ? String : Number)(input);
74
74
  }
75
- const _require = require('../../parsers/utils'),
76
- parseFile = _require.parseFile;
77
- const FlowParser = require('../../parsers/flow');
78
- const TypeScriptParser = require('../../parsers/typescript');
75
+ const _require = require('../../parsers/flow/parser'),
76
+ FlowParser = _require.FlowParser;
77
+ const _require2 = require('../../parsers/typescript/parser'),
78
+ TypeScriptParser = _require2.TypeScriptParser;
79
79
  const fs = require('fs');
80
80
  const path = require('path');
81
+ const flowParser = new FlowParser();
82
+ const typescriptParser = new TypeScriptParser();
81
83
  function combineSchemas(files) {
82
84
  return files.reduce(
83
85
  (merged, filename) => {
@@ -89,10 +91,8 @@ function combineSchemas(files) {
89
91
  ) {
90
92
  const isTypeScript =
91
93
  path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
92
- const schema = parseFile(
93
- filename,
94
- isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
95
- );
94
+ const parser = isTypeScript ? typescriptParser : flowParser;
95
+ const schema = parser.parseFile(filename);
96
96
  if (schema && schema.modules) {
97
97
  merged.modules = _objectSpread(
98
98
  _objectSpread({}, merged.modules),
@@ -11,12 +11,14 @@
11
11
  'use strict';
12
12
  import type {SchemaType} from '../../CodegenSchema.js';
13
13
 
14
- const {parseFile} = require('../../parsers/utils');
15
- const FlowParser = require('../../parsers/flow');
16
- const TypeScriptParser = require('../../parsers/typescript');
14
+ const {FlowParser} = require('../../parsers/flow/parser');
15
+ const {TypeScriptParser} = require('../../parsers/typescript/parser');
17
16
  const fs = require('fs');
18
17
  const path = require('path');
19
18
 
19
+ const flowParser = new FlowParser();
20
+ const typescriptParser = new TypeScriptParser();
21
+
20
22
  function combineSchemas(files: Array<string>): SchemaType {
21
23
  return files.reduce(
22
24
  (merged, filename) => {
@@ -30,10 +32,9 @@ function combineSchemas(files: Array<string>): SchemaType {
30
32
  const isTypeScript =
31
33
  path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
32
34
 
33
- const schema = parseFile(
34
- filename,
35
- isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
36
- );
35
+ const parser = isTypeScript ? typescriptParser : flowParser;
36
+
37
+ const schema = parser.parseFile(filename);
37
38
 
38
39
  if (schema && schema.modules) {
39
40
  merged.modules = {...merged.modules, ...schema.modules};
@@ -11,25 +11,18 @@
11
11
  'use strict';
12
12
 
13
13
  const path = require('path');
14
- const _require = require('../../parsers/utils'),
15
- parseFile = _require.parseFile;
16
- const FlowParser = require('../../parsers/flow');
17
- const TypeScriptParser = require('../../parsers/typescript');
14
+ const _require = require('../../parsers/flow/parser'),
15
+ FlowParser = _require.FlowParser;
16
+ const _require2 = require('../../parsers/typescript/parser'),
17
+ TypeScriptParser = _require2.TypeScriptParser;
18
+ const flowParser = new FlowParser();
19
+ const typescriptParser = new TypeScriptParser();
18
20
  function parseFiles(files) {
19
21
  files.forEach(filename => {
20
22
  const isTypeScript =
21
23
  path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
22
- console.log(
23
- filename,
24
- JSON.stringify(
25
- parseFile(
26
- filename,
27
- isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
28
- ),
29
- null,
30
- 2,
31
- ),
32
- );
24
+ const parser = isTypeScript ? typescriptParser : flowParser;
25
+ console.log(filename, JSON.stringify(parser.parseFile(filename), null, 2));
33
26
  });
34
27
  }
35
28
  module.exports = parseFiles;
@@ -11,26 +11,20 @@
11
11
  'use strict';
12
12
 
13
13
  const path = require('path');
14
- const {parseFile} = require('../../parsers/utils');
15
- const FlowParser = require('../../parsers/flow');
16
- const TypeScriptParser = require('../../parsers/typescript');
14
+ const {FlowParser} = require('../../parsers/flow/parser');
15
+ const {TypeScriptParser} = require('../../parsers/typescript/parser');
16
+
17
+ const flowParser = new FlowParser();
18
+ const typescriptParser = new TypeScriptParser();
17
19
 
18
20
  function parseFiles(files: Array<string>) {
19
21
  files.forEach(filename => {
20
22
  const isTypeScript =
21
23
  path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
22
24
 
23
- console.log(
24
- filename,
25
- JSON.stringify(
26
- parseFile(
27
- filename,
28
- isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
29
- ),
30
- null,
31
- 2,
32
- ),
33
- );
25
+ const parser = isTypeScript ? typescriptParser : flowParser;
26
+
27
+ console.log(filename, JSON.stringify(parser.parseFile(filename), null, 2));
34
28
  });
35
29
  }
36
30
 
@@ -25,7 +25,23 @@ function indent(nice, spaces) {
25
25
  })
26
26
  .join('\n');
27
27
  }
28
+ function toPascalCase(inString) {
29
+ if (inString.length === 0) {
30
+ return inString;
31
+ }
32
+ return inString[0].toUpperCase() + inString.slice(1);
33
+ }
34
+ function toSafeCppString(input) {
35
+ return input.split('-').map(toPascalCase).join('');
36
+ }
37
+ function getEnumName(moduleName, origEnumName) {
38
+ const uppercasedPropName = toSafeCppString(origEnumName);
39
+ return `${moduleName}${uppercasedPropName}`;
40
+ }
28
41
  module.exports = {
29
42
  capitalize,
30
43
  indent,
44
+ toPascalCase,
45
+ toSafeCppString,
46
+ getEnumName,
31
47
  };
@@ -27,7 +27,27 @@ function indent(nice: string, spaces: number): string {
27
27
  .join('\n');
28
28
  }
29
29
 
30
+ function toPascalCase(inString: string): string {
31
+ if (inString.length === 0) {
32
+ return inString;
33
+ }
34
+
35
+ return inString[0].toUpperCase() + inString.slice(1);
36
+ }
37
+
38
+ function toSafeCppString(input: string): string {
39
+ return input.split('-').map(toPascalCase).join('');
40
+ }
41
+
42
+ function getEnumName(moduleName: string, origEnumName: string): string {
43
+ const uppercasedPropName = toSafeCppString(origEnumName);
44
+ return `${moduleName}${uppercasedPropName}`;
45
+ }
46
+
30
47
  module.exports = {
31
48
  capitalize,
32
49
  indent,
50
+ toPascalCase,
51
+ toSafeCppString,
52
+ getEnumName,
33
53
  };
@@ -39,7 +39,8 @@ const SCHEMA_WITH_TM_AND_FC = {
39
39
  },
40
40
  NativeCalculator: {
41
41
  type: 'NativeModule',
42
- aliases: {},
42
+ aliasMap: {},
43
+ enumMap: {},
43
44
  spec: {
44
45
  properties: [
45
46
  {
@@ -41,7 +41,8 @@ const SCHEMA_WITH_TM_AND_FC: SchemaType = {
41
41
  },
42
42
  NativeCalculator: {
43
43
  type: 'NativeModule',
44
- aliases: {},
44
+ aliasMap: {},
45
+ enumMap: {},
45
46
  spec: {
46
47
  properties: [
47
48
  {
@@ -13,9 +13,10 @@
13
13
  const _require = require('./CppHelpers.js'),
14
14
  getCppTypeForAnnotation = _require.getCppTypeForAnnotation,
15
15
  getEnumMaskName = _require.getEnumMaskName,
16
- getEnumName = _require.getEnumName,
17
16
  generateStructName = _require.generateStructName,
18
17
  getImports = _require.getImports;
18
+ const _require2 = require('../Utils'),
19
+ getEnumName = _require2.getEnumName;
19
20
  function getNativeTypeFromAnnotation(componentName, prop, nameParts) {
20
21
  const typeAnnotation = prop.typeAnnotation;
21
22
  switch (typeAnnotation.type) {
@@ -37,6 +38,8 @@ function getNativeTypeFromAnnotation(componentName, prop, nameParts) {
37
38
  return 'Point';
38
39
  case 'EdgeInsetsPrimitive':
39
40
  return 'EdgeInsets';
41
+ case 'DimensionPrimitive':
42
+ return 'YGValue';
40
43
  default:
41
44
  typeAnnotation.name;
42
45
  throw new Error('Received unknown ReservedPropTypeAnnotation');
@@ -160,6 +163,9 @@ function getLocalImports(properties) {
160
163
  case 'EdgeInsetsPrimitive':
161
164
  imports.add('#include <react/renderer/graphics/RectangleEdges.h>');
162
165
  return;
166
+ case 'DimensionPrimitive':
167
+ imports.add('#include <yoga/Yoga.h>');
168
+ return;
163
169
  default:
164
170
  name;
165
171
  throw new Error(`Invalid ReservedPropTypeAnnotation name, got ${name}`);
@@ -186,8 +192,11 @@ function getLocalImports(properties) {
186
192
  typeAnnotation.type === 'ArrayTypeAnnotation' &&
187
193
  typeAnnotation.elementType.type === 'ObjectTypeAnnotation'
188
194
  ) {
195
+ imports.add('#include <react/renderer/core/propsConversions.h>');
189
196
  const objectProps = typeAnnotation.elementType.properties;
197
+ // $FlowFixMe[incompatible-call] the type is guaranteed to be ObjectTypeAnnotation<PropTypeAnnotation>
190
198
  const objectImports = getImports(objectProps);
199
+ // $FlowFixMe[incompatible-call] the type is guaranteed to be ObjectTypeAnnotation<PropTypeAnnotation>
191
200
  const localImports = getLocalImports(objectProps);
192
201
  // $FlowFixMe[method-unbinding] added when improving typing for this parameters
193
202
  objectImports.forEach(imports.add, imports);