@react-native/codegen 0.86.0-nightly-20260315-af0ccccda → 0.86.0-nightly-20260319-941ace990
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/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +1 -1
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +5 -69
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +13 -86
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +6 -66
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +13 -83
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStructUtils.js +77 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStructUtils.js.flow +117 -0
- package/package.json +4 -4
|
@@ -4,18 +4,11 @@ const {
|
|
|
4
4
|
unwrapNullable
|
|
5
5
|
} = require('../../../../parsers/parsers-commons');
|
|
6
6
|
const {
|
|
7
|
-
wrapOptional: wrapCxxOptional
|
|
8
|
-
} = require('../../../TypeUtils/Cxx');
|
|
9
|
-
const {
|
|
10
|
-
wrapOptional: wrapObjCOptional
|
|
11
|
-
} = require('../../../TypeUtils/Objective-C');
|
|
12
|
-
const {
|
|
13
|
-
capitalize
|
|
14
|
-
} = require('../../../Utils');
|
|
15
|
-
const {
|
|
16
|
-
getNamespacedStructName,
|
|
17
7
|
getSafePropertyName
|
|
18
8
|
} = require('../Utils');
|
|
9
|
+
const {
|
|
10
|
+
toObjCType
|
|
11
|
+
} = require('./serializeStructUtils');
|
|
19
12
|
const StructTemplate = ({
|
|
20
13
|
hasteModuleName,
|
|
21
14
|
structName,
|
|
@@ -62,63 +55,6 @@ ${properties}
|
|
|
62
55
|
inline JS::${hasteModuleName}::${structName}::Builder::Builder(${structName} i) : _factory(^{
|
|
63
56
|
return i.unsafeRawValue();
|
|
64
57
|
}) {}`;
|
|
65
|
-
function toObjCType(hasteModuleName, nullableTypeAnnotation, isOptional = false) {
|
|
66
|
-
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
67
|
-
const isRequired = !nullable && !isOptional;
|
|
68
|
-
switch (typeAnnotation.type) {
|
|
69
|
-
case 'ReservedTypeAnnotation':
|
|
70
|
-
switch (typeAnnotation.name) {
|
|
71
|
-
case 'RootTag':
|
|
72
|
-
return wrapCxxOptional('double', isRequired);
|
|
73
|
-
default:
|
|
74
|
-
typeAnnotation.name;
|
|
75
|
-
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
|
76
|
-
}
|
|
77
|
-
case 'StringTypeAnnotation':
|
|
78
|
-
return 'NSString *';
|
|
79
|
-
case 'StringLiteralTypeAnnotation':
|
|
80
|
-
return 'NSString *';
|
|
81
|
-
case 'UnionTypeAnnotation':
|
|
82
|
-
return 'NSObject *';
|
|
83
|
-
case 'NumberTypeAnnotation':
|
|
84
|
-
return wrapCxxOptional('double', isRequired);
|
|
85
|
-
case 'NumberLiteralTypeAnnotation':
|
|
86
|
-
return wrapCxxOptional('double', isRequired);
|
|
87
|
-
case 'FloatTypeAnnotation':
|
|
88
|
-
return wrapCxxOptional('double', isRequired);
|
|
89
|
-
case 'Int32TypeAnnotation':
|
|
90
|
-
return wrapCxxOptional('double', isRequired);
|
|
91
|
-
case 'DoubleTypeAnnotation':
|
|
92
|
-
return wrapCxxOptional('double', isRequired);
|
|
93
|
-
case 'BooleanTypeAnnotation':
|
|
94
|
-
return wrapCxxOptional('bool', isRequired);
|
|
95
|
-
case 'BooleanLiteralTypeAnnotation':
|
|
96
|
-
return wrapCxxOptional('bool', isRequired);
|
|
97
|
-
case 'EnumDeclaration':
|
|
98
|
-
switch (typeAnnotation.memberType) {
|
|
99
|
-
case 'NumberTypeAnnotation':
|
|
100
|
-
return wrapCxxOptional('double', isRequired);
|
|
101
|
-
case 'StringTypeAnnotation':
|
|
102
|
-
return 'NSString *';
|
|
103
|
-
default:
|
|
104
|
-
throw new Error(`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`);
|
|
105
|
-
}
|
|
106
|
-
case 'GenericObjectTypeAnnotation':
|
|
107
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
108
|
-
case 'ArrayTypeAnnotation':
|
|
109
|
-
if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') {
|
|
110
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
111
|
-
}
|
|
112
|
-
return wrapCxxOptional(`std::vector<${toObjCType(hasteModuleName, typeAnnotation.elementType)}>`, isRequired);
|
|
113
|
-
case 'TypeAliasTypeAnnotation':
|
|
114
|
-
const structName = capitalize(typeAnnotation.name);
|
|
115
|
-
const namespacedStructName = getNamespacedStructName(hasteModuleName, structName);
|
|
116
|
-
return wrapCxxOptional(`${namespacedStructName}::Builder`, isRequired);
|
|
117
|
-
default:
|
|
118
|
-
typeAnnotation.type;
|
|
119
|
-
throw new Error(`Couldn't convert into ObjC type: ${typeAnnotation.type}"`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
58
|
function toObjCValue(hasteModuleName, nullableTypeAnnotation, value, depth, isOptional = false) {
|
|
123
59
|
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
124
60
|
const isRequired = !nullable && !isOptional;
|
|
@@ -173,7 +109,7 @@ function toObjCValue(hasteModuleName, nullableTypeAnnotation, value, depth, isOp
|
|
|
173
109
|
return value;
|
|
174
110
|
}
|
|
175
111
|
const localVarName = `el${'_'.repeat(depth + 1)}`;
|
|
176
|
-
const elementObjCType = toObjCType(hasteModuleName, elementType);
|
|
112
|
+
const elementObjCType = toObjCType(hasteModuleName, elementType, 'CONSTANTS');
|
|
177
113
|
const elementObjCValue = toObjCValue(hasteModuleName, elementType, localVarName, depth + 1);
|
|
178
114
|
const RCTConvertVecToArray = transformer => {
|
|
179
115
|
return `RCTConvert${!isRequired ? 'Optional' : ''}VecToArray(${value}, ${transformer})`;
|
|
@@ -196,7 +132,7 @@ function serializeConstantsStruct(hasteModuleName, struct) {
|
|
|
196
132
|
optional
|
|
197
133
|
} = property;
|
|
198
134
|
const safePropName = getSafePropertyName(property);
|
|
199
|
-
const objCType = toObjCType(hasteModuleName, typeAnnotation, optional);
|
|
135
|
+
const objCType = toObjCType(hasteModuleName, typeAnnotation, 'CONSTANTS', optional);
|
|
200
136
|
if (!optional) {
|
|
201
137
|
return `RCTRequired<${objCType}> ${safePropName};`;
|
|
202
138
|
}
|
|
@@ -15,12 +15,8 @@ import type {ConstantsStruct, StructTypeAnnotation} from '../StructCollector';
|
|
|
15
15
|
import type {StructSerilizationOutput} from './serializeStruct';
|
|
16
16
|
|
|
17
17
|
const {unwrapNullable} = require('../../../../parsers/parsers-commons');
|
|
18
|
-
const {
|
|
19
|
-
const {
|
|
20
|
-
wrapOptional: wrapObjCOptional,
|
|
21
|
-
} = require('../../../TypeUtils/Objective-C');
|
|
22
|
-
const {capitalize} = require('../../../Utils');
|
|
23
|
-
const {getNamespacedStructName, getSafePropertyName} = require('../Utils');
|
|
18
|
+
const {getSafePropertyName} = require('../Utils');
|
|
19
|
+
const {toObjCType} = require('./serializeStructUtils');
|
|
24
20
|
|
|
25
21
|
const StructTemplate = ({
|
|
26
22
|
hasteModuleName,
|
|
@@ -78,84 +74,6 @@ inline JS::${hasteModuleName}::${structName}::Builder::Builder(${structName} i)
|
|
|
78
74
|
return i.unsafeRawValue();
|
|
79
75
|
}) {}`;
|
|
80
76
|
|
|
81
|
-
function toObjCType(
|
|
82
|
-
hasteModuleName: string,
|
|
83
|
-
nullableTypeAnnotation: Nullable<StructTypeAnnotation>,
|
|
84
|
-
isOptional: boolean = false,
|
|
85
|
-
): string {
|
|
86
|
-
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
87
|
-
const isRequired = !nullable && !isOptional;
|
|
88
|
-
|
|
89
|
-
switch (typeAnnotation.type) {
|
|
90
|
-
case 'ReservedTypeAnnotation':
|
|
91
|
-
switch (typeAnnotation.name) {
|
|
92
|
-
case 'RootTag':
|
|
93
|
-
return wrapCxxOptional('double', isRequired);
|
|
94
|
-
default:
|
|
95
|
-
(typeAnnotation.name: empty);
|
|
96
|
-
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
|
97
|
-
}
|
|
98
|
-
case 'StringTypeAnnotation':
|
|
99
|
-
return 'NSString *';
|
|
100
|
-
case 'StringLiteralTypeAnnotation':
|
|
101
|
-
return 'NSString *';
|
|
102
|
-
case 'UnionTypeAnnotation':
|
|
103
|
-
// TODO(T247151345): Implement proper heterogeneous union support. This is unsafe.
|
|
104
|
-
return 'NSObject *';
|
|
105
|
-
case 'NumberTypeAnnotation':
|
|
106
|
-
return wrapCxxOptional('double', isRequired);
|
|
107
|
-
case 'NumberLiteralTypeAnnotation':
|
|
108
|
-
return wrapCxxOptional('double', isRequired);
|
|
109
|
-
case 'FloatTypeAnnotation':
|
|
110
|
-
return wrapCxxOptional('double', isRequired);
|
|
111
|
-
case 'Int32TypeAnnotation':
|
|
112
|
-
return wrapCxxOptional('double', isRequired);
|
|
113
|
-
case 'DoubleTypeAnnotation':
|
|
114
|
-
return wrapCxxOptional('double', isRequired);
|
|
115
|
-
case 'BooleanTypeAnnotation':
|
|
116
|
-
return wrapCxxOptional('bool', isRequired);
|
|
117
|
-
case 'BooleanLiteralTypeAnnotation':
|
|
118
|
-
return wrapCxxOptional('bool', isRequired);
|
|
119
|
-
case 'EnumDeclaration':
|
|
120
|
-
switch (typeAnnotation.memberType) {
|
|
121
|
-
case 'NumberTypeAnnotation':
|
|
122
|
-
return wrapCxxOptional('double', isRequired);
|
|
123
|
-
case 'StringTypeAnnotation':
|
|
124
|
-
return 'NSString *';
|
|
125
|
-
default:
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
case 'GenericObjectTypeAnnotation':
|
|
131
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
132
|
-
case 'ArrayTypeAnnotation':
|
|
133
|
-
if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') {
|
|
134
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return wrapCxxOptional(
|
|
138
|
-
`std::vector<${toObjCType(
|
|
139
|
-
hasteModuleName,
|
|
140
|
-
typeAnnotation.elementType,
|
|
141
|
-
)}>`,
|
|
142
|
-
isRequired,
|
|
143
|
-
);
|
|
144
|
-
case 'TypeAliasTypeAnnotation':
|
|
145
|
-
const structName = capitalize(typeAnnotation.name);
|
|
146
|
-
const namespacedStructName = getNamespacedStructName(
|
|
147
|
-
hasteModuleName,
|
|
148
|
-
structName,
|
|
149
|
-
);
|
|
150
|
-
return wrapCxxOptional(`${namespacedStructName}::Builder`, isRequired);
|
|
151
|
-
default:
|
|
152
|
-
(typeAnnotation.type: empty);
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Couldn't convert into ObjC type: ${typeAnnotation.type}"`,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
77
|
function toObjCValue(
|
|
160
78
|
hasteModuleName: string,
|
|
161
79
|
nullableTypeAnnotation: Nullable<StructTypeAnnotation>,
|
|
@@ -223,7 +141,11 @@ function toObjCValue(
|
|
|
223
141
|
}
|
|
224
142
|
|
|
225
143
|
const localVarName = `el${'_'.repeat(depth + 1)}`;
|
|
226
|
-
const elementObjCType = toObjCType(
|
|
144
|
+
const elementObjCType = toObjCType(
|
|
145
|
+
hasteModuleName,
|
|
146
|
+
elementType,
|
|
147
|
+
'CONSTANTS',
|
|
148
|
+
);
|
|
227
149
|
const elementObjCValue = toObjCValue(
|
|
228
150
|
hasteModuleName,
|
|
229
151
|
elementType,
|
|
@@ -263,7 +185,12 @@ function serializeConstantsStruct(
|
|
|
263
185
|
.map(property => {
|
|
264
186
|
const {typeAnnotation, optional} = property;
|
|
265
187
|
const safePropName = getSafePropertyName(property);
|
|
266
|
-
const objCType = toObjCType(
|
|
188
|
+
const objCType = toObjCType(
|
|
189
|
+
hasteModuleName,
|
|
190
|
+
typeAnnotation,
|
|
191
|
+
'CONSTANTS',
|
|
192
|
+
optional,
|
|
193
|
+
);
|
|
267
194
|
|
|
268
195
|
if (!optional) {
|
|
269
196
|
return `RCTRequired<${objCType}> ${safePropName};`;
|
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
const {
|
|
4
4
|
unwrapNullable
|
|
5
5
|
} = require('../../../../parsers/parsers-commons');
|
|
6
|
-
const {
|
|
7
|
-
wrapOptional: wrapCxxOptional
|
|
8
|
-
} = require('../../../TypeUtils/Cxx');
|
|
9
|
-
const {
|
|
10
|
-
wrapOptional: wrapObjCOptional
|
|
11
|
-
} = require('../../../TypeUtils/Objective-C');
|
|
12
6
|
const {
|
|
13
7
|
capitalize
|
|
14
8
|
} = require('../../../Utils');
|
|
@@ -16,6 +10,9 @@ const {
|
|
|
16
10
|
getNamespacedStructName,
|
|
17
11
|
getSafePropertyName
|
|
18
12
|
} = require('../Utils');
|
|
13
|
+
const {
|
|
14
|
+
toObjCType
|
|
15
|
+
} = require('./serializeStructUtils');
|
|
19
16
|
const StructTemplate = ({
|
|
20
17
|
hasteModuleName,
|
|
21
18
|
structName,
|
|
@@ -47,63 +44,6 @@ const MethodTemplate = ({
|
|
|
47
44
|
id const p = _v[@"${propertyName}"];
|
|
48
45
|
return ${returnValue};
|
|
49
46
|
}`;
|
|
50
|
-
function toObjCType(hasteModuleName, nullableTypeAnnotation, isOptional = false) {
|
|
51
|
-
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
52
|
-
const isRequired = !nullable && !isOptional;
|
|
53
|
-
switch (typeAnnotation.type) {
|
|
54
|
-
case 'ReservedTypeAnnotation':
|
|
55
|
-
switch (typeAnnotation.name) {
|
|
56
|
-
case 'RootTag':
|
|
57
|
-
return wrapCxxOptional('double', isRequired);
|
|
58
|
-
default:
|
|
59
|
-
typeAnnotation.name;
|
|
60
|
-
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
|
61
|
-
}
|
|
62
|
-
case 'StringTypeAnnotation':
|
|
63
|
-
return 'NSString *';
|
|
64
|
-
case 'StringLiteralTypeAnnotation':
|
|
65
|
-
return 'NSString *';
|
|
66
|
-
case 'UnionTypeAnnotation':
|
|
67
|
-
return 'NSObject *';
|
|
68
|
-
case 'NumberTypeAnnotation':
|
|
69
|
-
return wrapCxxOptional('double', isRequired);
|
|
70
|
-
case 'NumberLiteralTypeAnnotation':
|
|
71
|
-
return wrapCxxOptional('double', isRequired);
|
|
72
|
-
case 'FloatTypeAnnotation':
|
|
73
|
-
return wrapCxxOptional('double', isRequired);
|
|
74
|
-
case 'Int32TypeAnnotation':
|
|
75
|
-
return wrapCxxOptional('double', isRequired);
|
|
76
|
-
case 'DoubleTypeAnnotation':
|
|
77
|
-
return wrapCxxOptional('double', isRequired);
|
|
78
|
-
case 'BooleanTypeAnnotation':
|
|
79
|
-
return wrapCxxOptional('bool', isRequired);
|
|
80
|
-
case 'BooleanLiteralTypeAnnotation':
|
|
81
|
-
return wrapCxxOptional('bool', isRequired);
|
|
82
|
-
case 'EnumDeclaration':
|
|
83
|
-
switch (typeAnnotation.memberType) {
|
|
84
|
-
case 'NumberTypeAnnotation':
|
|
85
|
-
return wrapCxxOptional('double', isRequired);
|
|
86
|
-
case 'StringTypeAnnotation':
|
|
87
|
-
return 'NSString *';
|
|
88
|
-
default:
|
|
89
|
-
throw new Error(`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`);
|
|
90
|
-
}
|
|
91
|
-
case 'GenericObjectTypeAnnotation':
|
|
92
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
93
|
-
case 'ArrayTypeAnnotation':
|
|
94
|
-
if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') {
|
|
95
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
96
|
-
}
|
|
97
|
-
return wrapCxxOptional(`facebook::react::LazyVector<${toObjCType(hasteModuleName, typeAnnotation.elementType)}>`, isRequired);
|
|
98
|
-
case 'TypeAliasTypeAnnotation':
|
|
99
|
-
const structName = capitalize(typeAnnotation.name);
|
|
100
|
-
const namespacedStructName = getNamespacedStructName(hasteModuleName, structName);
|
|
101
|
-
return wrapCxxOptional(namespacedStructName, isRequired);
|
|
102
|
-
default:
|
|
103
|
-
typeAnnotation.type;
|
|
104
|
-
throw new Error(`Couldn't convert into ObjC type: ${typeAnnotation.type}"`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
47
|
function toObjCValue(hasteModuleName, nullableTypeAnnotation, value, depth, isOptional = false) {
|
|
108
48
|
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
109
49
|
const isRequired = !nullable && !isOptional;
|
|
@@ -159,7 +99,7 @@ function toObjCValue(hasteModuleName, nullableTypeAnnotation, value, depth, isOp
|
|
|
159
99
|
return value;
|
|
160
100
|
}
|
|
161
101
|
const localVarName = `itemValue_${depth}`;
|
|
162
|
-
const elementObjCType = toObjCType(hasteModuleName, elementType);
|
|
102
|
+
const elementObjCType = toObjCType(hasteModuleName, elementType, 'REGULAR');
|
|
163
103
|
const elementObjCValue = toObjCValue(hasteModuleName, elementType, localVarName, depth + 1);
|
|
164
104
|
return RCTBridgingTo('Vec', `^${elementObjCType}(id ${localVarName}) { return ${elementObjCValue}; }`);
|
|
165
105
|
case 'TypeAliasTypeAnnotation':
|
|
@@ -181,7 +121,7 @@ function serializeRegularStruct(hasteModuleName, struct) {
|
|
|
181
121
|
optional
|
|
182
122
|
} = property;
|
|
183
123
|
const safePropName = getSafePropertyName(property);
|
|
184
|
-
const returnType = toObjCType(hasteModuleName, typeAnnotation, optional);
|
|
124
|
+
const returnType = toObjCType(hasteModuleName, typeAnnotation, 'REGULAR', optional);
|
|
185
125
|
const padding = ' '.repeat(returnType.endsWith('*') ? 0 : 1);
|
|
186
126
|
return `${returnType}${padding}${safePropName}() const;`;
|
|
187
127
|
}).join('\n ')
|
|
@@ -193,7 +133,7 @@ function serializeRegularStruct(hasteModuleName, struct) {
|
|
|
193
133
|
name: propName
|
|
194
134
|
} = property;
|
|
195
135
|
const safePropertyName = getSafePropertyName(property);
|
|
196
|
-
const returnType = toObjCType(hasteModuleName, typeAnnotation, optional);
|
|
136
|
+
const returnType = toObjCType(hasteModuleName, typeAnnotation, 'REGULAR', optional);
|
|
197
137
|
const returnValue = toObjCValue(hasteModuleName, typeAnnotation, 'p', 0, optional);
|
|
198
138
|
const padding = ' '.repeat(returnType.endsWith('*') ? 0 : 1);
|
|
199
139
|
return MethodTemplate({
|
|
@@ -15,12 +15,9 @@ import type {RegularStruct, StructTypeAnnotation} from '../StructCollector';
|
|
|
15
15
|
import type {StructSerilizationOutput} from './serializeStruct';
|
|
16
16
|
|
|
17
17
|
const {unwrapNullable} = require('../../../../parsers/parsers-commons');
|
|
18
|
-
const {wrapOptional: wrapCxxOptional} = require('../../../TypeUtils/Cxx');
|
|
19
|
-
const {
|
|
20
|
-
wrapOptional: wrapObjCOptional,
|
|
21
|
-
} = require('../../../TypeUtils/Objective-C');
|
|
22
18
|
const {capitalize} = require('../../../Utils');
|
|
23
19
|
const {getNamespacedStructName, getSafePropertyName} = require('../Utils');
|
|
20
|
+
const {toObjCType} = require('./serializeStructUtils');
|
|
24
21
|
|
|
25
22
|
const StructTemplate = ({
|
|
26
23
|
hasteModuleName,
|
|
@@ -66,83 +63,6 @@ const MethodTemplate = ({
|
|
|
66
63
|
return ${returnValue};
|
|
67
64
|
}`;
|
|
68
65
|
|
|
69
|
-
function toObjCType(
|
|
70
|
-
hasteModuleName: string,
|
|
71
|
-
nullableTypeAnnotation: Nullable<StructTypeAnnotation>,
|
|
72
|
-
isOptional: boolean = false,
|
|
73
|
-
): string {
|
|
74
|
-
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
75
|
-
const isRequired = !nullable && !isOptional;
|
|
76
|
-
|
|
77
|
-
switch (typeAnnotation.type) {
|
|
78
|
-
case 'ReservedTypeAnnotation':
|
|
79
|
-
switch (typeAnnotation.name) {
|
|
80
|
-
case 'RootTag':
|
|
81
|
-
return wrapCxxOptional('double', isRequired);
|
|
82
|
-
default:
|
|
83
|
-
(typeAnnotation.name: empty);
|
|
84
|
-
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
|
85
|
-
}
|
|
86
|
-
case 'StringTypeAnnotation':
|
|
87
|
-
return 'NSString *';
|
|
88
|
-
case 'StringLiteralTypeAnnotation':
|
|
89
|
-
return 'NSString *';
|
|
90
|
-
case 'UnionTypeAnnotation':
|
|
91
|
-
// TODO(T247151345): Implement proper heterogeneous union support. This is unsafe.
|
|
92
|
-
return 'NSObject *';
|
|
93
|
-
case 'NumberTypeAnnotation':
|
|
94
|
-
return wrapCxxOptional('double', isRequired);
|
|
95
|
-
case 'NumberLiteralTypeAnnotation':
|
|
96
|
-
return wrapCxxOptional('double', isRequired);
|
|
97
|
-
case 'FloatTypeAnnotation':
|
|
98
|
-
return wrapCxxOptional('double', isRequired);
|
|
99
|
-
case 'Int32TypeAnnotation':
|
|
100
|
-
return wrapCxxOptional('double', isRequired);
|
|
101
|
-
case 'DoubleTypeAnnotation':
|
|
102
|
-
return wrapCxxOptional('double', isRequired);
|
|
103
|
-
case 'BooleanTypeAnnotation':
|
|
104
|
-
return wrapCxxOptional('bool', isRequired);
|
|
105
|
-
case 'BooleanLiteralTypeAnnotation':
|
|
106
|
-
return wrapCxxOptional('bool', isRequired);
|
|
107
|
-
case 'EnumDeclaration':
|
|
108
|
-
switch (typeAnnotation.memberType) {
|
|
109
|
-
case 'NumberTypeAnnotation':
|
|
110
|
-
return wrapCxxOptional('double', isRequired);
|
|
111
|
-
case 'StringTypeAnnotation':
|
|
112
|
-
return 'NSString *';
|
|
113
|
-
default:
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
case 'GenericObjectTypeAnnotation':
|
|
119
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
120
|
-
case 'ArrayTypeAnnotation':
|
|
121
|
-
if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') {
|
|
122
|
-
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
123
|
-
}
|
|
124
|
-
return wrapCxxOptional(
|
|
125
|
-
`facebook::react::LazyVector<${toObjCType(
|
|
126
|
-
hasteModuleName,
|
|
127
|
-
typeAnnotation.elementType,
|
|
128
|
-
)}>`,
|
|
129
|
-
isRequired,
|
|
130
|
-
);
|
|
131
|
-
case 'TypeAliasTypeAnnotation':
|
|
132
|
-
const structName = capitalize(typeAnnotation.name);
|
|
133
|
-
const namespacedStructName = getNamespacedStructName(
|
|
134
|
-
hasteModuleName,
|
|
135
|
-
structName,
|
|
136
|
-
);
|
|
137
|
-
return wrapCxxOptional(namespacedStructName, isRequired);
|
|
138
|
-
default:
|
|
139
|
-
(typeAnnotation.type: empty);
|
|
140
|
-
throw new Error(
|
|
141
|
-
`Couldn't convert into ObjC type: ${typeAnnotation.type}"`,
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
66
|
function toObjCValue(
|
|
147
67
|
hasteModuleName: string,
|
|
148
68
|
nullableTypeAnnotation: Nullable<StructTypeAnnotation>,
|
|
@@ -212,7 +132,11 @@ function toObjCValue(
|
|
|
212
132
|
}
|
|
213
133
|
|
|
214
134
|
const localVarName = `itemValue_${depth}`;
|
|
215
|
-
const elementObjCType = toObjCType(
|
|
135
|
+
const elementObjCType = toObjCType(
|
|
136
|
+
hasteModuleName,
|
|
137
|
+
elementType,
|
|
138
|
+
'REGULAR',
|
|
139
|
+
);
|
|
216
140
|
const elementObjCValue = toObjCValue(
|
|
217
141
|
hasteModuleName,
|
|
218
142
|
elementType,
|
|
@@ -256,6 +180,7 @@ function serializeRegularStruct(
|
|
|
256
180
|
const returnType = toObjCType(
|
|
257
181
|
hasteModuleName,
|
|
258
182
|
typeAnnotation,
|
|
183
|
+
'REGULAR',
|
|
259
184
|
optional,
|
|
260
185
|
);
|
|
261
186
|
|
|
@@ -270,7 +195,12 @@ function serializeRegularStruct(
|
|
|
270
195
|
.map<string>(property => {
|
|
271
196
|
const {typeAnnotation, optional, name: propName} = property;
|
|
272
197
|
const safePropertyName = getSafePropertyName(property);
|
|
273
|
-
const returnType = toObjCType(
|
|
198
|
+
const returnType = toObjCType(
|
|
199
|
+
hasteModuleName,
|
|
200
|
+
typeAnnotation,
|
|
201
|
+
'REGULAR',
|
|
202
|
+
optional,
|
|
203
|
+
);
|
|
274
204
|
const returnValue = toObjCValue(
|
|
275
205
|
hasteModuleName,
|
|
276
206
|
typeAnnotation,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
unwrapNullable
|
|
5
|
+
} = require('../../../../parsers/parsers-commons');
|
|
6
|
+
const {
|
|
7
|
+
wrapOptional: wrapCxxOptional
|
|
8
|
+
} = require('../../../TypeUtils/Cxx');
|
|
9
|
+
const {
|
|
10
|
+
wrapOptional: wrapObjCOptional
|
|
11
|
+
} = require('../../../TypeUtils/Objective-C');
|
|
12
|
+
const {
|
|
13
|
+
capitalize
|
|
14
|
+
} = require('../../../Utils');
|
|
15
|
+
const {
|
|
16
|
+
getNamespacedStructName
|
|
17
|
+
} = require('../Utils');
|
|
18
|
+
function toObjCType(hasteModuleName, nullableTypeAnnotation, structContext, isOptional = false) {
|
|
19
|
+
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
20
|
+
const isRequired = !nullable && !isOptional;
|
|
21
|
+
switch (typeAnnotation.type) {
|
|
22
|
+
case 'ReservedTypeAnnotation':
|
|
23
|
+
switch (typeAnnotation.name) {
|
|
24
|
+
case 'RootTag':
|
|
25
|
+
return wrapCxxOptional('double', isRequired);
|
|
26
|
+
default:
|
|
27
|
+
typeAnnotation.name;
|
|
28
|
+
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
|
29
|
+
}
|
|
30
|
+
case 'StringTypeAnnotation':
|
|
31
|
+
return 'NSString *';
|
|
32
|
+
case 'StringLiteralTypeAnnotation':
|
|
33
|
+
return 'NSString *';
|
|
34
|
+
case 'UnionTypeAnnotation':
|
|
35
|
+
return 'NSObject *';
|
|
36
|
+
case 'NumberTypeAnnotation':
|
|
37
|
+
return wrapCxxOptional('double', isRequired);
|
|
38
|
+
case 'NumberLiteralTypeAnnotation':
|
|
39
|
+
return wrapCxxOptional('double', isRequired);
|
|
40
|
+
case 'FloatTypeAnnotation':
|
|
41
|
+
return wrapCxxOptional('double', isRequired);
|
|
42
|
+
case 'Int32TypeAnnotation':
|
|
43
|
+
return wrapCxxOptional('double', isRequired);
|
|
44
|
+
case 'DoubleTypeAnnotation':
|
|
45
|
+
return wrapCxxOptional('double', isRequired);
|
|
46
|
+
case 'BooleanTypeAnnotation':
|
|
47
|
+
return wrapCxxOptional('bool', isRequired);
|
|
48
|
+
case 'BooleanLiteralTypeAnnotation':
|
|
49
|
+
return wrapCxxOptional('bool', isRequired);
|
|
50
|
+
case 'EnumDeclaration':
|
|
51
|
+
switch (typeAnnotation.memberType) {
|
|
52
|
+
case 'NumberTypeAnnotation':
|
|
53
|
+
return wrapCxxOptional('double', isRequired);
|
|
54
|
+
case 'StringTypeAnnotation':
|
|
55
|
+
return 'NSString *';
|
|
56
|
+
default:
|
|
57
|
+
throw new Error(`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`);
|
|
58
|
+
}
|
|
59
|
+
case 'GenericObjectTypeAnnotation':
|
|
60
|
+
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
61
|
+
case 'ArrayTypeAnnotation':
|
|
62
|
+
if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') {
|
|
63
|
+
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
64
|
+
}
|
|
65
|
+
return wrapCxxOptional(structContext === 'CONSTANTS' ? `std::vector<${toObjCType(hasteModuleName, typeAnnotation.elementType, structContext)}>` : `facebook::react::LazyVector<${toObjCType(hasteModuleName, typeAnnotation.elementType, structContext)}>`, isRequired);
|
|
66
|
+
case 'TypeAliasTypeAnnotation':
|
|
67
|
+
const structName = capitalize(typeAnnotation.name);
|
|
68
|
+
const namespacedStructName = getNamespacedStructName(hasteModuleName, structName);
|
|
69
|
+
return wrapCxxOptional(structContext === 'CONSTANTS' ? `${namespacedStructName}::Builder` : namespacedStructName, isRequired);
|
|
70
|
+
default:
|
|
71
|
+
typeAnnotation.type;
|
|
72
|
+
throw new Error(`Couldn't convert into ObjC type: ${typeAnnotation.type}"`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
module.exports = {
|
|
76
|
+
toObjCType
|
|
77
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
import type {Nullable} from '../../../../CodegenSchema';
|
|
14
|
+
import type {StructContext, StructTypeAnnotation} from '../StructCollector';
|
|
15
|
+
|
|
16
|
+
const {unwrapNullable} = require('../../../../parsers/parsers-commons');
|
|
17
|
+
const {wrapOptional: wrapCxxOptional} = require('../../../TypeUtils/Cxx');
|
|
18
|
+
const {
|
|
19
|
+
wrapOptional: wrapObjCOptional,
|
|
20
|
+
} = require('../../../TypeUtils/Objective-C');
|
|
21
|
+
const {capitalize} = require('../../../Utils');
|
|
22
|
+
const {getNamespacedStructName} = require('../Utils');
|
|
23
|
+
|
|
24
|
+
function toObjCType(
|
|
25
|
+
hasteModuleName: string,
|
|
26
|
+
nullableTypeAnnotation: Nullable<StructTypeAnnotation>,
|
|
27
|
+
structContext: StructContext,
|
|
28
|
+
isOptional: boolean = false,
|
|
29
|
+
): string {
|
|
30
|
+
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
31
|
+
const isRequired = !nullable && !isOptional;
|
|
32
|
+
|
|
33
|
+
switch (typeAnnotation.type) {
|
|
34
|
+
case 'ReservedTypeAnnotation':
|
|
35
|
+
switch (typeAnnotation.name) {
|
|
36
|
+
case 'RootTag':
|
|
37
|
+
return wrapCxxOptional('double', isRequired);
|
|
38
|
+
default:
|
|
39
|
+
(typeAnnotation.name: empty);
|
|
40
|
+
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
|
41
|
+
}
|
|
42
|
+
case 'StringTypeAnnotation':
|
|
43
|
+
return 'NSString *';
|
|
44
|
+
case 'StringLiteralTypeAnnotation':
|
|
45
|
+
return 'NSString *';
|
|
46
|
+
case 'UnionTypeAnnotation':
|
|
47
|
+
// TODO(T247151345): Implement proper heterogeneous union support. This is unsafe.
|
|
48
|
+
return 'NSObject *';
|
|
49
|
+
case 'NumberTypeAnnotation':
|
|
50
|
+
return wrapCxxOptional('double', isRequired);
|
|
51
|
+
case 'NumberLiteralTypeAnnotation':
|
|
52
|
+
return wrapCxxOptional('double', isRequired);
|
|
53
|
+
case 'FloatTypeAnnotation':
|
|
54
|
+
return wrapCxxOptional('double', isRequired);
|
|
55
|
+
case 'Int32TypeAnnotation':
|
|
56
|
+
return wrapCxxOptional('double', isRequired);
|
|
57
|
+
case 'DoubleTypeAnnotation':
|
|
58
|
+
return wrapCxxOptional('double', isRequired);
|
|
59
|
+
case 'BooleanTypeAnnotation':
|
|
60
|
+
return wrapCxxOptional('bool', isRequired);
|
|
61
|
+
case 'BooleanLiteralTypeAnnotation':
|
|
62
|
+
return wrapCxxOptional('bool', isRequired);
|
|
63
|
+
case 'EnumDeclaration':
|
|
64
|
+
switch (typeAnnotation.memberType) {
|
|
65
|
+
case 'NumberTypeAnnotation':
|
|
66
|
+
return wrapCxxOptional('double', isRequired);
|
|
67
|
+
case 'StringTypeAnnotation':
|
|
68
|
+
return 'NSString *';
|
|
69
|
+
default:
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
case 'GenericObjectTypeAnnotation':
|
|
75
|
+
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
76
|
+
case 'ArrayTypeAnnotation':
|
|
77
|
+
if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') {
|
|
78
|
+
return wrapObjCOptional('id<NSObject>', isRequired);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return wrapCxxOptional(
|
|
82
|
+
structContext === 'CONSTANTS'
|
|
83
|
+
? `std::vector<${toObjCType(
|
|
84
|
+
hasteModuleName,
|
|
85
|
+
typeAnnotation.elementType,
|
|
86
|
+
structContext,
|
|
87
|
+
)}>`
|
|
88
|
+
: `facebook::react::LazyVector<${toObjCType(
|
|
89
|
+
hasteModuleName,
|
|
90
|
+
typeAnnotation.elementType,
|
|
91
|
+
structContext,
|
|
92
|
+
)}>`,
|
|
93
|
+
isRequired,
|
|
94
|
+
);
|
|
95
|
+
case 'TypeAliasTypeAnnotation':
|
|
96
|
+
const structName = capitalize(typeAnnotation.name);
|
|
97
|
+
const namespacedStructName = getNamespacedStructName(
|
|
98
|
+
hasteModuleName,
|
|
99
|
+
structName,
|
|
100
|
+
);
|
|
101
|
+
return wrapCxxOptional(
|
|
102
|
+
structContext === 'CONSTANTS'
|
|
103
|
+
? `${namespacedStructName}::Builder`
|
|
104
|
+
: namespacedStructName,
|
|
105
|
+
isRequired,
|
|
106
|
+
);
|
|
107
|
+
default:
|
|
108
|
+
(typeAnnotation.type: empty);
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Couldn't convert into ObjC type: ${typeAnnotation.type}"`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
toObjCType,
|
|
117
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/codegen",
|
|
3
|
-
"version": "0.86.0-nightly-
|
|
3
|
+
"version": "0.86.0-nightly-20260319-941ace990",
|
|
4
4
|
"description": "Code generation tools for React Native",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/core": "^7.25.2",
|
|
33
33
|
"@babel/parser": "^7.29.0",
|
|
34
|
-
"hermes-parser": "0.
|
|
34
|
+
"hermes-parser": "0.34.0",
|
|
35
35
|
"invariant": "^2.2.4",
|
|
36
36
|
"nullthrows": "^1.1.1",
|
|
37
37
|
"tinyglobby": "^0.2.15",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7",
|
|
46
46
|
"@babel/plugin-transform-optional-chaining": "^7.24.8",
|
|
47
47
|
"@babel/preset-env": "^7.25.3",
|
|
48
|
-
"babel-plugin-syntax-hermes-parser": "0.
|
|
49
|
-
"hermes-estree": "0.
|
|
48
|
+
"babel-plugin-syntax-hermes-parser": "0.34.0",
|
|
49
|
+
"hermes-estree": "0.34.0",
|
|
50
50
|
"micromatch": "^4.0.4",
|
|
51
51
|
"prettier": "3.6.2",
|
|
52
52
|
"rimraf": "^3.0.2"
|