@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.
- package/lib/CodegenSchema.d.ts +348 -0
- package/lib/CodegenSchema.js.flow +31 -3
- package/lib/SchemaValidator.d.ts +11 -0
- package/lib/cli/combine/combine-js-to-schema.js +8 -8
- package/lib/cli/combine/combine-js-to-schema.js.flow +8 -7
- package/lib/cli/parser/parser.js +8 -15
- package/lib/cli/parser/parser.js.flow +8 -14
- package/lib/generators/Utils.js +16 -0
- package/lib/generators/Utils.js.flow +20 -0
- package/lib/generators/__test_fixtures__/fixtures.js +2 -1
- package/lib/generators/__test_fixtures__/fixtures.js.flow +2 -1
- package/lib/generators/components/ComponentsGeneratorUtils.js +10 -1
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +12 -2
- package/lib/generators/components/CppHelpers.js +8 -15
- package/lib/generators/components/CppHelpers.js.flow +8 -19
- package/lib/generators/components/GenerateEventEmitterCpp.js +7 -3
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +7 -3
- package/lib/generators/components/GenerateEventEmitterH.js +2 -2
- package/lib/generators/components/GenerateEventEmitterH.js.flow +1 -2
- package/lib/generators/components/GeneratePropsH.js +3 -4
- package/lib/generators/components/GeneratePropsH.js.flow +2 -4
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +3 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +3 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +8 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +12 -0
- package/lib/generators/components/GenerateTests.js +3 -2
- package/lib/generators/components/GenerateTests.js.flow +3 -1
- package/lib/generators/components/GenerateViewConfigJs.js +5 -2
- package/lib/generators/components/GenerateViewConfigJs.js.flow +5 -2
- package/lib/generators/components/JavaHelpers.js +9 -0
- package/lib/generators/components/JavaHelpers.js.flow +12 -1
- package/lib/generators/components/__test_fixtures__/fixtures.js +41 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +42 -0
- package/lib/generators/modules/GenerateModuleCpp.js +9 -4
- package/lib/generators/modules/GenerateModuleCpp.js.flow +11 -3
- package/lib/generators/modules/GenerateModuleH.js +185 -33
- package/lib/generators/modules/GenerateModuleH.js.flow +203 -25
- package/lib/generators/modules/GenerateModuleJavaSpec.js +2 -2
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +5 -5
- package/lib/generators/modules/GenerateModuleJniCpp.js +2 -2
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +5 -5
- package/lib/generators/modules/GenerateModuleObjCpp/index.js +2 -2
- package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +2 -2
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +2 -2
- package/lib/generators/modules/Utils.js +4 -0
- package/lib/generators/modules/Utils.js.flow +6 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js +152 -10
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +152 -10
- package/lib/parsers/error-utils.js +1 -19
- package/lib/parsers/error-utils.js.flow +1 -19
- package/lib/parsers/errors.d.ts +10 -0
- package/lib/parsers/errors.js +9 -29
- package/lib/parsers/errors.js.flow +2 -20
- package/lib/parsers/flow/Visitor.js +37 -0
- package/lib/parsers/flow/Visitor.js.flow +41 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +20 -2
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +20 -2
- package/lib/parsers/flow/components/commands.js +3 -0
- package/lib/parsers/flow/components/commands.js.flow +2 -1
- package/lib/parsers/flow/components/componentsUtils.js +10 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +11 -1
- package/lib/parsers/flow/components/events.js.flow +1 -1
- package/lib/parsers/flow/components/extends.js.flow +1 -1
- package/lib/parsers/flow/components/index.js.flow +1 -1
- package/lib/parsers/flow/components/options.js.flow +1 -1
- package/lib/parsers/flow/components/props.js.flow +1 -1
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js +54 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +56 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +64 -1
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +66 -1
- package/lib/parsers/flow/modules/index.js +99 -25
- package/lib/parsers/flow/modules/index.js.flow +106 -22
- package/lib/parsers/flow/parser.d.ts +10 -0
- package/lib/parsers/flow/parser.js +122 -32
- package/lib/parsers/flow/parser.js.flow +144 -24
- package/lib/parsers/flow/utils.js +33 -19
- package/lib/parsers/flow/utils.js.flow +37 -22
- package/lib/parsers/parser.d.ts +17 -0
- package/lib/parsers/parser.js.flow +102 -17
- package/lib/parsers/parserMock.js +87 -30
- package/lib/parsers/parserMock.js.flow +118 -24
- package/lib/parsers/parsers-commons.js +121 -119
- package/lib/parsers/parsers-commons.js.flow +130 -131
- package/lib/parsers/parsers-primitives.js +75 -12
- package/lib/parsers/parsers-primitives.js.flow +92 -13
- package/lib/parsers/schema/index.d.ts +10 -0
- package/lib/parsers/typescript/Visitor.js +42 -0
- package/lib/parsers/typescript/Visitor.js.flow +47 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +22 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +22 -0
- package/lib/parsers/typescript/components/commands.js +3 -0
- package/lib/parsers/typescript/components/commands.js.flow +2 -1
- package/lib/parsers/typescript/components/componentsUtils.js +5 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +6 -1
- package/lib/parsers/typescript/components/events.js.flow +1 -1
- package/lib/parsers/typescript/components/extends.js.flow +1 -1
- package/lib/parsers/typescript/components/index.js.flow +1 -1
- package/lib/parsers/typescript/components/options.js.flow +1 -1
- package/lib/parsers/typescript/components/props.js.flow +1 -1
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +52 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +54 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +142 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +146 -0
- package/lib/parsers/typescript/modules/index.js +266 -87
- package/lib/parsers/typescript/modules/index.js.flow +230 -48
- package/lib/parsers/typescript/parser.d.ts +10 -0
- package/lib/parsers/typescript/parser.js +131 -25
- package/lib/parsers/typescript/parser.js.flow +137 -26
- package/lib/parsers/typescript/utils.js +40 -20
- package/lib/parsers/typescript/utils.js.flow +44 -24
- package/lib/parsers/utils.js +0 -125
- package/lib/parsers/utils.js.flow +3 -70
- package/package.json +4 -1
- package/lib/parsers/flow/index.js +0 -80
- package/lib/parsers/flow/index.js.flow +0 -85
- package/lib/parsers/typescript/index.js +0 -85
- package/lib/parsers/typescript/index.js.flow +0 -94
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
DoubleTypeAnnotation,
|
|
17
17
|
Int32TypeAnnotation,
|
|
18
18
|
NativeModuleAliasMap,
|
|
19
|
+
NativeModuleEnumMap,
|
|
19
20
|
NativeModuleBaseTypeAnnotation,
|
|
20
21
|
NativeModuleTypeAnnotation,
|
|
21
22
|
NativeModuleFloatTypeAnnotation,
|
|
@@ -30,16 +31,23 @@ import type {
|
|
|
30
31
|
ReservedTypeAnnotation,
|
|
31
32
|
StringTypeAnnotation,
|
|
32
33
|
VoidTypeAnnotation,
|
|
34
|
+
NativeModuleObjectTypeAnnotation,
|
|
35
|
+
NativeModuleEnumDeclaration,
|
|
33
36
|
} from '../CodegenSchema';
|
|
34
37
|
import type {ParserType} from './errors';
|
|
35
38
|
import type {Parser} from './parser';
|
|
36
39
|
import type {
|
|
37
40
|
ParserErrorCapturer,
|
|
38
|
-
|
|
41
|
+
TypeResolutionStatus,
|
|
39
42
|
TypeDeclarationMap,
|
|
40
43
|
} from './utils';
|
|
41
44
|
|
|
42
|
-
const {
|
|
45
|
+
const {
|
|
46
|
+
UnsupportedUnionTypeAnnotationParserError,
|
|
47
|
+
UnsupportedTypeAnnotationParserError,
|
|
48
|
+
ParserError,
|
|
49
|
+
} = require('./errors');
|
|
50
|
+
|
|
43
51
|
const {
|
|
44
52
|
throwIfArrayElementTypeAnnotationIsUnsupported,
|
|
45
53
|
} = require('./error-utils');
|
|
@@ -102,10 +110,11 @@ function emitFunction(
|
|
|
102
110
|
typeAnnotation: $FlowFixMe,
|
|
103
111
|
types: TypeDeclarationMap,
|
|
104
112
|
aliasMap: {...NativeModuleAliasMap},
|
|
113
|
+
enumMap: {...NativeModuleEnumMap},
|
|
105
114
|
tryParse: ParserErrorCapturer,
|
|
106
115
|
cxxOnly: boolean,
|
|
107
116
|
translateTypeAnnotation: $FlowFixMe,
|
|
108
|
-
|
|
117
|
+
parser: Parser,
|
|
109
118
|
): Nullable<NativeModuleFunctionTypeAnnotation> {
|
|
110
119
|
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
|
|
111
120
|
translateFunctionTypeAnnotation(
|
|
@@ -113,10 +122,11 @@ function emitFunction(
|
|
|
113
122
|
typeAnnotation,
|
|
114
123
|
types,
|
|
115
124
|
aliasMap,
|
|
125
|
+
enumMap,
|
|
116
126
|
tryParse,
|
|
117
127
|
cxxOnly,
|
|
118
128
|
translateTypeAnnotation,
|
|
119
|
-
|
|
129
|
+
parser,
|
|
120
130
|
);
|
|
121
131
|
return wrapNullable(nullable, translateFunctionTypeAnnotationValue);
|
|
122
132
|
}
|
|
@@ -136,7 +146,7 @@ function emitString(nullable: boolean): Nullable<StringTypeAnnotation> {
|
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
function typeAliasResolution(
|
|
139
|
-
|
|
149
|
+
typeResolution: TypeResolutionStatus,
|
|
140
150
|
objectTypeAnnotation: ObjectTypeAnnotation<
|
|
141
151
|
Nullable<NativeModuleBaseTypeAnnotation>,
|
|
142
152
|
>,
|
|
@@ -145,14 +155,14 @@ function typeAliasResolution(
|
|
|
145
155
|
):
|
|
146
156
|
| Nullable<NativeModuleTypeAliasTypeAnnotation>
|
|
147
157
|
| Nullable<ObjectTypeAnnotation<Nullable<NativeModuleBaseTypeAnnotation>>> {
|
|
148
|
-
if (!
|
|
158
|
+
if (!typeResolution.successful) {
|
|
149
159
|
return wrapNullable(nullable, objectTypeAnnotation);
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
/**
|
|
153
163
|
* All aliases RHS are required.
|
|
154
164
|
*/
|
|
155
|
-
aliasMap[
|
|
165
|
+
aliasMap[typeResolution.name] = objectTypeAnnotation;
|
|
156
166
|
|
|
157
167
|
/**
|
|
158
168
|
* Nullability of type aliases is transitive.
|
|
@@ -185,7 +195,58 @@ function typeAliasResolution(
|
|
|
185
195
|
*/
|
|
186
196
|
return wrapNullable(nullable, {
|
|
187
197
|
type: 'TypeAliasTypeAnnotation',
|
|
188
|
-
name:
|
|
198
|
+
name: typeResolution.name,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function typeEnumResolution(
|
|
203
|
+
typeAnnotation: $FlowFixMe,
|
|
204
|
+
typeResolution: TypeResolutionStatus,
|
|
205
|
+
nullable: boolean,
|
|
206
|
+
hasteModuleName: string,
|
|
207
|
+
language: ParserType,
|
|
208
|
+
enumMap: {...NativeModuleEnumMap},
|
|
209
|
+
parser: Parser,
|
|
210
|
+
): Nullable<NativeModuleEnumDeclaration> {
|
|
211
|
+
if (!typeResolution.successful || typeResolution.type !== 'enum') {
|
|
212
|
+
throw new UnsupportedTypeAnnotationParserError(
|
|
213
|
+
hasteModuleName,
|
|
214
|
+
typeAnnotation,
|
|
215
|
+
language,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const enumName = typeResolution.name;
|
|
220
|
+
|
|
221
|
+
const enumMemberType = parser.parseEnumMembersType(typeAnnotation);
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
parser.validateEnumMembersSupported(typeAnnotation, enumMemberType);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
if (e instanceof Error) {
|
|
227
|
+
throw new ParserError(
|
|
228
|
+
hasteModuleName,
|
|
229
|
+
typeAnnotation,
|
|
230
|
+
`Failed parsing the enum ${enumName} in ${hasteModuleName} with the error: ${e.message}`,
|
|
231
|
+
);
|
|
232
|
+
} else {
|
|
233
|
+
throw e;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const enumMembers = parser.parseEnumMembers(typeAnnotation);
|
|
238
|
+
|
|
239
|
+
enumMap[enumName] = {
|
|
240
|
+
name: enumName,
|
|
241
|
+
type: 'EnumDeclarationWithMembers',
|
|
242
|
+
memberType: enumMemberType,
|
|
243
|
+
members: enumMembers,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
return wrapNullable(nullable, {
|
|
247
|
+
name: enumName,
|
|
248
|
+
type: 'EnumDeclaration',
|
|
249
|
+
memberType: enumMemberType,
|
|
189
250
|
});
|
|
190
251
|
}
|
|
191
252
|
|
|
@@ -196,6 +257,7 @@ function emitPromise(
|
|
|
196
257
|
nullable: boolean,
|
|
197
258
|
types: TypeDeclarationMap,
|
|
198
259
|
aliasMap: {...NativeModuleAliasMap},
|
|
260
|
+
enumMap: {...NativeModuleEnumMap},
|
|
199
261
|
tryParse: ParserErrorCapturer,
|
|
200
262
|
cxxOnly: boolean,
|
|
201
263
|
translateTypeAnnotation: $FlowFixMe,
|
|
@@ -223,8 +285,10 @@ function emitPromise(
|
|
|
223
285
|
typeAnnotation.typeParameters.params[0],
|
|
224
286
|
types,
|
|
225
287
|
aliasMap,
|
|
288
|
+
enumMap,
|
|
226
289
|
tryParse,
|
|
227
290
|
cxxOnly,
|
|
291
|
+
parser,
|
|
228
292
|
),
|
|
229
293
|
});
|
|
230
294
|
} catch {
|
|
@@ -235,7 +299,7 @@ function emitPromise(
|
|
|
235
299
|
}
|
|
236
300
|
}
|
|
237
301
|
|
|
238
|
-
function
|
|
302
|
+
function emitGenericObject(
|
|
239
303
|
nullable: boolean,
|
|
240
304
|
): Nullable<NativeModuleGenericObjectTypeAnnotation> {
|
|
241
305
|
return wrapNullable(nullable, {
|
|
@@ -243,6 +307,16 @@ function emitObject(
|
|
|
243
307
|
});
|
|
244
308
|
}
|
|
245
309
|
|
|
310
|
+
function emitObject(
|
|
311
|
+
nullable: boolean,
|
|
312
|
+
properties: Array<$FlowFixMe>,
|
|
313
|
+
): Nullable<NativeModuleObjectTypeAnnotation> {
|
|
314
|
+
return wrapNullable(nullable, {
|
|
315
|
+
type: 'ObjectTypeAnnotation',
|
|
316
|
+
properties,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
246
320
|
function emitFloat(
|
|
247
321
|
nullable: boolean,
|
|
248
322
|
): Nullable<NativeModuleFloatTypeAnnotation> {
|
|
@@ -267,7 +341,6 @@ function emitUnion(
|
|
|
267
341
|
hasteModuleName,
|
|
268
342
|
typeAnnotation,
|
|
269
343
|
unionTypes,
|
|
270
|
-
parser.language(),
|
|
271
344
|
);
|
|
272
345
|
}
|
|
273
346
|
|
|
@@ -281,12 +354,13 @@ function translateArrayTypeAnnotation(
|
|
|
281
354
|
hasteModuleName: string,
|
|
282
355
|
types: TypeDeclarationMap,
|
|
283
356
|
aliasMap: {...NativeModuleAliasMap},
|
|
357
|
+
enumMap: {...NativeModuleEnumMap},
|
|
284
358
|
cxxOnly: boolean,
|
|
285
359
|
arrayType: 'Array' | 'ReadonlyArray',
|
|
286
360
|
elementType: $FlowFixMe,
|
|
287
361
|
nullable: boolean,
|
|
288
|
-
language: ParserType,
|
|
289
362
|
translateTypeAnnotation: $FlowFixMe,
|
|
363
|
+
parser: Parser,
|
|
290
364
|
): Nullable<NativeModuleTypeAnnotation> {
|
|
291
365
|
try {
|
|
292
366
|
/**
|
|
@@ -300,6 +374,7 @@ function translateArrayTypeAnnotation(
|
|
|
300
374
|
elementType,
|
|
301
375
|
types,
|
|
302
376
|
aliasMap,
|
|
377
|
+
enumMap,
|
|
303
378
|
/**
|
|
304
379
|
* TODO(T72031674): Ensure that all ParsingErrors that are thrown
|
|
305
380
|
* while parsing the array element don't get captured and collected.
|
|
@@ -310,6 +385,7 @@ function translateArrayTypeAnnotation(
|
|
|
310
385
|
*/
|
|
311
386
|
nullGuard,
|
|
312
387
|
cxxOnly,
|
|
388
|
+
parser,
|
|
313
389
|
),
|
|
314
390
|
);
|
|
315
391
|
|
|
@@ -318,7 +394,6 @@ function translateArrayTypeAnnotation(
|
|
|
318
394
|
elementType,
|
|
319
395
|
arrayType,
|
|
320
396
|
_elementType.type,
|
|
321
|
-
language,
|
|
322
397
|
);
|
|
323
398
|
|
|
324
399
|
return wrapNullable(nullable, {
|
|
@@ -339,6 +414,7 @@ function emitArrayType(
|
|
|
339
414
|
parser: Parser,
|
|
340
415
|
types: TypeDeclarationMap,
|
|
341
416
|
aliasMap: {...NativeModuleAliasMap},
|
|
417
|
+
enumMap: {...NativeModuleEnumMap},
|
|
342
418
|
cxxOnly: boolean,
|
|
343
419
|
nullable: boolean,
|
|
344
420
|
translateTypeAnnotation: $FlowFixMe,
|
|
@@ -353,12 +429,13 @@ function emitArrayType(
|
|
|
353
429
|
hasteModuleName,
|
|
354
430
|
types,
|
|
355
431
|
aliasMap,
|
|
432
|
+
enumMap,
|
|
356
433
|
cxxOnly,
|
|
357
434
|
typeAnnotation.type,
|
|
358
435
|
typeAnnotation.typeParameters.params[0],
|
|
359
436
|
nullable,
|
|
360
|
-
parser.language(),
|
|
361
437
|
translateTypeAnnotation,
|
|
438
|
+
parser,
|
|
362
439
|
);
|
|
363
440
|
}
|
|
364
441
|
|
|
@@ -370,6 +447,7 @@ module.exports = {
|
|
|
370
447
|
emitFunction,
|
|
371
448
|
emitInt32,
|
|
372
449
|
emitNumber,
|
|
450
|
+
emitGenericObject,
|
|
373
451
|
emitObject,
|
|
374
452
|
emitPromise,
|
|
375
453
|
emitRootTag,
|
|
@@ -379,5 +457,6 @@ module.exports = {
|
|
|
379
457
|
emitMixed,
|
|
380
458
|
emitUnion,
|
|
381
459
|
typeAliasResolution,
|
|
460
|
+
typeEnumResolution,
|
|
382
461
|
translateArrayTypeAnnotation,
|
|
383
462
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
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 parse(filename: string): SchemaType | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const _require = require('../utils'),
|
|
14
|
+
isModuleRegistryCall = _require.isModuleRegistryCall;
|
|
15
|
+
function Visitor(infoMap) {
|
|
16
|
+
return {
|
|
17
|
+
CallExpression(node) {
|
|
18
|
+
if (
|
|
19
|
+
node.callee.type === 'Identifier' &&
|
|
20
|
+
node.callee.name === 'codegenNativeComponent'
|
|
21
|
+
) {
|
|
22
|
+
infoMap.isComponent = true;
|
|
23
|
+
}
|
|
24
|
+
if (isModuleRegistryCall(node)) {
|
|
25
|
+
infoMap.isModule = true;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
TSInterfaceDeclaration(node) {
|
|
29
|
+
if (
|
|
30
|
+
Array.isArray(node.extends) &&
|
|
31
|
+
node.extends.some(
|
|
32
|
+
extension => extension.expression.name === 'TurboModule',
|
|
33
|
+
)
|
|
34
|
+
) {
|
|
35
|
+
infoMap.isModule = true;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
module.exports = {
|
|
41
|
+
Visitor,
|
|
42
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const {isModuleRegistryCall} = require('../utils');
|
|
14
|
+
|
|
15
|
+
function Visitor(infoMap: {isComponent: boolean, isModule: boolean}): {
|
|
16
|
+
[type: string]: (node: $FlowFixMe) => void,
|
|
17
|
+
} {
|
|
18
|
+
return {
|
|
19
|
+
CallExpression(node: $FlowFixMe) {
|
|
20
|
+
if (
|
|
21
|
+
node.callee.type === 'Identifier' &&
|
|
22
|
+
node.callee.name === 'codegenNativeComponent'
|
|
23
|
+
) {
|
|
24
|
+
infoMap.isComponent = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (isModuleRegistryCall(node)) {
|
|
28
|
+
infoMap.isModule = true;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
TSInterfaceDeclaration(node: $FlowFixMe) {
|
|
33
|
+
if (
|
|
34
|
+
Array.isArray(node.extends) &&
|
|
35
|
+
node.extends.some(
|
|
36
|
+
extension => extension.expression.name === 'TurboModule',
|
|
37
|
+
)
|
|
38
|
+
) {
|
|
39
|
+
infoMap.isModule = true;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
Visitor,
|
|
47
|
+
};
|
|
@@ -200,6 +200,7 @@ import type {
|
|
|
200
200
|
ColorArrayValue,
|
|
201
201
|
PointValue,
|
|
202
202
|
EdgeInsetsValue,
|
|
203
|
+
DimensionValue,
|
|
203
204
|
} from 'StyleSheetTypes';
|
|
204
205
|
import type {ViewProps} from 'ViewPropTypes';
|
|
205
206
|
import type {HostComponent} from 'react-native';
|
|
@@ -298,6 +299,13 @@ export interface ModuleProps extends ViewProps {
|
|
|
298
299
|
insets_optional_key?: EdgeInsetsValue;
|
|
299
300
|
insets_optional_value: EdgeInsetsValue | null | undefined;
|
|
300
301
|
insets_optional_both?: EdgeInsetsValue | null | undefined;
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
// DimensionValue props
|
|
305
|
+
dimension_required: DimensionValue;
|
|
306
|
+
dimension_optional_key?: DimensionValue;
|
|
307
|
+
dimension_optional_value: DimensionValue | null | undefined;
|
|
308
|
+
dimension_optional_both?: DimensionValue | null | undefined;
|
|
301
309
|
}
|
|
302
310
|
|
|
303
311
|
export default codegenNativeComponent<ModuleProps>(
|
|
@@ -325,6 +333,7 @@ import type {
|
|
|
325
333
|
ColorArrayValue,
|
|
326
334
|
PointValue,
|
|
327
335
|
EdgeInsetsValue,
|
|
336
|
+
DimensionValue,
|
|
328
337
|
} from 'StyleSheetTypes';
|
|
329
338
|
import type {ViewProps} from 'ViewPropTypes';
|
|
330
339
|
import type {HostComponent} from 'react-native';
|
|
@@ -398,6 +407,12 @@ export interface ModuleProps extends ViewProps {
|
|
|
398
407
|
array_insets_optional_value: ReadonlyArray<EdgeInsetsValue> | null | undefined;
|
|
399
408
|
array_insets_optional_both?: ReadonlyArray<EdgeInsetsValue> | null | undefined;
|
|
400
409
|
|
|
410
|
+
// DimensionValue props
|
|
411
|
+
array_dimension_required: ReadonlyArray<DimensionValue>;
|
|
412
|
+
array_dimension_optional_key?: ReadonlyArray<DimensionValue>;
|
|
413
|
+
array_dimension_optional_value: ReadonlyArray<DimensionValue> | null | undefined;
|
|
414
|
+
array_dimension_optional_both?: ReadonlyArray<DimensionValue> | null | undefined;
|
|
415
|
+
|
|
401
416
|
// Object props
|
|
402
417
|
array_object_required: ReadonlyArray<Readonly<{prop: string}>>;
|
|
403
418
|
array_object_optional_key?: ReadonlyArray<Readonly<{prop: string}>>;
|
|
@@ -615,6 +630,7 @@ import type {
|
|
|
615
630
|
ColorArrayValue,
|
|
616
631
|
PointValue,
|
|
617
632
|
EdgeInsetsValue,
|
|
633
|
+
DimensionValue,
|
|
618
634
|
} from 'StyleSheetTypes';
|
|
619
635
|
import type {ViewProps} from 'ViewPropTypes';
|
|
620
636
|
import type {HostComponent} from 'react-native';
|
|
@@ -680,6 +696,12 @@ export interface ModuleProps extends ViewProps {
|
|
|
680
696
|
insets_optional_value: Readonly<{prop: EdgeInsetsValue | null | undefined}>;
|
|
681
697
|
insets_optional_both: Readonly<{prop?: EdgeInsetsValue | null | undefined}>;
|
|
682
698
|
|
|
699
|
+
// DimensionValue props
|
|
700
|
+
dimension_required: Readonly<{prop: DimensionValue}>;
|
|
701
|
+
dimension_optional_key: Readonly<{prop?: DimensionValue}>;
|
|
702
|
+
dimension_optional_value: Readonly<{prop: DimensionValue | null | undefined}>;
|
|
703
|
+
dimension_optional_both: Readonly<{prop?: DimensionValue | null | undefined}>;
|
|
704
|
+
|
|
683
705
|
// Nested object props
|
|
684
706
|
object_required: Readonly<{prop: Readonly<{nestedProp: string}>}>;
|
|
685
707
|
object_optional_key?: Readonly<{prop: Readonly<{nestedProp: string}>}>;
|
|
@@ -204,6 +204,7 @@ import type {
|
|
|
204
204
|
ColorArrayValue,
|
|
205
205
|
PointValue,
|
|
206
206
|
EdgeInsetsValue,
|
|
207
|
+
DimensionValue,
|
|
207
208
|
} from 'StyleSheetTypes';
|
|
208
209
|
import type {ViewProps} from 'ViewPropTypes';
|
|
209
210
|
import type {HostComponent} from 'react-native';
|
|
@@ -302,6 +303,13 @@ export interface ModuleProps extends ViewProps {
|
|
|
302
303
|
insets_optional_key?: EdgeInsetsValue;
|
|
303
304
|
insets_optional_value: EdgeInsetsValue | null | undefined;
|
|
304
305
|
insets_optional_both?: EdgeInsetsValue | null | undefined;
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
// DimensionValue props
|
|
309
|
+
dimension_required: DimensionValue;
|
|
310
|
+
dimension_optional_key?: DimensionValue;
|
|
311
|
+
dimension_optional_value: DimensionValue | null | undefined;
|
|
312
|
+
dimension_optional_both?: DimensionValue | null | undefined;
|
|
305
313
|
}
|
|
306
314
|
|
|
307
315
|
export default codegenNativeComponent<ModuleProps>(
|
|
@@ -330,6 +338,7 @@ import type {
|
|
|
330
338
|
ColorArrayValue,
|
|
331
339
|
PointValue,
|
|
332
340
|
EdgeInsetsValue,
|
|
341
|
+
DimensionValue,
|
|
333
342
|
} from 'StyleSheetTypes';
|
|
334
343
|
import type {ViewProps} from 'ViewPropTypes';
|
|
335
344
|
import type {HostComponent} from 'react-native';
|
|
@@ -403,6 +412,12 @@ export interface ModuleProps extends ViewProps {
|
|
|
403
412
|
array_insets_optional_value: ReadonlyArray<EdgeInsetsValue> | null | undefined;
|
|
404
413
|
array_insets_optional_both?: ReadonlyArray<EdgeInsetsValue> | null | undefined;
|
|
405
414
|
|
|
415
|
+
// DimensionValue props
|
|
416
|
+
array_dimension_required: ReadonlyArray<DimensionValue>;
|
|
417
|
+
array_dimension_optional_key?: ReadonlyArray<DimensionValue>;
|
|
418
|
+
array_dimension_optional_value: ReadonlyArray<DimensionValue> | null | undefined;
|
|
419
|
+
array_dimension_optional_both?: ReadonlyArray<DimensionValue> | null | undefined;
|
|
420
|
+
|
|
406
421
|
// Object props
|
|
407
422
|
array_object_required: ReadonlyArray<Readonly<{prop: string}>>;
|
|
408
423
|
array_object_optional_key?: ReadonlyArray<Readonly<{prop: string}>>;
|
|
@@ -622,6 +637,7 @@ import type {
|
|
|
622
637
|
ColorArrayValue,
|
|
623
638
|
PointValue,
|
|
624
639
|
EdgeInsetsValue,
|
|
640
|
+
DimensionValue,
|
|
625
641
|
} from 'StyleSheetTypes';
|
|
626
642
|
import type {ViewProps} from 'ViewPropTypes';
|
|
627
643
|
import type {HostComponent} from 'react-native';
|
|
@@ -687,6 +703,12 @@ export interface ModuleProps extends ViewProps {
|
|
|
687
703
|
insets_optional_value: Readonly<{prop: EdgeInsetsValue | null | undefined}>;
|
|
688
704
|
insets_optional_both: Readonly<{prop?: EdgeInsetsValue | null | undefined}>;
|
|
689
705
|
|
|
706
|
+
// DimensionValue props
|
|
707
|
+
dimension_required: Readonly<{prop: DimensionValue}>;
|
|
708
|
+
dimension_optional_key: Readonly<{prop?: DimensionValue}>;
|
|
709
|
+
dimension_optional_value: Readonly<{prop: DimensionValue | null | undefined}>;
|
|
710
|
+
dimension_optional_both: Readonly<{prop?: DimensionValue | null | undefined}>;
|
|
711
|
+
|
|
690
712
|
// Nested object props
|
|
691
713
|
object_required: Readonly<{prop: Readonly<{nestedProp: string}>}>;
|
|
692
714
|
object_optional_key?: Readonly<{prop: Readonly<{nestedProp: string}>}>;
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
const _require = require('../parseTopLevelType'),
|
|
14
14
|
parseTopLevelType = _require.parseTopLevelType;
|
|
15
|
+
|
|
16
|
+
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
17
|
+
|
|
15
18
|
function buildCommandSchemaInternal(name, optional, parameters, types) {
|
|
16
19
|
var _firstParam$typeAnnot, _firstParam$typeAnnot2;
|
|
17
20
|
const firstParam = parameters[0].typeAnnotation;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow
|
|
7
|
+
* @flow strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
import type {TypeDeclarationMap} from '../../utils';
|
|
18
18
|
const {parseTopLevelType} = require('../parseTopLevelType');
|
|
19
19
|
|
|
20
|
+
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
20
21
|
type EventTypeAST = Object;
|
|
21
22
|
|
|
22
23
|
function buildCommandSchemaInternal(
|
|
@@ -218,6 +218,11 @@ function getCommonTypeAnnotation(
|
|
|
218
218
|
type: 'ReservedPropTypeAnnotation',
|
|
219
219
|
name: 'EdgeInsetsPrimitive',
|
|
220
220
|
};
|
|
221
|
+
case 'DimensionValue':
|
|
222
|
+
return {
|
|
223
|
+
type: 'ReservedPropTypeAnnotation',
|
|
224
|
+
name: 'DimensionPrimitive',
|
|
225
|
+
};
|
|
221
226
|
case 'TSUnionType':
|
|
222
227
|
return getUnionOfLiterals(
|
|
223
228
|
name,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow strict
|
|
7
|
+
* @flow strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -228,6 +228,11 @@ function getCommonTypeAnnotation<T>(
|
|
|
228
228
|
type: 'ReservedPropTypeAnnotation',
|
|
229
229
|
name: 'EdgeInsetsPrimitive',
|
|
230
230
|
};
|
|
231
|
+
case 'DimensionValue':
|
|
232
|
+
return {
|
|
233
|
+
type: 'ReservedPropTypeAnnotation',
|
|
234
|
+
name: 'DimensionPrimitive',
|
|
235
|
+
};
|
|
231
236
|
case 'TSUnionType':
|
|
232
237
|
return getUnionOfLiterals(
|
|
233
238
|
name,
|
|
@@ -149,6 +149,56 @@ export interface Spec2 extends TurboModule {
|
|
|
149
149
|
readonly getSth: (a: number | null | undefined) => void;
|
|
150
150
|
}
|
|
151
151
|
`;
|
|
152
|
+
const EMPTY_ENUM_NATIVE_MODULE = `
|
|
153
|
+
/**
|
|
154
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
155
|
+
*
|
|
156
|
+
* This source code is licensed under the MIT license found in the
|
|
157
|
+
* LICENSE file in the root directory of this source tree.
|
|
158
|
+
*
|
|
159
|
+
* @format
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
163
|
+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
|
|
164
|
+
|
|
165
|
+
export enum SomeEnum {
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface Spec extends TurboModule {
|
|
169
|
+
readonly getEnums: (a: SomeEnum) => string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export default TurboModuleRegistry.getEnforcing<Spec>(
|
|
173
|
+
'EmptyEnumNativeModule',
|
|
174
|
+
);
|
|
175
|
+
`;
|
|
176
|
+
const MIXED_VALUES_ENUM_NATIVE_MODULE = `
|
|
177
|
+
/**
|
|
178
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
179
|
+
*
|
|
180
|
+
* This source code is licensed under the MIT license found in the
|
|
181
|
+
* LICENSE file in the root directory of this source tree.
|
|
182
|
+
*
|
|
183
|
+
* @format
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
187
|
+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
|
|
188
|
+
|
|
189
|
+
export enum SomeEnum {
|
|
190
|
+
NUM = 1,
|
|
191
|
+
STR = 'str',
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface Spec extends TurboModule {
|
|
195
|
+
readonly getEnums: (a: SomeEnum) => string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default TurboModuleRegistry.getEnforcing<Spec>(
|
|
199
|
+
'MixedValuesEnumNativeModule',
|
|
200
|
+
);
|
|
201
|
+
`;
|
|
152
202
|
module.exports = {
|
|
153
203
|
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
|
|
154
204
|
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
|
|
@@ -157,4 +207,6 @@ module.exports = {
|
|
|
157
207
|
TWO_NATIVE_MODULES_EXPORTED_WITH_DEFAULT,
|
|
158
208
|
NATIVE_MODULES_WITH_NOT_ONLY_METHODS,
|
|
159
209
|
TWO_NATIVE_EXTENDING_TURBO_MODULE,
|
|
210
|
+
EMPTY_ENUM_NATIVE_MODULE,
|
|
211
|
+
MIXED_VALUES_ENUM_NATIVE_MODULE,
|
|
160
212
|
};
|