@react-native/codegen 0.87.0-nightly-20260519-58cd1bf58 → 0.87.0-nightly-20260528-eaf770433
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 +6 -1
- package/lib/CodegenSchema.js.flow +13 -8
- package/lib/generators/ReservedPrimitiveTypes.js.flow +84 -79
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +5 -5
- package/lib/generators/modules/GenerateModuleH.js +4 -0
- package/lib/generators/modules/GenerateModuleH.js.flow +4 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js +6 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +12 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js +6 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +6 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +2 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +4 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +4 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +8 -0
- package/lib/parsers/error-utils.js +4 -2
- package/lib/parsers/error-utils.js.flow +2 -0
- package/lib/parsers/errors.js.flow +1 -1
- package/lib/parsers/flow/components/componentsUtils.js.flow +2 -2
- package/lib/parsers/parsers-commons.js +1 -1
- package/lib/parsers/parsers-commons.js.flow +4 -3
- package/lib/parsers/parsers-primitives.js +14 -5
- package/lib/parsers/parsers-primitives.js.flow +27 -13
- package/package.json +2 -2
package/lib/CodegenSchema.d.ts
CHANGED
|
@@ -46,6 +46,10 @@ export interface VoidTypeAnnotation {
|
|
|
46
46
|
readonly type: 'VoidTypeAnnotation';
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
export interface ArrayBufferTypeAnnotation {
|
|
50
|
+
readonly type: 'ArrayBufferTypeAnnotation';
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
export interface BooleanLiteralTypeAnnotation {
|
|
50
54
|
readonly type: 'BooleanLiteralTypeAnnotation';
|
|
51
55
|
readonly value: boolean;
|
|
@@ -417,7 +421,8 @@ export type NativeModuleEventEmitterTypeAnnotation =
|
|
|
417
421
|
| ArrayTypeAnnotation<NativeModuleEventEmitterBaseTypeAnnotation>;
|
|
418
422
|
|
|
419
423
|
export type NativeModuleBaseTypeAnnotation =
|
|
420
|
-
|
|
424
|
+
ArrayBufferTypeAnnotation
|
|
425
|
+
| NativeModuleStringTypeAnnotation
|
|
421
426
|
| StringLiteralTypeAnnotation
|
|
422
427
|
| StringLiteralUnionTypeAnnotation
|
|
423
428
|
| NativeModuleNumberTypeAnnotation
|
|
@@ -68,14 +68,18 @@ export type VoidTypeAnnotation = Readonly<{
|
|
|
68
68
|
type: 'VoidTypeAnnotation',
|
|
69
69
|
}>;
|
|
70
70
|
|
|
71
|
-
export type
|
|
71
|
+
export type ArrayBufferTypeAnnotation = Readonly<{
|
|
72
|
+
type: 'ArrayBufferTypeAnnotation',
|
|
73
|
+
}>;
|
|
74
|
+
|
|
75
|
+
export type ObjectTypeAnnotation<out T> = Readonly<{
|
|
72
76
|
type: 'ObjectTypeAnnotation',
|
|
73
77
|
properties: ReadonlyArray<NamedShape<T>>,
|
|
74
78
|
// metadata for objects that generated from interfaces
|
|
75
79
|
baseTypes?: ReadonlyArray<string>,
|
|
76
80
|
}>;
|
|
77
81
|
|
|
78
|
-
export type UnionTypeAnnotation
|
|
82
|
+
export type UnionTypeAnnotation<out T> = Readonly<{
|
|
79
83
|
type: 'UnionTypeAnnotation',
|
|
80
84
|
types: ReadonlyArray<T>,
|
|
81
85
|
}>;
|
|
@@ -89,13 +93,13 @@ export type EventEmitterTypeAnnotation = Readonly<{
|
|
|
89
93
|
typeAnnotation: NativeModuleEventEmitterTypeAnnotation | $FlowFixMe,
|
|
90
94
|
}>;
|
|
91
95
|
|
|
92
|
-
type FunctionTypeAnnotation
|
|
96
|
+
type FunctionTypeAnnotation<out P, out R> = Readonly<{
|
|
93
97
|
type: 'FunctionTypeAnnotation',
|
|
94
98
|
params: ReadonlyArray<NamedShape<P>>,
|
|
95
99
|
returnTypeAnnotation: R,
|
|
96
100
|
}>;
|
|
97
101
|
|
|
98
|
-
export type NamedShape
|
|
102
|
+
export type NamedShape<out T> = Readonly<{
|
|
99
103
|
name: string,
|
|
100
104
|
optional: boolean,
|
|
101
105
|
typeAnnotation: T,
|
|
@@ -191,7 +195,7 @@ export type ComponentCommandArrayTypeAnnotation = ArrayTypeAnnotation<
|
|
|
191
195
|
| MixedTypeAnnotation,
|
|
192
196
|
>;
|
|
193
197
|
|
|
194
|
-
export type ArrayTypeAnnotation
|
|
198
|
+
export type ArrayTypeAnnotation<out T> = Readonly<{
|
|
195
199
|
type: 'ArrayTypeAnnotation',
|
|
196
200
|
elementType: T,
|
|
197
201
|
}>;
|
|
@@ -265,11 +269,11 @@ export type ReservedTypeAnnotation = Readonly<{
|
|
|
265
269
|
/**
|
|
266
270
|
* NativeModule Types
|
|
267
271
|
*/
|
|
268
|
-
export type Nullable
|
|
272
|
+
export type Nullable<out T extends NativeModuleTypeAnnotation> =
|
|
269
273
|
| NullableTypeAnnotation<T>
|
|
270
274
|
| T;
|
|
271
275
|
|
|
272
|
-
export type NullableTypeAnnotation
|
|
276
|
+
export type NullableTypeAnnotation<out T extends NativeModuleTypeAnnotation> =
|
|
273
277
|
Readonly<{
|
|
274
278
|
type: 'NullableTypeAnnotation',
|
|
275
279
|
typeAnnotation: T,
|
|
@@ -317,7 +321,7 @@ export type NativeModuleObjectTypeAnnotation = ObjectTypeAnnotation<
|
|
|
317
321
|
>;
|
|
318
322
|
|
|
319
323
|
export type NativeModuleArrayTypeAnnotation<
|
|
320
|
-
|
|
324
|
+
out T extends Nullable<NativeModuleBaseTypeAnnotation>,
|
|
321
325
|
> = ArrayTypeAnnotation<
|
|
322
326
|
| T
|
|
323
327
|
/**
|
|
@@ -411,6 +415,7 @@ export type NativeModuleEventEmitterTypeAnnotation =
|
|
|
411
415
|
| ArrayTypeAnnotation<NativeModuleEventEmitterBaseTypeAnnotation>;
|
|
412
416
|
|
|
413
417
|
export type NativeModuleBaseTypeAnnotation =
|
|
418
|
+
| ArrayBufferTypeAnnotation
|
|
414
419
|
| StringTypeAnnotation
|
|
415
420
|
| StringLiteralTypeAnnotation
|
|
416
421
|
| StringLiteralUnionTypeAnnotation
|
|
@@ -28,99 +28,104 @@ export type ReservedPrimitiveName =
|
|
|
28
28
|
| 'DimensionPrimitive';
|
|
29
29
|
|
|
30
30
|
type CppTypeInfo = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
readonly typeName: string,
|
|
32
|
+
readonly localIncludes: ReadonlyArray<string>,
|
|
33
|
+
readonly conversionIncludes: ReadonlyArray<string>,
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
type JavaImportInfo = {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
readonly interfaceImports: ReadonlyArray<string>,
|
|
38
|
+
readonly delegateImports: ReadonlyArray<string>,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
type ReservedTypeMapping = {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
readonly cpp: CppTypeInfo,
|
|
43
|
+
readonly java: JavaImportInfo,
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const RESERVED_TYPES: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const RESERVED_TYPES: {readonly [ReservedPrimitiveName]: ReservedTypeMapping} =
|
|
47
|
+
{
|
|
48
|
+
ColorPrimitive: {
|
|
49
|
+
cpp: {
|
|
50
|
+
typeName: 'SharedColor',
|
|
51
|
+
localIncludes: ['#include <react/renderer/graphics/Color.h>'],
|
|
52
|
+
conversionIncludes: [],
|
|
53
|
+
},
|
|
54
|
+
java: {
|
|
55
|
+
interfaceImports: [],
|
|
56
|
+
delegateImports: [
|
|
57
|
+
'import com.facebook.react.bridge.ColorPropConverter;',
|
|
58
|
+
],
|
|
59
|
+
},
|
|
52
60
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
ImageSourcePrimitive: {
|
|
62
|
+
cpp: {
|
|
63
|
+
typeName: 'ImageSource',
|
|
64
|
+
localIncludes: ['#include <react/renderer/imagemanager/primitives.h>'],
|
|
65
|
+
conversionIncludes: [
|
|
66
|
+
'#include <react/renderer/components/image/conversions.h>',
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
java: {
|
|
70
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
71
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
72
|
+
},
|
|
56
73
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
ImageRequestPrimitive: {
|
|
75
|
+
cpp: {
|
|
76
|
+
typeName: 'ImageRequest',
|
|
77
|
+
localIncludes: [
|
|
78
|
+
'#include <react/renderer/imagemanager/ImageRequest.h>',
|
|
79
|
+
],
|
|
80
|
+
conversionIncludes: [],
|
|
81
|
+
},
|
|
82
|
+
java: {
|
|
83
|
+
// ImageRequestPrimitive is not used in Java component props
|
|
84
|
+
interfaceImports: [],
|
|
85
|
+
delegateImports: [],
|
|
86
|
+
},
|
|
65
87
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
PointPrimitive: {
|
|
89
|
+
cpp: {
|
|
90
|
+
typeName: 'Point',
|
|
91
|
+
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
|
|
92
|
+
conversionIncludes: [],
|
|
93
|
+
},
|
|
94
|
+
java: {
|
|
95
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
96
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
97
|
+
},
|
|
69
98
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
EdgeInsetsPrimitive: {
|
|
100
|
+
cpp: {
|
|
101
|
+
typeName: 'EdgeInsets',
|
|
102
|
+
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
|
|
103
|
+
conversionIncludes: [],
|
|
104
|
+
},
|
|
105
|
+
java: {
|
|
106
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
107
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
108
|
+
},
|
|
76
109
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
110
|
+
DimensionPrimitive: {
|
|
111
|
+
cpp: {
|
|
112
|
+
typeName: 'YGValue',
|
|
113
|
+
localIncludes: [
|
|
114
|
+
'#include <yoga/Yoga.h>',
|
|
115
|
+
'#include <react/renderer/core/graphicsConversions.h>',
|
|
116
|
+
],
|
|
117
|
+
conversionIncludes: [
|
|
118
|
+
'#include <react/renderer/components/view/conversions.h>',
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
java: {
|
|
122
|
+
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
|
|
123
|
+
delegateImports: [
|
|
124
|
+
'import com.facebook.react.bridge.DimensionPropConverter;',
|
|
125
|
+
],
|
|
126
|
+
},
|
|
81
127
|
},
|
|
82
|
-
}
|
|
83
|
-
PointPrimitive: {
|
|
84
|
-
cpp: {
|
|
85
|
-
typeName: 'Point',
|
|
86
|
-
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
|
|
87
|
-
conversionIncludes: [],
|
|
88
|
-
},
|
|
89
|
-
java: {
|
|
90
|
-
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
91
|
-
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
EdgeInsetsPrimitive: {
|
|
95
|
-
cpp: {
|
|
96
|
-
typeName: 'EdgeInsets',
|
|
97
|
-
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
|
|
98
|
-
conversionIncludes: [],
|
|
99
|
-
},
|
|
100
|
-
java: {
|
|
101
|
-
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
102
|
-
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
DimensionPrimitive: {
|
|
106
|
-
cpp: {
|
|
107
|
-
typeName: 'YGValue',
|
|
108
|
-
localIncludes: [
|
|
109
|
-
'#include <yoga/Yoga.h>',
|
|
110
|
-
'#include <react/renderer/core/graphicsConversions.h>',
|
|
111
|
-
],
|
|
112
|
-
conversionIncludes: [
|
|
113
|
-
'#include <react/renderer/components/view/conversions.h>',
|
|
114
|
-
],
|
|
115
|
-
},
|
|
116
|
-
java: {
|
|
117
|
-
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
|
|
118
|
-
delegateImports: [
|
|
119
|
-
'import com.facebook.react.bridge.DimensionPropConverter;',
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
};
|
|
128
|
+
};
|
|
124
129
|
|
|
125
130
|
function getCppTypeForReservedPrimitive(name: ReservedPrimitiveName): string {
|
|
126
131
|
return RESERVED_TYPES[name].cpp.typeName;
|
|
@@ -49,13 +49,13 @@ function getNativeTypeFromAnnotation(
|
|
|
49
49
|
| ObjectTypeAnnotation<PropTypeAnnotation>
|
|
50
50
|
| ReservedPropTypeAnnotation
|
|
51
51
|
| {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
readonly default: string,
|
|
53
|
+
readonly options: ReadonlyArray<string>,
|
|
54
|
+
readonly type: 'StringEnumTypeAnnotation',
|
|
55
55
|
}
|
|
56
56
|
| {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
readonly elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
|
|
58
|
+
readonly type: 'ArrayTypeAnnotation',
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
61
|
nameParts: ReadonlyArray<string>,
|
|
@@ -100,6 +100,8 @@ function serializeArg(moduleName, arg, index, resolveAlias, enumMap) {
|
|
|
100
100
|
return wrap(val => `${val}.asObject(rt)`);
|
|
101
101
|
case 'MixedTypeAnnotation':
|
|
102
102
|
return wrap(val => `jsi::Value(rt, ${val})`);
|
|
103
|
+
case 'ArrayBufferTypeAnnotation':
|
|
104
|
+
return wrap(val => `${val}.asObject(rt).getArrayBuffer(rt)`);
|
|
103
105
|
default:
|
|
104
106
|
realTypeAnnotation.type;
|
|
105
107
|
throw new Error(`Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.type}"`);
|
|
@@ -231,6 +233,8 @@ function translatePrimitiveJSTypeToCpp(moduleName, parentObjectAliasName, nullab
|
|
|
231
233
|
return wrapOptional('jsi::Value', isRequired);
|
|
232
234
|
case 'MixedTypeAnnotation':
|
|
233
235
|
return wrapOptional('jsi::Value', isRequired);
|
|
236
|
+
case 'ArrayBufferTypeAnnotation':
|
|
237
|
+
return wrapOptional('jsi::ArrayBuffer', isRequired);
|
|
234
238
|
default:
|
|
235
239
|
realTypeAnnotation.type;
|
|
236
240
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -146,6 +146,8 @@ function serializeArg(
|
|
|
146
146
|
return wrap(val => `${val}.asObject(rt)`);
|
|
147
147
|
case 'MixedTypeAnnotation':
|
|
148
148
|
return wrap(val => `jsi::Value(rt, ${val})`);
|
|
149
|
+
case 'ArrayBufferTypeAnnotation':
|
|
150
|
+
return wrap(val => `${val}.asObject(rt).getArrayBuffer(rt)`);
|
|
149
151
|
default:
|
|
150
152
|
realTypeAnnotation.type as empty;
|
|
151
153
|
throw new Error(
|
|
@@ -307,6 +309,8 @@ function translatePrimitiveJSTypeToCpp(
|
|
|
307
309
|
return wrapOptional('jsi::Value', isRequired);
|
|
308
310
|
case 'MixedTypeAnnotation':
|
|
309
311
|
return wrapOptional('jsi::Value', isRequired);
|
|
312
|
+
case 'ArrayBufferTypeAnnotation':
|
|
313
|
+
return wrapOptional('jsi::ArrayBuffer', isRequired);
|
|
310
314
|
default:
|
|
311
315
|
realTypeAnnotation.type as empty;
|
|
312
316
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -202,6 +202,8 @@ function translateFunctionParamToJavaType(param, createErrorMessage, resolveAlia
|
|
|
202
202
|
case 'FunctionTypeAnnotation':
|
|
203
203
|
imports.add('com.facebook.react.bridge.Callback');
|
|
204
204
|
return wrapOptional('Callback', isRequired);
|
|
205
|
+
case 'ArrayBufferTypeAnnotation':
|
|
206
|
+
throw new Error(`${createErrorMessage(realTypeAnnotation.type)} ArrayBuffer is only supported for C++ TurboModules.`);
|
|
205
207
|
default:
|
|
206
208
|
realTypeAnnotation.type;
|
|
207
209
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -282,6 +284,8 @@ function translateFunctionReturnTypeToJavaType(nullableReturnTypeAnnotation, cre
|
|
|
282
284
|
case 'ArrayTypeAnnotation':
|
|
283
285
|
imports.add('com.facebook.react.bridge.WritableArray');
|
|
284
286
|
return wrapOptional('WritableArray', isRequired);
|
|
287
|
+
case 'ArrayBufferTypeAnnotation':
|
|
288
|
+
throw new Error(`${createErrorMessage(realTypeAnnotation.type)} ArrayBuffer is only supported for C++ TurboModules.`);
|
|
285
289
|
default:
|
|
286
290
|
realTypeAnnotation.type;
|
|
287
291
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -354,6 +358,8 @@ function getFalsyReturnStatementFromReturnType(nullableReturnTypeAnnotation, cre
|
|
|
354
358
|
return 'return null;';
|
|
355
359
|
case 'ArrayTypeAnnotation':
|
|
356
360
|
return 'return null;';
|
|
361
|
+
case 'ArrayBufferTypeAnnotation':
|
|
362
|
+
throw new Error(`${createErrorMessage(realTypeAnnotation.type)} ArrayBuffer is only supported for C++ TurboModules.`);
|
|
357
363
|
default:
|
|
358
364
|
realTypeAnnotation.type;
|
|
359
365
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -267,6 +267,10 @@ function translateFunctionParamToJavaType(
|
|
|
267
267
|
case 'FunctionTypeAnnotation':
|
|
268
268
|
imports.add('com.facebook.react.bridge.Callback');
|
|
269
269
|
return wrapOptional('Callback', isRequired);
|
|
270
|
+
case 'ArrayBufferTypeAnnotation':
|
|
271
|
+
throw new Error(
|
|
272
|
+
`${createErrorMessage(realTypeAnnotation.type)} ArrayBuffer is only supported for C++ TurboModules.`,
|
|
273
|
+
);
|
|
270
274
|
default:
|
|
271
275
|
realTypeAnnotation.type as 'MixedTypeAnnotation';
|
|
272
276
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -361,6 +365,10 @@ function translateFunctionReturnTypeToJavaType(
|
|
|
361
365
|
case 'ArrayTypeAnnotation':
|
|
362
366
|
imports.add('com.facebook.react.bridge.WritableArray');
|
|
363
367
|
return wrapOptional('WritableArray', isRequired);
|
|
368
|
+
case 'ArrayBufferTypeAnnotation':
|
|
369
|
+
throw new Error(
|
|
370
|
+
`${createErrorMessage(realTypeAnnotation.type)} ArrayBuffer is only supported for C++ TurboModules.`,
|
|
371
|
+
);
|
|
364
372
|
default:
|
|
365
373
|
realTypeAnnotation.type as 'MixedTypeAnnotation';
|
|
366
374
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -443,6 +451,10 @@ function getFalsyReturnStatementFromReturnType(
|
|
|
443
451
|
return 'return null;';
|
|
444
452
|
case 'ArrayTypeAnnotation':
|
|
445
453
|
return 'return null;';
|
|
454
|
+
case 'ArrayBufferTypeAnnotation':
|
|
455
|
+
throw new Error(
|
|
456
|
+
`${createErrorMessage(realTypeAnnotation.type)} ArrayBuffer is only supported for C++ TurboModules.`,
|
|
457
|
+
);
|
|
446
458
|
default:
|
|
447
459
|
realTypeAnnotation.type as 'MixedTypeAnnotation';
|
|
448
460
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -146,6 +146,8 @@ function translateReturnTypeToKind(nullableTypeAnnotation, resolveAlias) {
|
|
|
146
146
|
return 'ObjectKind';
|
|
147
147
|
case 'ArrayTypeAnnotation':
|
|
148
148
|
return 'ArrayKind';
|
|
149
|
+
case 'ArrayBufferTypeAnnotation':
|
|
150
|
+
throw new Error('ArrayBuffer is only supported for C++ TurboModules.');
|
|
149
151
|
default:
|
|
150
152
|
realTypeAnnotation.type;
|
|
151
153
|
throw new Error(`Unknown prop type for returning value, found: ${realTypeAnnotation.type}"`);
|
|
@@ -221,6 +223,8 @@ function translateParamTypeToJniType(param, resolveAlias) {
|
|
|
221
223
|
return 'Lcom/facebook/react/bridge/ReadableArray;';
|
|
222
224
|
case 'FunctionTypeAnnotation':
|
|
223
225
|
return 'Lcom/facebook/react/bridge/Callback;';
|
|
226
|
+
case 'ArrayBufferTypeAnnotation':
|
|
227
|
+
throw new Error('ArrayBuffer is only supported for C++ TurboModules.');
|
|
224
228
|
default:
|
|
225
229
|
realTypeAnnotation.type;
|
|
226
230
|
throw new Error(`Unknown prop type for method arg, found: ${realTypeAnnotation.type}"`);
|
|
@@ -293,6 +297,8 @@ function translateReturnTypeToJniType(nullableTypeAnnotation, resolveAlias) {
|
|
|
293
297
|
return 'Lcom/facebook/react/bridge/WritableMap;';
|
|
294
298
|
case 'ArrayTypeAnnotation':
|
|
295
299
|
return 'Lcom/facebook/react/bridge/WritableArray;';
|
|
300
|
+
case 'ArrayBufferTypeAnnotation':
|
|
301
|
+
throw new Error('ArrayBuffer is only supported for C++ TurboModules.');
|
|
296
302
|
default:
|
|
297
303
|
realTypeAnnotation.type;
|
|
298
304
|
throw new Error(`Unknown prop type for method return type, found: ${realTypeAnnotation.type}"`);
|
|
@@ -216,6 +216,8 @@ function translateReturnTypeToKind(
|
|
|
216
216
|
return 'ObjectKind';
|
|
217
217
|
case 'ArrayTypeAnnotation':
|
|
218
218
|
return 'ArrayKind';
|
|
219
|
+
case 'ArrayBufferTypeAnnotation':
|
|
220
|
+
throw new Error('ArrayBuffer is only supported for C++ TurboModules.');
|
|
219
221
|
default:
|
|
220
222
|
realTypeAnnotation.type as 'MixedTypeAnnotation';
|
|
221
223
|
throw new Error(
|
|
@@ -303,6 +305,8 @@ function translateParamTypeToJniType(
|
|
|
303
305
|
return 'Lcom/facebook/react/bridge/ReadableArray;';
|
|
304
306
|
case 'FunctionTypeAnnotation':
|
|
305
307
|
return 'Lcom/facebook/react/bridge/Callback;';
|
|
308
|
+
case 'ArrayBufferTypeAnnotation':
|
|
309
|
+
throw new Error('ArrayBuffer is only supported for C++ TurboModules.');
|
|
306
310
|
default:
|
|
307
311
|
realTypeAnnotation.type as 'MixedTypeAnnotation';
|
|
308
312
|
throw new Error(
|
|
@@ -387,6 +391,8 @@ function translateReturnTypeToJniType(
|
|
|
387
391
|
return 'Lcom/facebook/react/bridge/WritableMap;';
|
|
388
392
|
case 'ArrayTypeAnnotation':
|
|
389
393
|
return 'Lcom/facebook/react/bridge/WritableArray;';
|
|
394
|
+
case 'ArrayBufferTypeAnnotation':
|
|
395
|
+
throw new Error('ArrayBuffer is only supported for C++ TurboModules.');
|
|
390
396
|
default:
|
|
391
397
|
realTypeAnnotation.type as 'MixedTypeAnnotation';
|
|
392
398
|
throw new Error(
|
|
@@ -51,6 +51,8 @@ class StructCollector {
|
|
|
51
51
|
return wrapNullable(nullable, typeAnnotation);
|
|
52
52
|
case 'MixedTypeAnnotation':
|
|
53
53
|
throw new Error('Mixed types are unsupported in structs');
|
|
54
|
+
case 'ArrayBufferTypeAnnotation':
|
|
55
|
+
throw new Error('ArrayBuffer is unsupported in TurboModule struct types.');
|
|
54
56
|
case 'UnionTypeAnnotation':
|
|
55
57
|
try {
|
|
56
58
|
const validUnionType = parseValidUnionType(typeAnnotation);
|
|
@@ -132,6 +132,10 @@ class StructCollector {
|
|
|
132
132
|
return wrapNullable(nullable, typeAnnotation);
|
|
133
133
|
case 'MixedTypeAnnotation':
|
|
134
134
|
throw new Error('Mixed types are unsupported in structs');
|
|
135
|
+
case 'ArrayBufferTypeAnnotation':
|
|
136
|
+
throw new Error(
|
|
137
|
+
'ArrayBuffer is unsupported in TurboModule struct types.',
|
|
138
|
+
);
|
|
135
139
|
case 'UnionTypeAnnotation':
|
|
136
140
|
try {
|
|
137
141
|
const validUnionType = parseValidUnionType(typeAnnotation);
|
|
@@ -243,6 +243,8 @@ function getReturnObjCType(methodName, nullableTypeAnnotation) {
|
|
|
243
243
|
}
|
|
244
244
|
case 'GenericObjectTypeAnnotation':
|
|
245
245
|
return wrapOptional('NSDictionary *', isRequired);
|
|
246
|
+
case 'ArrayBufferTypeAnnotation':
|
|
247
|
+
throw new Error(`Unsupported return type for ${methodName}: ArrayBuffer is only supported for C++ TurboModules.`);
|
|
246
248
|
default:
|
|
247
249
|
typeAnnotation.type;
|
|
248
250
|
throw new Error(`Unsupported return type for ${methodName}. Found: ${typeAnnotation.type}`);
|
|
@@ -307,6 +309,8 @@ function getReturnJSType(methodName, nullableTypeAnnotation) {
|
|
|
307
309
|
validUnionType;
|
|
308
310
|
throw new Error(`Unsupported union member types`);
|
|
309
311
|
}
|
|
312
|
+
case 'ArrayBufferTypeAnnotation':
|
|
313
|
+
throw new Error(`Unsupported return type for ${methodName}: ArrayBuffer is only supported for C++ TurboModules.`);
|
|
310
314
|
default:
|
|
311
315
|
typeAnnotation.type;
|
|
312
316
|
throw new Error(`Unsupported return type for ${methodName}. Found: ${typeAnnotation.type}`);
|
|
@@ -387,6 +387,10 @@ function getReturnObjCType(
|
|
|
387
387
|
}
|
|
388
388
|
case 'GenericObjectTypeAnnotation':
|
|
389
389
|
return wrapOptional('NSDictionary *', isRequired);
|
|
390
|
+
case 'ArrayBufferTypeAnnotation':
|
|
391
|
+
throw new Error(
|
|
392
|
+
`Unsupported return type for ${methodName}: ArrayBuffer is only supported for C++ TurboModules.`,
|
|
393
|
+
);
|
|
390
394
|
default:
|
|
391
395
|
typeAnnotation.type as 'MixedTypeAnnotation';
|
|
392
396
|
throw new Error(
|
|
@@ -459,6 +463,10 @@ function getReturnJSType(
|
|
|
459
463
|
validUnionType as empty;
|
|
460
464
|
throw new Error(`Unsupported union member types`);
|
|
461
465
|
}
|
|
466
|
+
case 'ArrayBufferTypeAnnotation':
|
|
467
|
+
throw new Error(
|
|
468
|
+
`Unsupported return type for ${methodName}: ArrayBuffer is only supported for C++ TurboModules.`,
|
|
469
|
+
);
|
|
462
470
|
default:
|
|
463
471
|
typeAnnotation.type as 'MixedTypeAnnotation';
|
|
464
472
|
throw new Error(
|
|
@@ -80,7 +80,8 @@ function throwIfModuleTypeIsUnsupported(nativeModuleName, propertyValue, propert
|
|
|
80
80
|
const UnsupportedObjectPropertyTypeToInvalidPropertyValueTypeMap = {
|
|
81
81
|
FunctionTypeAnnotation: 'FunctionTypeAnnotation',
|
|
82
82
|
VoidTypeAnnotation: 'void',
|
|
83
|
-
PromiseTypeAnnotation: 'Promise'
|
|
83
|
+
PromiseTypeAnnotation: 'Promise',
|
|
84
|
+
ArrayBufferTypeAnnotation: 'ArrayBuffer'
|
|
84
85
|
};
|
|
85
86
|
function throwIfPropertyValueTypeIsUnsupported(moduleName, propertyValue, propertyKey, type) {
|
|
86
87
|
const invalidPropertyValueType = UnsupportedObjectPropertyTypeToInvalidPropertyValueTypeMap[type];
|
|
@@ -98,7 +99,8 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(hasteModuleName, flowEle
|
|
|
98
99
|
const TypeMap = {
|
|
99
100
|
FunctionTypeAnnotation: 'FunctionTypeAnnotation',
|
|
100
101
|
VoidTypeAnnotation: 'void',
|
|
101
|
-
PromiseTypeAnnotation: 'Promise'
|
|
102
|
+
PromiseTypeAnnotation: 'Promise',
|
|
103
|
+
ArrayBufferTypeAnnotation: 'ArrayBuffer'
|
|
102
104
|
};
|
|
103
105
|
if (type in TypeMap) {
|
|
104
106
|
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, flowElementType, flowArrayType, TypeMap[type]);
|
|
@@ -218,6 +218,7 @@ const UnsupportedObjectPropertyTypeToInvalidPropertyValueTypeMap = {
|
|
|
218
218
|
FunctionTypeAnnotation: 'FunctionTypeAnnotation',
|
|
219
219
|
VoidTypeAnnotation: 'void',
|
|
220
220
|
PromiseTypeAnnotation: 'Promise',
|
|
221
|
+
ArrayBufferTypeAnnotation: 'ArrayBuffer',
|
|
221
222
|
};
|
|
222
223
|
|
|
223
224
|
function throwIfPropertyValueTypeIsUnsupported(
|
|
@@ -277,6 +278,7 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(
|
|
|
277
278
|
FunctionTypeAnnotation: 'FunctionTypeAnnotation',
|
|
278
279
|
VoidTypeAnnotation: 'void',
|
|
279
280
|
PromiseTypeAnnotation: 'Promise',
|
|
281
|
+
ArrayBufferTypeAnnotation: 'ArrayBuffer',
|
|
280
282
|
// TODO: Added as a work-around for now until TupleTypeAnnotation are fully supported in both flow and TS
|
|
281
283
|
// Right now they are partially treated as UnionTypeAnnotation
|
|
282
284
|
// UnionTypeAnnotation: 'UnionTypeAnnotation',
|
|
@@ -128,7 +128,7 @@ class UnsupportedModulePropertyParserError extends ParserError {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
class UnsupportedTypeAnnotationParserError extends ParserError {
|
|
131
|
-
|
|
131
|
+
readonly typeAnnotationType: string;
|
|
132
132
|
constructor(
|
|
133
133
|
nativeModuleName: string,
|
|
134
134
|
typeAnnotation: $FlowFixMe,
|
|
@@ -17,7 +17,7 @@ const {verifyPropNotAlreadyDefined} = require('../../parsers-commons');
|
|
|
17
17
|
const {getValueFromTypes} = require('../utils.js');
|
|
18
18
|
|
|
19
19
|
// $FlowFixMe[unsupported-variance-annotation]
|
|
20
|
-
function getTypeAnnotationForArray
|
|
20
|
+
function getTypeAnnotationForArray<out T>(
|
|
21
21
|
name: string,
|
|
22
22
|
typeAnnotation: $FlowFixMe,
|
|
23
23
|
defaultValue: $FlowFixMe | null,
|
|
@@ -219,7 +219,7 @@ function flattenProperties(
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
// $FlowFixMe[unsupported-variance-annotation]
|
|
222
|
-
function getTypeAnnotation
|
|
222
|
+
function getTypeAnnotation<out T>(
|
|
223
223
|
name: string,
|
|
224
224
|
annotation: $FlowFixMe | ASTNode,
|
|
225
225
|
defaultValue: $FlowFixMe | null,
|
|
@@ -129,7 +129,7 @@ function parseObjectProperty(parentObject, property, hasteModuleName, types, ali
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
const [propertyTypeAnnotation, isPropertyNullable] = unwrapNullable(translateTypeAnnotation(hasteModuleName, languageTypeAnnotation, types, aliasMap, enumMap, tryParse, cxxOnly, parser));
|
|
132
|
-
if (propertyTypeAnnotation.type === 'FunctionTypeAnnotation' && !cxxOnly || propertyTypeAnnotation.type === 'PromiseTypeAnnotation' || propertyTypeAnnotation.type === 'VoidTypeAnnotation') {
|
|
132
|
+
if (propertyTypeAnnotation.type === 'FunctionTypeAnnotation' && !cxxOnly || propertyTypeAnnotation.type === 'PromiseTypeAnnotation' || propertyTypeAnnotation.type === 'VoidTypeAnnotation' || propertyTypeAnnotation.type === 'ArrayBufferTypeAnnotation') {
|
|
133
133
|
throwIfPropertyValueTypeIsUnsupported(hasteModuleName, languageTypeAnnotation, property.key, propertyTypeAnnotation.type);
|
|
134
134
|
}
|
|
135
135
|
return {
|
|
@@ -107,7 +107,7 @@ function wrapModuleSchema(
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// $FlowFixMe[unsupported-variance-annotation]
|
|
110
|
-
function unwrapNullable
|
|
110
|
+
function unwrapNullable<out T extends NativeModuleTypeAnnotation>(
|
|
111
111
|
x: Nullable<T>,
|
|
112
112
|
): [T, boolean] {
|
|
113
113
|
if (x.type === 'NullableTypeAnnotation') {
|
|
@@ -118,7 +118,7 @@ function unwrapNullable<+T extends NativeModuleTypeAnnotation>(
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// $FlowFixMe[unsupported-variance-annotation]
|
|
121
|
-
function wrapNullable
|
|
121
|
+
function wrapNullable<out T extends NativeModuleTypeAnnotation>(
|
|
122
122
|
nullable: boolean,
|
|
123
123
|
typeAnnotation: T,
|
|
124
124
|
): Nullable<T> {
|
|
@@ -307,7 +307,8 @@ function parseObjectProperty(
|
|
|
307
307
|
if (
|
|
308
308
|
(propertyTypeAnnotation.type === 'FunctionTypeAnnotation' && !cxxOnly) ||
|
|
309
309
|
propertyTypeAnnotation.type === 'PromiseTypeAnnotation' ||
|
|
310
|
-
propertyTypeAnnotation.type === 'VoidTypeAnnotation'
|
|
310
|
+
propertyTypeAnnotation.type === 'VoidTypeAnnotation' ||
|
|
311
|
+
propertyTypeAnnotation.type === 'ArrayBufferTypeAnnotation'
|
|
311
312
|
) {
|
|
312
313
|
throwIfPropertyValueTypeIsUnsupported(
|
|
313
314
|
hasteModuleName,
|
|
@@ -70,6 +70,11 @@ function emitVoid(nullable) {
|
|
|
70
70
|
type: 'VoidTypeAnnotation'
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
+
function emitArrayBuffer(nullable) {
|
|
74
|
+
return wrapNullable(nullable, {
|
|
75
|
+
type: 'ArrayBufferTypeAnnotation'
|
|
76
|
+
});
|
|
77
|
+
}
|
|
73
78
|
function emitStringish(nullable) {
|
|
74
79
|
return wrapNullable(nullable, {
|
|
75
80
|
type: 'StringTypeAnnotation'
|
|
@@ -165,11 +170,9 @@ function emitPromise(hasteModuleName, typeAnnotation, parser, nullable, types, a
|
|
|
165
170
|
}
|
|
166
171
|
});
|
|
167
172
|
} else {
|
|
173
|
+
let elementTypeResult;
|
|
168
174
|
try {
|
|
169
|
-
|
|
170
|
-
type: 'PromiseTypeAnnotation',
|
|
171
|
-
elementType: translateTypeAnnotation(hasteModuleName, typeAnnotation.typeParameters.params[0], types, aliasMap, enumMap, tryParse, cxxOnly, parser)
|
|
172
|
-
});
|
|
175
|
+
elementTypeResult = translateTypeAnnotation(hasteModuleName, typeAnnotation.typeParameters.params[0], types, aliasMap, enumMap, tryParse, cxxOnly, parser);
|
|
173
176
|
} catch {
|
|
174
177
|
return wrapNullable(nullable, {
|
|
175
178
|
type: 'PromiseTypeAnnotation',
|
|
@@ -178,6 +181,10 @@ function emitPromise(hasteModuleName, typeAnnotation, parser, nullable, types, a
|
|
|
178
181
|
}
|
|
179
182
|
});
|
|
180
183
|
}
|
|
184
|
+
return wrapNullable(nullable, {
|
|
185
|
+
type: 'PromiseTypeAnnotation',
|
|
186
|
+
elementType: elementTypeResult
|
|
187
|
+
});
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
190
|
function emitGenericObject(nullable) {
|
|
@@ -302,7 +309,8 @@ function emitCommonTypes(hasteModuleName, types, typeAnnotation, aliasMap, enumM
|
|
|
302
309
|
MixedTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject,
|
|
303
310
|
UnsafeMixed: cxxOnly ? emitMixed : emitGenericObject,
|
|
304
311
|
unknown: cxxOnly ? emitMixed : emitGenericObject,
|
|
305
|
-
UnknownTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject
|
|
312
|
+
UnknownTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject,
|
|
313
|
+
ArrayBuffer: emitArrayBuffer
|
|
306
314
|
};
|
|
307
315
|
const typeAnnotationName = parser.convertKeywordToTypeAnnotation(typeAnnotation.type);
|
|
308
316
|
const simpleEmitter = typeMap[typeAnnotationName];
|
|
@@ -355,6 +363,7 @@ function emitUnionProp(name, optional, parser, typeAnnotation) {
|
|
|
355
363
|
};
|
|
356
364
|
}
|
|
357
365
|
module.exports = {
|
|
366
|
+
emitArrayBuffer,
|
|
358
367
|
emitArrayType,
|
|
359
368
|
emitBoolean,
|
|
360
369
|
emitBooleanLiteral,
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
import type {
|
|
14
|
+
ArrayBufferTypeAnnotation,
|
|
14
15
|
BooleanLiteralTypeAnnotation,
|
|
15
16
|
BooleanTypeAnnotation,
|
|
16
17
|
DoubleTypeAnnotation,
|
|
@@ -127,6 +128,14 @@ function emitVoid(nullable: boolean): Nullable<VoidTypeAnnotation> {
|
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
function emitArrayBuffer(
|
|
132
|
+
nullable: boolean,
|
|
133
|
+
): Nullable<ArrayBufferTypeAnnotation> {
|
|
134
|
+
return wrapNullable(nullable, {
|
|
135
|
+
type: 'ArrayBufferTypeAnnotation',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
130
139
|
function emitStringish(nullable: boolean): Nullable<StringTypeAnnotation> {
|
|
131
140
|
return wrapNullable(nullable, {
|
|
132
141
|
type: 'StringTypeAnnotation',
|
|
@@ -351,20 +360,18 @@ function emitPromise(
|
|
|
351
360
|
},
|
|
352
361
|
});
|
|
353
362
|
} else {
|
|
363
|
+
let elementTypeResult;
|
|
354
364
|
try {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
parser,
|
|
366
|
-
),
|
|
367
|
-
});
|
|
365
|
+
elementTypeResult = translateTypeAnnotation(
|
|
366
|
+
hasteModuleName,
|
|
367
|
+
typeAnnotation.typeParameters.params[0],
|
|
368
|
+
types,
|
|
369
|
+
aliasMap,
|
|
370
|
+
enumMap,
|
|
371
|
+
tryParse,
|
|
372
|
+
cxxOnly,
|
|
373
|
+
parser,
|
|
374
|
+
);
|
|
368
375
|
} catch {
|
|
369
376
|
return wrapNullable(nullable, {
|
|
370
377
|
type: 'PromiseTypeAnnotation',
|
|
@@ -373,6 +380,11 @@ function emitPromise(
|
|
|
373
380
|
},
|
|
374
381
|
});
|
|
375
382
|
}
|
|
383
|
+
|
|
384
|
+
return wrapNullable(nullable, {
|
|
385
|
+
type: 'PromiseTypeAnnotation',
|
|
386
|
+
elementType: elementTypeResult,
|
|
387
|
+
});
|
|
376
388
|
}
|
|
377
389
|
}
|
|
378
390
|
|
|
@@ -666,6 +678,7 @@ function emitCommonTypes(
|
|
|
666
678
|
UnsafeMixed: cxxOnly ? emitMixed : emitGenericObject,
|
|
667
679
|
unknown: cxxOnly ? emitMixed : emitGenericObject,
|
|
668
680
|
UnknownTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject,
|
|
681
|
+
ArrayBuffer: emitArrayBuffer,
|
|
669
682
|
};
|
|
670
683
|
|
|
671
684
|
const typeAnnotationName = parser.convertKeywordToTypeAnnotation(
|
|
@@ -764,6 +777,7 @@ function emitUnionProp(
|
|
|
764
777
|
}
|
|
765
778
|
|
|
766
779
|
module.exports = {
|
|
780
|
+
emitArrayBuffer,
|
|
767
781
|
emitArrayType,
|
|
768
782
|
emitBoolean,
|
|
769
783
|
emitBooleanLiteral,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/codegen",
|
|
3
|
-
"version": "0.87.0-nightly-
|
|
3
|
+
"version": "0.87.0-nightly-20260528-eaf770433",
|
|
4
4
|
"description": "Code generation tools for React Native",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"bugs": "https://github.com/facebook/react-native/issues",
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": "^
|
|
21
|
+
"node": "^22.13.0 || ^24.3.0 || >= 26.0.0"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "yarn clean && node scripts/build.js --verbose",
|