@react-native/codegen 0.77.0-nightly-20241007-d0912ed06 → 0.77.0-nightly-20241009-e4814b0d6
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 +14 -0
- package/lib/CodegenSchema.js.flow +14 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js +6 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +6 -0
- package/lib/generators/components/JavaHelpers.js +1 -0
- package/lib/generators/components/JavaHelpers.js.flow +2 -6
- package/lib/generators/modules/GenerateModuleCpp.js +4 -0
- package/lib/generators/modules/GenerateModuleCpp.js.flow +4 -0
- package/lib/generators/modules/GenerateModuleH.js +4 -0
- package/lib/generators/modules/GenerateModuleH.js.flow +4 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js +27 -1
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +27 -1
- package/lib/generators/modules/GenerateModuleJniCpp.js +12 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +12 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +4 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +8 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +8 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +8 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +8 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeEventEmitter.js +15 -1
- package/lib/generators/modules/GenerateModuleObjCpp/serializeEventEmitter.js.flow +16 -1
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +16 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +16 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js +83 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +84 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +1 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +1 -0
- package/lib/parsers/flow/modules/index.js +2 -3
- package/lib/parsers/flow/modules/index.js.flow +2 -3
- package/lib/parsers/flow/parser.js +3 -0
- package/lib/parsers/flow/parser.js.flow +6 -0
- package/lib/parsers/parser.js.flow +8 -0
- package/lib/parsers/parserMock.js +3 -0
- package/lib/parsers/parserMock.js.flow +6 -0
- package/lib/parsers/parsers-primitives.js +39 -0
- package/lib/parsers/parsers-primitives.js.flow +51 -1
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +1 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +1 -0
- package/lib/parsers/typescript/modules/index.js +16 -0
- package/lib/parsers/typescript/modules/index.js.flow +16 -0
- package/lib/parsers/typescript/parser.js +3 -0
- package/lib/parsers/typescript/parser.js.flow +6 -0
- package/package.json +1 -1
package/lib/CodegenSchema.d.ts
CHANGED
|
@@ -290,6 +290,16 @@ export interface NativeModuleStringTypeAnnotation {
|
|
|
290
290
|
readonly type: 'StringTypeAnnotation';
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
+
export interface NativeModuleStringLiteralTypeAnnotation {
|
|
294
|
+
readonly type: 'StringLiteralTypeAnnotation';
|
|
295
|
+
readonly value: string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface NativeModuleStringLiteralUnionTypeAnnotation {
|
|
299
|
+
readonly type: 'StringLiteralUnionTypeAnnotation';
|
|
300
|
+
readonly types: NativeModuleStringLiteralTypeAnnotation[];
|
|
301
|
+
}
|
|
302
|
+
|
|
293
303
|
export interface NativeModuleNumberTypeAnnotation {
|
|
294
304
|
readonly type: 'NumberTypeAnnotation';
|
|
295
305
|
}
|
|
@@ -371,6 +381,8 @@ export type NativeModuleEventEmitterBaseTypeAnnotation =
|
|
|
371
381
|
| NativeModuleInt32TypeAnnotation
|
|
372
382
|
| NativeModuleNumberTypeAnnotation
|
|
373
383
|
| NativeModuleStringTypeAnnotation
|
|
384
|
+
| NativeModuleStringLiteralTypeAnnotation
|
|
385
|
+
| NativeModuleStringLiteralUnionTypeAnnotation
|
|
374
386
|
| NativeModuleTypeAliasTypeAnnotation
|
|
375
387
|
| NativeModuleGenericObjectTypeAnnotation
|
|
376
388
|
| VoidTypeAnnotation;
|
|
@@ -384,6 +396,8 @@ export type NativeModuleEventEmitterTypeAnnotation =
|
|
|
384
396
|
|
|
385
397
|
export type NativeModuleBaseTypeAnnotation =
|
|
386
398
|
| NativeModuleStringTypeAnnotation
|
|
399
|
+
| NativeModuleStringLiteralTypeAnnotation
|
|
400
|
+
| NativeModuleStringLiteralUnionTypeAnnotation
|
|
387
401
|
| NativeModuleNumberTypeAnnotation
|
|
388
402
|
| NativeModuleInt32TypeAnnotation
|
|
389
403
|
| NativeModuleDoubleTypeAnnotation
|
|
@@ -41,6 +41,16 @@ export type StringTypeAnnotation = $ReadOnly<{
|
|
|
41
41
|
type: 'StringTypeAnnotation',
|
|
42
42
|
}>;
|
|
43
43
|
|
|
44
|
+
export type StringLiteralTypeAnnotation = $ReadOnly<{
|
|
45
|
+
type: 'StringLiteralTypeAnnotation',
|
|
46
|
+
value: string,
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export type StringLiteralUnionTypeAnnotation = $ReadOnly<{
|
|
50
|
+
type: 'StringLiteralUnionTypeAnnotation',
|
|
51
|
+
types: $ReadOnlyArray<StringLiteralTypeAnnotation>,
|
|
52
|
+
}>;
|
|
53
|
+
|
|
44
54
|
export type StringEnumTypeAnnotation = $ReadOnly<{
|
|
45
55
|
type: 'StringEnumTypeAnnotation',
|
|
46
56
|
options: $ReadOnlyArray<string>,
|
|
@@ -357,6 +367,8 @@ type NativeModuleEventEmitterBaseTypeAnnotation =
|
|
|
357
367
|
| Int32TypeAnnotation
|
|
358
368
|
| NativeModuleNumberTypeAnnotation
|
|
359
369
|
| StringTypeAnnotation
|
|
370
|
+
| StringLiteralTypeAnnotation
|
|
371
|
+
| StringLiteralUnionTypeAnnotation
|
|
360
372
|
| NativeModuleTypeAliasTypeAnnotation
|
|
361
373
|
| NativeModuleGenericObjectTypeAnnotation
|
|
362
374
|
| VoidTypeAnnotation;
|
|
@@ -370,6 +382,8 @@ export type NativeModuleEventEmitterTypeAnnotation =
|
|
|
370
382
|
|
|
371
383
|
export type NativeModuleBaseTypeAnnotation =
|
|
372
384
|
| StringTypeAnnotation
|
|
385
|
+
| StringLiteralTypeAnnotation
|
|
386
|
+
| StringLiteralUnionTypeAnnotation
|
|
373
387
|
| NativeModuleNumberTypeAnnotation
|
|
374
388
|
| Int32TypeAnnotation
|
|
375
389
|
| DoubleTypeAnnotation
|
|
@@ -59,11 +59,17 @@ const _require = require('./combine-js-to-schema'),
|
|
|
59
59
|
_require.combineSchemasInFileListAndWriteToFile;
|
|
60
60
|
const yargs = require('yargs');
|
|
61
61
|
const argv = yargs
|
|
62
|
+
.usage('Usage: $0 <outfile> <file1> [<file2> ...]')
|
|
62
63
|
.option('p', {
|
|
64
|
+
describe:
|
|
65
|
+
'Platforms to generate schema for, this works on filenames: <filename>[.<platform>].(js|tsx?)',
|
|
63
66
|
alias: 'platform',
|
|
67
|
+
default: null,
|
|
64
68
|
})
|
|
65
69
|
.option('e', {
|
|
70
|
+
describe: 'Regular expression to exclude files from schema generation',
|
|
66
71
|
alias: 'exclude',
|
|
72
|
+
default: null,
|
|
67
73
|
})
|
|
68
74
|
.parseSync();
|
|
69
75
|
const _argv$_ = _toArray(argv._),
|
|
@@ -17,11 +17,17 @@ const {
|
|
|
17
17
|
const yargs = require('yargs');
|
|
18
18
|
|
|
19
19
|
const argv = yargs
|
|
20
|
+
.usage('Usage: $0 <outfile> <file1> [<file2> ...]')
|
|
20
21
|
.option('p', {
|
|
22
|
+
describe:
|
|
23
|
+
'Platforms to generate schema for, this works on filenames: <filename>[.<platform>].(js|tsx?)',
|
|
21
24
|
alias: 'platform',
|
|
25
|
+
default: null,
|
|
22
26
|
})
|
|
23
27
|
.option('e', {
|
|
28
|
+
describe: 'Regular expression to exclude files from schema generation',
|
|
24
29
|
alias: 'exclude',
|
|
30
|
+
default: null,
|
|
25
31
|
})
|
|
26
32
|
.parseSync();
|
|
27
33
|
|
|
@@ -77,6 +77,7 @@ function getImports(component, type) {
|
|
|
77
77
|
component.props.forEach(prop => {
|
|
78
78
|
const typeAnnotation = prop.typeAnnotation;
|
|
79
79
|
if (typeAnnotation.type === 'ReservedPropTypeAnnotation') {
|
|
80
|
+
// $FlowFixMe[incompatible-call]
|
|
80
81
|
addImportsForNativeName(typeAnnotation.name);
|
|
81
82
|
}
|
|
82
83
|
if (typeAnnotation.type === 'ArrayTypeAnnotation') {
|
|
@@ -66,12 +66,7 @@ function getImports(
|
|
|
66
66
|
| 'EdgeInsetsPrimitive'
|
|
67
67
|
| 'ImageSourcePrimitive'
|
|
68
68
|
| 'PointPrimitive'
|
|
69
|
-
| 'DimensionPrimitive'
|
|
70
|
-
| $TEMPORARY$string<'ColorPrimitive'>
|
|
71
|
-
| $TEMPORARY$string<'EdgeInsetsPrimitive'>
|
|
72
|
-
| $TEMPORARY$string<'ImageSourcePrimitive'>
|
|
73
|
-
| $TEMPORARY$string<'PointPrimitive'>
|
|
74
|
-
| $TEMPORARY$string<'DimensionPrimitive'>,
|
|
69
|
+
| 'DimensionPrimitive',
|
|
75
70
|
) {
|
|
76
71
|
switch (name) {
|
|
77
72
|
case 'ColorPrimitive':
|
|
@@ -107,6 +102,7 @@ function getImports(
|
|
|
107
102
|
const typeAnnotation = prop.typeAnnotation;
|
|
108
103
|
|
|
109
104
|
if (typeAnnotation.type === 'ReservedPropTypeAnnotation') {
|
|
105
|
+
// $FlowFixMe[incompatible-call]
|
|
110
106
|
addImportsForNativeName(typeAnnotation.name);
|
|
111
107
|
}
|
|
112
108
|
|
|
@@ -193,6 +193,10 @@ function serializeArg(moduleName, arg, index, resolveAlias, enumMap) {
|
|
|
193
193
|
}
|
|
194
194
|
case 'StringTypeAnnotation':
|
|
195
195
|
return wrap(val => `${val}.asString(rt)`);
|
|
196
|
+
case 'StringLiteralTypeAnnotation':
|
|
197
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
198
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
199
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
196
200
|
case 'BooleanTypeAnnotation':
|
|
197
201
|
return wrap(val => `${val}.asBool()`);
|
|
198
202
|
case 'EnumDeclaration':
|
|
@@ -161,6 +161,10 @@ function serializeArg(
|
|
|
161
161
|
}
|
|
162
162
|
case 'StringTypeAnnotation':
|
|
163
163
|
return wrap(val => `${val}.asString(rt)`);
|
|
164
|
+
case 'StringLiteralTypeAnnotation':
|
|
165
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
166
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
167
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
164
168
|
case 'BooleanTypeAnnotation':
|
|
165
169
|
return wrap(val => `${val}.asBool()`);
|
|
166
170
|
case 'EnumDeclaration':
|
|
@@ -213,6 +213,10 @@ function translatePrimitiveJSTypeToCpp(
|
|
|
213
213
|
return 'void';
|
|
214
214
|
case 'StringTypeAnnotation':
|
|
215
215
|
return wrapOptional('jsi::String', isRequired);
|
|
216
|
+
case 'StringLiteralTypeAnnotation':
|
|
217
|
+
return wrapOptional('jsi::String', isRequired);
|
|
218
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
219
|
+
return wrapOptional('jsi::String', isRequired);
|
|
216
220
|
case 'NumberTypeAnnotation':
|
|
217
221
|
return wrapOptional('double', isRequired);
|
|
218
222
|
case 'DoubleTypeAnnotation':
|
|
@@ -173,6 +173,10 @@ function translatePrimitiveJSTypeToCpp(
|
|
|
173
173
|
return 'void';
|
|
174
174
|
case 'StringTypeAnnotation':
|
|
175
175
|
return wrapOptional('jsi::String', isRequired);
|
|
176
|
+
case 'StringLiteralTypeAnnotation':
|
|
177
|
+
return wrapOptional('jsi::String', isRequired);
|
|
178
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
179
|
+
return wrapOptional('jsi::String', isRequired);
|
|
176
180
|
case 'NumberTypeAnnotation':
|
|
177
181
|
return wrapOptional('double', isRequired);
|
|
178
182
|
case 'DoubleTypeAnnotation':
|
|
@@ -162,9 +162,14 @@ function MethodTemplate(config) {
|
|
|
162
162
|
)})${methodClosing}`;
|
|
163
163
|
}
|
|
164
164
|
function translateEventEmitterTypeToJavaType(eventEmitter, imports) {
|
|
165
|
-
|
|
165
|
+
const type = eventEmitter.typeAnnotation.typeAnnotation.type;
|
|
166
|
+
switch (type) {
|
|
166
167
|
case 'StringTypeAnnotation':
|
|
167
168
|
return 'String';
|
|
169
|
+
case 'StringLiteralTypeAnnotation':
|
|
170
|
+
return 'String';
|
|
171
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
172
|
+
return 'String';
|
|
168
173
|
case 'NumberTypeAnnotation':
|
|
169
174
|
case 'FloatTypeAnnotation':
|
|
170
175
|
case 'DoubleTypeAnnotation':
|
|
@@ -180,7 +185,16 @@ function translateEventEmitterTypeToJavaType(eventEmitter, imports) {
|
|
|
180
185
|
case 'ArrayTypeAnnotation':
|
|
181
186
|
imports.add('com.facebook.react.bridge.ReadableArray');
|
|
182
187
|
return 'ReadableArray';
|
|
188
|
+
case 'DoubleTypeAnnotation':
|
|
189
|
+
case 'FloatTypeAnnotation':
|
|
190
|
+
case 'Int32TypeAnnotation':
|
|
191
|
+
case 'VoidTypeAnnotation':
|
|
192
|
+
// TODO: Add support for these types
|
|
193
|
+
throw new Error(
|
|
194
|
+
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
195
|
+
);
|
|
183
196
|
default:
|
|
197
|
+
type;
|
|
184
198
|
throw new Error(
|
|
185
199
|
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
186
200
|
);
|
|
@@ -219,6 +233,10 @@ function translateFunctionParamToJavaType(
|
|
|
219
233
|
}
|
|
220
234
|
case 'StringTypeAnnotation':
|
|
221
235
|
return wrapOptional('String', isRequired);
|
|
236
|
+
case 'StringLiteralTypeAnnotation':
|
|
237
|
+
return wrapOptional('String', isRequired);
|
|
238
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
239
|
+
return wrapOptional('String', isRequired);
|
|
222
240
|
case 'NumberTypeAnnotation':
|
|
223
241
|
return wrapOptional('double', isRequired);
|
|
224
242
|
case 'FloatTypeAnnotation':
|
|
@@ -305,6 +323,10 @@ function translateFunctionReturnTypeToJavaType(
|
|
|
305
323
|
return 'void';
|
|
306
324
|
case 'StringTypeAnnotation':
|
|
307
325
|
return wrapOptional('String', isRequired);
|
|
326
|
+
case 'StringLiteralTypeAnnotation':
|
|
327
|
+
return wrapOptional('String', isRequired);
|
|
328
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
329
|
+
return wrapOptional('String', isRequired);
|
|
308
330
|
case 'NumberTypeAnnotation':
|
|
309
331
|
return wrapOptional('double', isRequired);
|
|
310
332
|
case 'FloatTypeAnnotation':
|
|
@@ -412,6 +434,10 @@ function getFalsyReturnStatementFromReturnType(
|
|
|
412
434
|
}
|
|
413
435
|
case 'StringTypeAnnotation':
|
|
414
436
|
return nullable ? 'return null;' : 'return "";';
|
|
437
|
+
case 'StringLiteralTypeAnnotation':
|
|
438
|
+
return nullable ? 'return null;' : 'return "";';
|
|
439
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
440
|
+
return nullable ? 'return null;' : 'return "";';
|
|
415
441
|
case 'ObjectTypeAnnotation':
|
|
416
442
|
return 'return null;';
|
|
417
443
|
case 'GenericObjectTypeAnnotation':
|
|
@@ -127,9 +127,14 @@ function translateEventEmitterTypeToJavaType(
|
|
|
127
127
|
eventEmitter: NativeModuleEventEmitterShape,
|
|
128
128
|
imports: Set<string>,
|
|
129
129
|
): string {
|
|
130
|
-
|
|
130
|
+
const type = eventEmitter.typeAnnotation.typeAnnotation.type;
|
|
131
|
+
switch (type) {
|
|
131
132
|
case 'StringTypeAnnotation':
|
|
132
133
|
return 'String';
|
|
134
|
+
case 'StringLiteralTypeAnnotation':
|
|
135
|
+
return 'String';
|
|
136
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
137
|
+
return 'String';
|
|
133
138
|
case 'NumberTypeAnnotation':
|
|
134
139
|
case 'FloatTypeAnnotation':
|
|
135
140
|
case 'DoubleTypeAnnotation':
|
|
@@ -145,7 +150,16 @@ function translateEventEmitterTypeToJavaType(
|
|
|
145
150
|
case 'ArrayTypeAnnotation':
|
|
146
151
|
imports.add('com.facebook.react.bridge.ReadableArray');
|
|
147
152
|
return 'ReadableArray';
|
|
153
|
+
case 'DoubleTypeAnnotation':
|
|
154
|
+
case 'FloatTypeAnnotation':
|
|
155
|
+
case 'Int32TypeAnnotation':
|
|
156
|
+
case 'VoidTypeAnnotation':
|
|
157
|
+
// TODO: Add support for these types
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
160
|
+
);
|
|
148
161
|
default:
|
|
162
|
+
(type: empty);
|
|
149
163
|
throw new Error(
|
|
150
164
|
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
151
165
|
);
|
|
@@ -183,6 +197,10 @@ function translateFunctionParamToJavaType(
|
|
|
183
197
|
}
|
|
184
198
|
case 'StringTypeAnnotation':
|
|
185
199
|
return wrapOptional('String', isRequired);
|
|
200
|
+
case 'StringLiteralTypeAnnotation':
|
|
201
|
+
return wrapOptional('String', isRequired);
|
|
202
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
203
|
+
return wrapOptional('String', isRequired);
|
|
186
204
|
case 'NumberTypeAnnotation':
|
|
187
205
|
return wrapOptional('double', isRequired);
|
|
188
206
|
case 'FloatTypeAnnotation':
|
|
@@ -273,6 +291,10 @@ function translateFunctionReturnTypeToJavaType(
|
|
|
273
291
|
return 'void';
|
|
274
292
|
case 'StringTypeAnnotation':
|
|
275
293
|
return wrapOptional('String', isRequired);
|
|
294
|
+
case 'StringLiteralTypeAnnotation':
|
|
295
|
+
return wrapOptional('String', isRequired);
|
|
296
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
297
|
+
return wrapOptional('String', isRequired);
|
|
276
298
|
case 'NumberTypeAnnotation':
|
|
277
299
|
return wrapOptional('double', isRequired);
|
|
278
300
|
case 'FloatTypeAnnotation':
|
|
@@ -383,6 +405,10 @@ function getFalsyReturnStatementFromReturnType(
|
|
|
383
405
|
}
|
|
384
406
|
case 'StringTypeAnnotation':
|
|
385
407
|
return nullable ? 'return null;' : 'return "";';
|
|
408
|
+
case 'StringLiteralTypeAnnotation':
|
|
409
|
+
return nullable ? 'return null;' : 'return "";';
|
|
410
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
411
|
+
return nullable ? 'return null;' : 'return "";';
|
|
386
412
|
case 'ObjectTypeAnnotation':
|
|
387
413
|
return 'return null;';
|
|
388
414
|
case 'GenericObjectTypeAnnotation':
|
|
@@ -180,6 +180,10 @@ function translateReturnTypeToKind(nullableTypeAnnotation, resolveAlias) {
|
|
|
180
180
|
return 'VoidKind';
|
|
181
181
|
case 'StringTypeAnnotation':
|
|
182
182
|
return 'StringKind';
|
|
183
|
+
case 'StringLiteralTypeAnnotation':
|
|
184
|
+
return 'StringKind';
|
|
185
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
186
|
+
return 'StringKind';
|
|
183
187
|
case 'BooleanTypeAnnotation':
|
|
184
188
|
return 'BooleanKind';
|
|
185
189
|
case 'EnumDeclaration':
|
|
@@ -254,6 +258,10 @@ function translateParamTypeToJniType(param, resolveAlias) {
|
|
|
254
258
|
}
|
|
255
259
|
case 'StringTypeAnnotation':
|
|
256
260
|
return 'Ljava/lang/String;';
|
|
261
|
+
case 'StringLiteralTypeAnnotation':
|
|
262
|
+
return 'Ljava/lang/String;';
|
|
263
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
264
|
+
return 'Ljava/lang/String;';
|
|
257
265
|
case 'BooleanTypeAnnotation':
|
|
258
266
|
return !isRequired ? 'Ljava/lang/Boolean;' : 'Z';
|
|
259
267
|
case 'EnumDeclaration':
|
|
@@ -327,6 +335,10 @@ function translateReturnTypeToJniType(nullableTypeAnnotation, resolveAlias) {
|
|
|
327
335
|
return 'V';
|
|
328
336
|
case 'StringTypeAnnotation':
|
|
329
337
|
return 'Ljava/lang/String;';
|
|
338
|
+
case 'StringLiteralTypeAnnotation':
|
|
339
|
+
return 'Ljava/lang/String;';
|
|
340
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
341
|
+
return 'Ljava/lang/String;';
|
|
330
342
|
case 'BooleanTypeAnnotation':
|
|
331
343
|
return nullable ? 'Ljava/lang/Boolean;' : 'Z';
|
|
332
344
|
case 'EnumDeclaration':
|
|
@@ -165,6 +165,10 @@ function translateReturnTypeToKind(
|
|
|
165
165
|
return 'VoidKind';
|
|
166
166
|
case 'StringTypeAnnotation':
|
|
167
167
|
return 'StringKind';
|
|
168
|
+
case 'StringLiteralTypeAnnotation':
|
|
169
|
+
return 'StringKind';
|
|
170
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
171
|
+
return 'StringKind';
|
|
168
172
|
case 'BooleanTypeAnnotation':
|
|
169
173
|
return 'BooleanKind';
|
|
170
174
|
case 'EnumDeclaration':
|
|
@@ -244,6 +248,10 @@ function translateParamTypeToJniType(
|
|
|
244
248
|
}
|
|
245
249
|
case 'StringTypeAnnotation':
|
|
246
250
|
return 'Ljava/lang/String;';
|
|
251
|
+
case 'StringLiteralTypeAnnotation':
|
|
252
|
+
return 'Ljava/lang/String;';
|
|
253
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
254
|
+
return 'Ljava/lang/String;';
|
|
247
255
|
case 'BooleanTypeAnnotation':
|
|
248
256
|
return !isRequired ? 'Ljava/lang/Boolean;' : 'Z';
|
|
249
257
|
case 'EnumDeclaration':
|
|
@@ -320,6 +328,10 @@ function translateReturnTypeToJniType(
|
|
|
320
328
|
return 'V';
|
|
321
329
|
case 'StringTypeAnnotation':
|
|
322
330
|
return 'Ljava/lang/String;';
|
|
331
|
+
case 'StringLiteralTypeAnnotation':
|
|
332
|
+
return 'Ljava/lang/String;';
|
|
333
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
334
|
+
return 'Ljava/lang/String;';
|
|
323
335
|
case 'BooleanTypeAnnotation':
|
|
324
336
|
return nullable ? 'Ljava/lang/Boolean;' : 'Z';
|
|
325
337
|
case 'EnumDeclaration':
|
|
@@ -22,6 +22,8 @@ import type {
|
|
|
22
22
|
NativeModuleNumberTypeAnnotation,
|
|
23
23
|
NativeModuleObjectTypeAnnotation,
|
|
24
24
|
StringTypeAnnotation,
|
|
25
|
+
StringLiteralTypeAnnotation,
|
|
26
|
+
StringLiteralUnionTypeAnnotation,
|
|
25
27
|
NativeModuleTypeAliasTypeAnnotation,
|
|
26
28
|
Nullable,
|
|
27
29
|
ReservedTypeAnnotation,
|
|
@@ -58,6 +60,8 @@ export type StructProperty = $ReadOnly<{
|
|
|
58
60
|
|
|
59
61
|
export type StructTypeAnnotation =
|
|
60
62
|
| StringTypeAnnotation
|
|
63
|
+
| StringLiteralTypeAnnotation
|
|
64
|
+
| StringLiteralUnionTypeAnnotation
|
|
61
65
|
| NativeModuleNumberTypeAnnotation
|
|
62
66
|
| Int32TypeAnnotation
|
|
63
67
|
| DoubleTypeAnnotation
|
|
@@ -157,6 +157,10 @@ function toObjCType(
|
|
|
157
157
|
}
|
|
158
158
|
case 'StringTypeAnnotation':
|
|
159
159
|
return 'NSString *';
|
|
160
|
+
case 'StringLiteralTypeAnnotation':
|
|
161
|
+
return 'NSString *';
|
|
162
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
163
|
+
return 'NSString *';
|
|
160
164
|
case 'NumberTypeAnnotation':
|
|
161
165
|
return wrapCxxOptional('double', isRequired);
|
|
162
166
|
case 'FloatTypeAnnotation':
|
|
@@ -235,6 +239,10 @@ function toObjCValue(
|
|
|
235
239
|
}
|
|
236
240
|
case 'StringTypeAnnotation':
|
|
237
241
|
return value;
|
|
242
|
+
case 'StringLiteralTypeAnnotation':
|
|
243
|
+
return value;
|
|
244
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
245
|
+
return value;
|
|
238
246
|
case 'NumberTypeAnnotation':
|
|
239
247
|
return wrapPrimitive('double');
|
|
240
248
|
case 'FloatTypeAnnotation':
|
|
@@ -94,6 +94,10 @@ function toObjCType(
|
|
|
94
94
|
}
|
|
95
95
|
case 'StringTypeAnnotation':
|
|
96
96
|
return 'NSString *';
|
|
97
|
+
case 'StringLiteralTypeAnnotation':
|
|
98
|
+
return 'NSString *';
|
|
99
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
100
|
+
return 'NSString *';
|
|
97
101
|
case 'NumberTypeAnnotation':
|
|
98
102
|
return wrapCxxOptional('double', isRequired);
|
|
99
103
|
case 'FloatTypeAnnotation':
|
|
@@ -173,6 +177,10 @@ function toObjCValue(
|
|
|
173
177
|
}
|
|
174
178
|
case 'StringTypeAnnotation':
|
|
175
179
|
return value;
|
|
180
|
+
case 'StringLiteralTypeAnnotation':
|
|
181
|
+
return value;
|
|
182
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
183
|
+
return value;
|
|
176
184
|
case 'NumberTypeAnnotation':
|
|
177
185
|
return wrapPrimitive('double');
|
|
178
186
|
case 'FloatTypeAnnotation':
|
|
@@ -145,6 +145,10 @@ function toObjCType(
|
|
|
145
145
|
}
|
|
146
146
|
case 'StringTypeAnnotation':
|
|
147
147
|
return 'NSString *';
|
|
148
|
+
case 'StringLiteralTypeAnnotation':
|
|
149
|
+
return 'NSString *';
|
|
150
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
151
|
+
return 'NSString *';
|
|
148
152
|
case 'NumberTypeAnnotation':
|
|
149
153
|
return wrapCxxOptional('double', isRequired);
|
|
150
154
|
case 'FloatTypeAnnotation':
|
|
@@ -224,6 +228,10 @@ function toObjCValue(
|
|
|
224
228
|
}
|
|
225
229
|
case 'StringTypeAnnotation':
|
|
226
230
|
return RCTBridgingTo('String');
|
|
231
|
+
case 'StringLiteralTypeAnnotation':
|
|
232
|
+
return RCTBridgingTo('String');
|
|
233
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
234
|
+
return RCTBridgingTo('String');
|
|
227
235
|
case 'NumberTypeAnnotation':
|
|
228
236
|
return RCTBridgingTo('Double');
|
|
229
237
|
case 'FloatTypeAnnotation':
|
|
@@ -85,6 +85,10 @@ function toObjCType(
|
|
|
85
85
|
}
|
|
86
86
|
case 'StringTypeAnnotation':
|
|
87
87
|
return 'NSString *';
|
|
88
|
+
case 'StringLiteralTypeAnnotation':
|
|
89
|
+
return 'NSString *';
|
|
90
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
91
|
+
return 'NSString *';
|
|
88
92
|
case 'NumberTypeAnnotation':
|
|
89
93
|
return wrapCxxOptional('double', isRequired);
|
|
90
94
|
case 'FloatTypeAnnotation':
|
|
@@ -163,6 +167,10 @@ function toObjCValue(
|
|
|
163
167
|
}
|
|
164
168
|
case 'StringTypeAnnotation':
|
|
165
169
|
return RCTBridgingTo('String');
|
|
170
|
+
case 'StringLiteralTypeAnnotation':
|
|
171
|
+
return RCTBridgingTo('String');
|
|
172
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
173
|
+
return RCTBridgingTo('String');
|
|
166
174
|
case 'NumberTypeAnnotation':
|
|
167
175
|
return RCTBridgingTo('Double');
|
|
168
176
|
case 'FloatTypeAnnotation':
|
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
const _require = require('../../Utils'),
|
|
12
12
|
toPascalCase = _require.toPascalCase;
|
|
13
13
|
function getEventEmitterTypeObjCType(eventEmitter) {
|
|
14
|
-
|
|
14
|
+
const type = eventEmitter.typeAnnotation.typeAnnotation.type;
|
|
15
|
+
switch (type) {
|
|
15
16
|
case 'StringTypeAnnotation':
|
|
16
17
|
return 'NSString *_Nonnull';
|
|
18
|
+
case 'StringLiteralTypeAnnotation':
|
|
19
|
+
return 'NSString *_Nonnull';
|
|
20
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
21
|
+
return 'NSString *_Nonnull';
|
|
17
22
|
case 'NumberTypeAnnotation':
|
|
18
23
|
return 'NSNumber *_Nonnull';
|
|
19
24
|
case 'BooleanTypeAnnotation':
|
|
@@ -24,7 +29,16 @@ function getEventEmitterTypeObjCType(eventEmitter) {
|
|
|
24
29
|
return 'NSDictionary *';
|
|
25
30
|
case 'ArrayTypeAnnotation':
|
|
26
31
|
return 'NSArray<id<NSObject>> *';
|
|
32
|
+
case 'DoubleTypeAnnotation':
|
|
33
|
+
case 'FloatTypeAnnotation':
|
|
34
|
+
case 'Int32TypeAnnotation':
|
|
35
|
+
case 'VoidTypeAnnotation':
|
|
36
|
+
// TODO: Add support for these types
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
39
|
+
);
|
|
27
40
|
default:
|
|
41
|
+
type;
|
|
28
42
|
throw new Error(
|
|
29
43
|
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
30
44
|
);
|
|
@@ -15,9 +15,15 @@ const {toPascalCase} = require('../../Utils');
|
|
|
15
15
|
function getEventEmitterTypeObjCType(
|
|
16
16
|
eventEmitter: NativeModuleEventEmitterShape,
|
|
17
17
|
): string {
|
|
18
|
-
|
|
18
|
+
const type = eventEmitter.typeAnnotation.typeAnnotation.type;
|
|
19
|
+
|
|
20
|
+
switch (type) {
|
|
19
21
|
case 'StringTypeAnnotation':
|
|
20
22
|
return 'NSString *_Nonnull';
|
|
23
|
+
case 'StringLiteralTypeAnnotation':
|
|
24
|
+
return 'NSString *_Nonnull';
|
|
25
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
26
|
+
return 'NSString *_Nonnull';
|
|
21
27
|
case 'NumberTypeAnnotation':
|
|
22
28
|
return 'NSNumber *_Nonnull';
|
|
23
29
|
case 'BooleanTypeAnnotation':
|
|
@@ -28,7 +34,16 @@ function getEventEmitterTypeObjCType(
|
|
|
28
34
|
return 'NSDictionary *';
|
|
29
35
|
case 'ArrayTypeAnnotation':
|
|
30
36
|
return 'NSArray<id<NSObject>> *';
|
|
37
|
+
case 'DoubleTypeAnnotation':
|
|
38
|
+
case 'FloatTypeAnnotation':
|
|
39
|
+
case 'Int32TypeAnnotation':
|
|
40
|
+
case 'VoidTypeAnnotation':
|
|
41
|
+
// TODO: Add support for these types
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
44
|
+
);
|
|
31
45
|
default:
|
|
46
|
+
(type: empty);
|
|
32
47
|
throw new Error(
|
|
33
48
|
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
|
|
34
49
|
);
|
|
@@ -297,6 +297,10 @@ function getParamObjCType(
|
|
|
297
297
|
}
|
|
298
298
|
case 'StringTypeAnnotation':
|
|
299
299
|
return notStruct(wrapOptional('NSString *', !nullable));
|
|
300
|
+
case 'StringLiteralTypeAnnotation':
|
|
301
|
+
return notStruct(wrapOptional('NSString *', !nullable));
|
|
302
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
303
|
+
return notStruct(wrapOptional('NSString *', !nullable));
|
|
300
304
|
case 'NumberTypeAnnotation':
|
|
301
305
|
return notStruct(isRequired ? 'double' : 'NSNumber *');
|
|
302
306
|
case 'FloatTypeAnnotation':
|
|
@@ -367,6 +371,14 @@ function getReturnObjCType(methodName, nullableTypeAnnotation) {
|
|
|
367
371
|
// TODO: Can NSString * returns not be _Nullable?
|
|
368
372
|
// In the legacy codegen, we don't surround NSSTring * with _Nullable
|
|
369
373
|
return wrapOptional('NSString *', isRequired);
|
|
374
|
+
case 'StringLiteralTypeAnnotation':
|
|
375
|
+
// TODO: Can NSString * returns not be _Nullable?
|
|
376
|
+
// In the legacy codegen, we don't surround NSSTring * with _Nullable
|
|
377
|
+
return wrapOptional('NSString *', isRequired);
|
|
378
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
379
|
+
// TODO: Can NSString * returns not be _Nullable?
|
|
380
|
+
// In the legacy codegen, we don't surround NSSTring * with _Nullable
|
|
381
|
+
return wrapOptional('NSString *', isRequired);
|
|
370
382
|
case 'NumberTypeAnnotation':
|
|
371
383
|
return wrapOptional('NSNumber *', isRequired);
|
|
372
384
|
case 'FloatTypeAnnotation':
|
|
@@ -431,6 +443,10 @@ function getReturnJSType(methodName, nullableTypeAnnotation) {
|
|
|
431
443
|
return 'NumberKind';
|
|
432
444
|
case 'StringTypeAnnotation':
|
|
433
445
|
return 'StringKind';
|
|
446
|
+
case 'StringLiteralTypeAnnotation':
|
|
447
|
+
return 'StringKind';
|
|
448
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
449
|
+
return 'StringKind';
|
|
434
450
|
case 'NumberTypeAnnotation':
|
|
435
451
|
return 'NumberKind';
|
|
436
452
|
case 'FloatTypeAnnotation':
|
|
@@ -257,6 +257,10 @@ function getParamObjCType(
|
|
|
257
257
|
}
|
|
258
258
|
case 'StringTypeAnnotation':
|
|
259
259
|
return notStruct(wrapOptional('NSString *', !nullable));
|
|
260
|
+
case 'StringLiteralTypeAnnotation':
|
|
261
|
+
return notStruct(wrapOptional('NSString *', !nullable));
|
|
262
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
263
|
+
return notStruct(wrapOptional('NSString *', !nullable));
|
|
260
264
|
case 'NumberTypeAnnotation':
|
|
261
265
|
return notStruct(isRequired ? 'double' : 'NSNumber *');
|
|
262
266
|
case 'FloatTypeAnnotation':
|
|
@@ -330,6 +334,14 @@ function getReturnObjCType(
|
|
|
330
334
|
// TODO: Can NSString * returns not be _Nullable?
|
|
331
335
|
// In the legacy codegen, we don't surround NSSTring * with _Nullable
|
|
332
336
|
return wrapOptional('NSString *', isRequired);
|
|
337
|
+
case 'StringLiteralTypeAnnotation':
|
|
338
|
+
// TODO: Can NSString * returns not be _Nullable?
|
|
339
|
+
// In the legacy codegen, we don't surround NSSTring * with _Nullable
|
|
340
|
+
return wrapOptional('NSString *', isRequired);
|
|
341
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
342
|
+
// TODO: Can NSString * returns not be _Nullable?
|
|
343
|
+
// In the legacy codegen, we don't surround NSSTring * with _Nullable
|
|
344
|
+
return wrapOptional('NSString *', isRequired);
|
|
333
345
|
case 'NumberTypeAnnotation':
|
|
334
346
|
return wrapOptional('NSNumber *', isRequired);
|
|
335
347
|
case 'FloatTypeAnnotation':
|
|
@@ -396,6 +408,10 @@ function getReturnJSType(
|
|
|
396
408
|
return 'NumberKind';
|
|
397
409
|
case 'StringTypeAnnotation':
|
|
398
410
|
return 'StringKind';
|
|
411
|
+
case 'StringLiteralTypeAnnotation':
|
|
412
|
+
return 'StringKind';
|
|
413
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
414
|
+
return 'StringKind';
|
|
399
415
|
case 'NumberTypeAnnotation':
|
|
400
416
|
return 'NumberKind';
|
|
401
417
|
case 'FloatTypeAnnotation':
|
|
@@ -2306,6 +2306,23 @@ const CXX_ONLY_NATIVE_MODULES = {
|
|
|
2306
2306
|
memberType: 'StringTypeAnnotation',
|
|
2307
2307
|
},
|
|
2308
2308
|
},
|
|
2309
|
+
{
|
|
2310
|
+
name: 'y-literal',
|
|
2311
|
+
optional: false,
|
|
2312
|
+
typeAnnotation: {
|
|
2313
|
+
type: 'StringLiteralUnionTypeAnnotation',
|
|
2314
|
+
types: [
|
|
2315
|
+
{
|
|
2316
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2317
|
+
value: 'foo',
|
|
2318
|
+
},
|
|
2319
|
+
{
|
|
2320
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2321
|
+
value: 'bar',
|
|
2322
|
+
},
|
|
2323
|
+
],
|
|
2324
|
+
},
|
|
2325
|
+
},
|
|
2309
2326
|
{
|
|
2310
2327
|
name: 'z',
|
|
2311
2328
|
optional: false,
|
|
@@ -2613,6 +2630,71 @@ const UNION_MODULE = {
|
|
|
2613
2630
|
memberType: 'StringTypeAnnotation',
|
|
2614
2631
|
},
|
|
2615
2632
|
},
|
|
2633
|
+
{
|
|
2634
|
+
name: 'chooseStringLiteral',
|
|
2635
|
+
optional: false,
|
|
2636
|
+
typeAnnotation: {
|
|
2637
|
+
type: 'StringLiteralUnionTypeAnnotation',
|
|
2638
|
+
types: [
|
|
2639
|
+
{
|
|
2640
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2641
|
+
value: 'foo',
|
|
2642
|
+
},
|
|
2643
|
+
{
|
|
2644
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2645
|
+
value: 'bar',
|
|
2646
|
+
},
|
|
2647
|
+
],
|
|
2648
|
+
},
|
|
2649
|
+
},
|
|
2650
|
+
],
|
|
2651
|
+
},
|
|
2652
|
+
},
|
|
2653
|
+
],
|
|
2654
|
+
},
|
|
2655
|
+
moduleName: 'SampleTurboModule',
|
|
2656
|
+
},
|
|
2657
|
+
},
|
|
2658
|
+
};
|
|
2659
|
+
const STRING_LITERALS = {
|
|
2660
|
+
modules: {
|
|
2661
|
+
NativeSampleTurboModule: {
|
|
2662
|
+
type: 'NativeModule',
|
|
2663
|
+
aliasMap: {},
|
|
2664
|
+
enumMap: {},
|
|
2665
|
+
spec: {
|
|
2666
|
+
eventEmitters: [
|
|
2667
|
+
{
|
|
2668
|
+
name: 'literalEvent',
|
|
2669
|
+
optional: false,
|
|
2670
|
+
typeAnnotation: {
|
|
2671
|
+
type: 'EventEmitterTypeAnnotation',
|
|
2672
|
+
typeAnnotation: {
|
|
2673
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2674
|
+
value: 'A String Literal Event',
|
|
2675
|
+
},
|
|
2676
|
+
},
|
|
2677
|
+
},
|
|
2678
|
+
],
|
|
2679
|
+
methods: [
|
|
2680
|
+
{
|
|
2681
|
+
name: 'getStringLiteral',
|
|
2682
|
+
optional: false,
|
|
2683
|
+
typeAnnotation: {
|
|
2684
|
+
type: 'FunctionTypeAnnotation',
|
|
2685
|
+
returnTypeAnnotation: {
|
|
2686
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2687
|
+
value: 'A String Literal Return',
|
|
2688
|
+
},
|
|
2689
|
+
params: [
|
|
2690
|
+
{
|
|
2691
|
+
name: 'literalParam',
|
|
2692
|
+
optional: false,
|
|
2693
|
+
typeAnnotation: {
|
|
2694
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2695
|
+
value: 'A String Literal Param',
|
|
2696
|
+
},
|
|
2697
|
+
},
|
|
2616
2698
|
],
|
|
2617
2699
|
},
|
|
2618
2700
|
},
|
|
@@ -2633,4 +2715,5 @@ module.exports = {
|
|
|
2633
2715
|
cxx_only_native_modules: CXX_ONLY_NATIVE_MODULES,
|
|
2634
2716
|
SampleWithUppercaseName: SAMPLE_WITH_UPPERCASE_NAME,
|
|
2635
2717
|
union_module: UNION_MODULE,
|
|
2718
|
+
string_literals: STRING_LITERALS,
|
|
2636
2719
|
};
|
|
@@ -2316,6 +2316,23 @@ const CXX_ONLY_NATIVE_MODULES: SchemaType = {
|
|
|
2316
2316
|
memberType: 'StringTypeAnnotation',
|
|
2317
2317
|
},
|
|
2318
2318
|
},
|
|
2319
|
+
{
|
|
2320
|
+
name: 'y-literal',
|
|
2321
|
+
optional: false,
|
|
2322
|
+
typeAnnotation: {
|
|
2323
|
+
type: 'StringLiteralUnionTypeAnnotation',
|
|
2324
|
+
types: [
|
|
2325
|
+
{
|
|
2326
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2327
|
+
value: 'foo',
|
|
2328
|
+
},
|
|
2329
|
+
{
|
|
2330
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2331
|
+
value: 'bar',
|
|
2332
|
+
},
|
|
2333
|
+
],
|
|
2334
|
+
},
|
|
2335
|
+
},
|
|
2319
2336
|
{
|
|
2320
2337
|
name: 'z',
|
|
2321
2338
|
optional: false,
|
|
@@ -2626,6 +2643,72 @@ const UNION_MODULE: SchemaType = {
|
|
|
2626
2643
|
memberType: 'StringTypeAnnotation',
|
|
2627
2644
|
},
|
|
2628
2645
|
},
|
|
2646
|
+
{
|
|
2647
|
+
name: 'chooseStringLiteral',
|
|
2648
|
+
optional: false,
|
|
2649
|
+
typeAnnotation: {
|
|
2650
|
+
type: 'StringLiteralUnionTypeAnnotation',
|
|
2651
|
+
types: [
|
|
2652
|
+
{
|
|
2653
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2654
|
+
value: 'foo',
|
|
2655
|
+
},
|
|
2656
|
+
{
|
|
2657
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2658
|
+
value: 'bar',
|
|
2659
|
+
},
|
|
2660
|
+
],
|
|
2661
|
+
},
|
|
2662
|
+
},
|
|
2663
|
+
],
|
|
2664
|
+
},
|
|
2665
|
+
},
|
|
2666
|
+
],
|
|
2667
|
+
},
|
|
2668
|
+
moduleName: 'SampleTurboModule',
|
|
2669
|
+
},
|
|
2670
|
+
},
|
|
2671
|
+
};
|
|
2672
|
+
|
|
2673
|
+
const STRING_LITERALS = {
|
|
2674
|
+
modules: {
|
|
2675
|
+
NativeSampleTurboModule: {
|
|
2676
|
+
type: 'NativeModule',
|
|
2677
|
+
aliasMap: {},
|
|
2678
|
+
enumMap: {},
|
|
2679
|
+
spec: {
|
|
2680
|
+
eventEmitters: [
|
|
2681
|
+
{
|
|
2682
|
+
name: 'literalEvent',
|
|
2683
|
+
optional: false,
|
|
2684
|
+
typeAnnotation: {
|
|
2685
|
+
type: 'EventEmitterTypeAnnotation',
|
|
2686
|
+
typeAnnotation: {
|
|
2687
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2688
|
+
value: 'A String Literal Event',
|
|
2689
|
+
},
|
|
2690
|
+
},
|
|
2691
|
+
},
|
|
2692
|
+
],
|
|
2693
|
+
methods: [
|
|
2694
|
+
{
|
|
2695
|
+
name: 'getStringLiteral',
|
|
2696
|
+
optional: false,
|
|
2697
|
+
typeAnnotation: {
|
|
2698
|
+
type: 'FunctionTypeAnnotation',
|
|
2699
|
+
returnTypeAnnotation: {
|
|
2700
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2701
|
+
value: 'A String Literal Return',
|
|
2702
|
+
},
|
|
2703
|
+
params: [
|
|
2704
|
+
{
|
|
2705
|
+
name: 'literalParam',
|
|
2706
|
+
optional: false,
|
|
2707
|
+
typeAnnotation: {
|
|
2708
|
+
type: 'StringLiteralTypeAnnotation',
|
|
2709
|
+
value: 'A String Literal Param',
|
|
2710
|
+
},
|
|
2711
|
+
},
|
|
2629
2712
|
],
|
|
2630
2713
|
},
|
|
2631
2714
|
},
|
|
@@ -2647,4 +2730,5 @@ module.exports = {
|
|
|
2647
2730
|
cxx_only_native_modules: CXX_ONLY_NATIVE_MODULES,
|
|
2648
2731
|
SampleWithUppercaseName: SAMPLE_WITH_UPPERCASE_NAME,
|
|
2649
2732
|
union_module: UNION_MODULE,
|
|
2733
|
+
string_literals: STRING_LITERALS,
|
|
2650
2734
|
};
|
|
@@ -125,6 +125,7 @@ export interface Spec extends TurboModule {
|
|
|
125
125
|
+passNumber: (arg: number) => void;
|
|
126
126
|
+passString: (arg: string) => void;
|
|
127
127
|
+passStringish: (arg: Stringish) => void;
|
|
128
|
+
+passStringLiteral: (arg: 'A String Literal') => void;
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
|
@@ -128,6 +128,7 @@ export interface Spec extends TurboModule {
|
|
|
128
128
|
+passNumber: (arg: number) => void;
|
|
129
129
|
+passString: (arg: string) => void;
|
|
130
130
|
+passStringish: (arg: Stringish) => void;
|
|
131
|
+
+passStringLiteral: (arg: 'A String Literal') => void;
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
|
@@ -301,10 +301,9 @@ function translateTypeAnnotation(
|
|
|
301
301
|
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
|
|
302
302
|
}
|
|
303
303
|
case 'StringLiteralTypeAnnotation': {
|
|
304
|
-
// 'a' is a special case for 'a' | 'b' but the type name is different
|
|
305
304
|
return wrapNullable(nullable, {
|
|
306
|
-
type: '
|
|
307
|
-
|
|
305
|
+
type: 'StringLiteralTypeAnnotation',
|
|
306
|
+
value: typeAnnotation.value,
|
|
308
307
|
});
|
|
309
308
|
}
|
|
310
309
|
case 'EnumStringBody':
|
|
@@ -244,10 +244,9 @@ function translateTypeAnnotation(
|
|
|
244
244
|
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
|
|
245
245
|
}
|
|
246
246
|
case 'StringLiteralTypeAnnotation': {
|
|
247
|
-
// 'a' is a special case for 'a' | 'b' but the type name is different
|
|
248
247
|
return wrapNullable(nullable, {
|
|
249
|
-
type: '
|
|
250
|
-
|
|
248
|
+
type: 'StringLiteralTypeAnnotation',
|
|
249
|
+
value: typeAnnotation.value,
|
|
251
250
|
});
|
|
252
251
|
}
|
|
253
252
|
case 'EnumStringBody':
|
|
@@ -124,6 +124,9 @@ class FlowParser {
|
|
|
124
124
|
};
|
|
125
125
|
return [...new Set(membersTypes.map(remapLiteral))];
|
|
126
126
|
}
|
|
127
|
+
getStringLiteralUnionTypeAnnotationStringLiterals(membersTypes) {
|
|
128
|
+
return membersTypes.map(item => item.value);
|
|
129
|
+
}
|
|
127
130
|
parseFile(filename) {
|
|
128
131
|
const contents = fs.readFileSync(filename, 'utf8');
|
|
129
132
|
return this.parseString(contents, filename);
|
|
@@ -117,6 +117,12 @@ class FlowParser implements Parser {
|
|
|
117
117
|
return [...new Set(membersTypes.map(remapLiteral))];
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
getStringLiteralUnionTypeAnnotationStringLiterals(
|
|
121
|
+
membersTypes: $FlowFixMe[],
|
|
122
|
+
): string[] {
|
|
123
|
+
return membersTypes.map((item: $FlowFixMe) => item.value);
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
parseFile(filename: string): SchemaType {
|
|
121
127
|
const contents = fs.readFileSync(filename, 'utf8');
|
|
122
128
|
|
|
@@ -146,6 +146,14 @@ export interface Parser {
|
|
|
146
146
|
remapUnionTypeAnnotationMemberNames(
|
|
147
147
|
types: $FlowFixMe,
|
|
148
148
|
): UnionTypeAnnotationMemberType[];
|
|
149
|
+
/**
|
|
150
|
+
* Given a union annotation members types, it returns an array of string literals.
|
|
151
|
+
* @parameter membersTypes: union annotation members types
|
|
152
|
+
* @returns: an array of string literals.
|
|
153
|
+
*/
|
|
154
|
+
getStringLiteralUnionTypeAnnotationStringLiterals(
|
|
155
|
+
types: $FlowFixMe,
|
|
156
|
+
): string[];
|
|
149
157
|
/**
|
|
150
158
|
* Given the name of a file, it returns a Schema.
|
|
151
159
|
* @parameter filename: the name of the file.
|
|
@@ -115,6 +115,9 @@ export class MockedParser {
|
|
|
115
115
|
remapUnionTypeAnnotationMemberNames(membersTypes) {
|
|
116
116
|
return [];
|
|
117
117
|
}
|
|
118
|
+
getStringLiteralUnionTypeAnnotationStringLiterals(membersTypes) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
118
121
|
parseFile(filename) {
|
|
119
122
|
return schemaMock;
|
|
120
123
|
}
|
|
@@ -109,6 +109,12 @@ export class MockedParser implements Parser {
|
|
|
109
109
|
return [];
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
getStringLiteralUnionTypeAnnotationStringLiterals(
|
|
113
|
+
membersTypes: $FlowFixMe[],
|
|
114
|
+
): string[] {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
|
|
112
118
|
parseFile(filename: string): SchemaType {
|
|
113
119
|
return schemaMock;
|
|
114
120
|
}
|
|
@@ -193,6 +193,12 @@ function emitString(nullable) {
|
|
|
193
193
|
type: 'StringTypeAnnotation',
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
|
+
function emitStringLiteral(nullable, value) {
|
|
197
|
+
return wrapNullable(nullable, {
|
|
198
|
+
type: 'StringLiteralTypeAnnotation',
|
|
199
|
+
value,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
196
202
|
function emitStringProp(name, optional) {
|
|
197
203
|
return {
|
|
198
204
|
name,
|
|
@@ -379,6 +385,11 @@ function emitFloatProp(name, optional) {
|
|
|
379
385
|
};
|
|
380
386
|
}
|
|
381
387
|
function emitUnion(nullable, hasteModuleName, typeAnnotation, parser) {
|
|
388
|
+
// Get all the literals by type
|
|
389
|
+
// Verify they are all the same
|
|
390
|
+
// If string, persist as StringLiteralUnionType
|
|
391
|
+
// If number, persist as NumberTypeAnnotation (TODO: Number literal)
|
|
392
|
+
|
|
382
393
|
const unionTypes = parser.remapUnionTypeAnnotationMemberNames(
|
|
383
394
|
typeAnnotation.types,
|
|
384
395
|
);
|
|
@@ -391,11 +402,38 @@ function emitUnion(nullable, hasteModuleName, typeAnnotation, parser) {
|
|
|
391
402
|
unionTypes,
|
|
392
403
|
);
|
|
393
404
|
}
|
|
405
|
+
if (unionTypes[0] === 'StringTypeAnnotation') {
|
|
406
|
+
// Reprocess as a string literal union
|
|
407
|
+
return emitStringLiteralUnion(
|
|
408
|
+
nullable,
|
|
409
|
+
hasteModuleName,
|
|
410
|
+
typeAnnotation,
|
|
411
|
+
parser,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
394
414
|
return wrapNullable(nullable, {
|
|
395
415
|
type: 'UnionTypeAnnotation',
|
|
396
416
|
memberType: unionTypes[0],
|
|
397
417
|
});
|
|
398
418
|
}
|
|
419
|
+
function emitStringLiteralUnion(
|
|
420
|
+
nullable,
|
|
421
|
+
hasteModuleName,
|
|
422
|
+
typeAnnotation,
|
|
423
|
+
parser,
|
|
424
|
+
) {
|
|
425
|
+
const stringLiterals =
|
|
426
|
+
parser.getStringLiteralUnionTypeAnnotationStringLiterals(
|
|
427
|
+
typeAnnotation.types,
|
|
428
|
+
);
|
|
429
|
+
return wrapNullable(nullable, {
|
|
430
|
+
type: 'StringLiteralUnionTypeAnnotation',
|
|
431
|
+
types: stringLiterals.map(stringLiteral => ({
|
|
432
|
+
type: 'StringLiteralTypeAnnotation',
|
|
433
|
+
value: stringLiteral,
|
|
434
|
+
})),
|
|
435
|
+
});
|
|
436
|
+
}
|
|
399
437
|
function translateArrayTypeAnnotation(
|
|
400
438
|
hasteModuleName,
|
|
401
439
|
types,
|
|
@@ -666,6 +704,7 @@ module.exports = {
|
|
|
666
704
|
emitString,
|
|
667
705
|
emitStringish,
|
|
668
706
|
emitStringProp,
|
|
707
|
+
emitStringLiteral,
|
|
669
708
|
emitMixed,
|
|
670
709
|
emitUnion,
|
|
671
710
|
emitPartial,
|
|
@@ -34,6 +34,8 @@ import type {
|
|
|
34
34
|
ObjectTypeAnnotation,
|
|
35
35
|
ReservedTypeAnnotation,
|
|
36
36
|
StringTypeAnnotation,
|
|
37
|
+
StringLiteralTypeAnnotation,
|
|
38
|
+
StringLiteralUnionTypeAnnotation,
|
|
37
39
|
VoidTypeAnnotation,
|
|
38
40
|
} from '../CodegenSchema';
|
|
39
41
|
import type {Parser} from './parser';
|
|
@@ -174,6 +176,16 @@ function emitString(nullable: boolean): Nullable<StringTypeAnnotation> {
|
|
|
174
176
|
});
|
|
175
177
|
}
|
|
176
178
|
|
|
179
|
+
function emitStringLiteral(
|
|
180
|
+
nullable: boolean,
|
|
181
|
+
value: string,
|
|
182
|
+
): Nullable<StringLiteralTypeAnnotation> {
|
|
183
|
+
return wrapNullable(nullable, {
|
|
184
|
+
type: 'StringLiteralTypeAnnotation',
|
|
185
|
+
value,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
177
189
|
function emitStringProp(
|
|
178
190
|
name: string,
|
|
179
191
|
optional: boolean,
|
|
@@ -398,7 +410,14 @@ function emitUnion(
|
|
|
398
410
|
hasteModuleName: string,
|
|
399
411
|
typeAnnotation: $FlowFixMe,
|
|
400
412
|
parser: Parser,
|
|
401
|
-
): Nullable<
|
|
413
|
+
): Nullable<
|
|
414
|
+
NativeModuleUnionTypeAnnotation | StringLiteralUnionTypeAnnotation,
|
|
415
|
+
> {
|
|
416
|
+
// Get all the literals by type
|
|
417
|
+
// Verify they are all the same
|
|
418
|
+
// If string, persist as StringLiteralUnionType
|
|
419
|
+
// If number, persist as NumberTypeAnnotation (TODO: Number literal)
|
|
420
|
+
|
|
402
421
|
const unionTypes = parser.remapUnionTypeAnnotationMemberNames(
|
|
403
422
|
typeAnnotation.types,
|
|
404
423
|
);
|
|
@@ -412,12 +431,42 @@ function emitUnion(
|
|
|
412
431
|
);
|
|
413
432
|
}
|
|
414
433
|
|
|
434
|
+
if (unionTypes[0] === 'StringTypeAnnotation') {
|
|
435
|
+
// Reprocess as a string literal union
|
|
436
|
+
return emitStringLiteralUnion(
|
|
437
|
+
nullable,
|
|
438
|
+
hasteModuleName,
|
|
439
|
+
typeAnnotation,
|
|
440
|
+
parser,
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
415
444
|
return wrapNullable(nullable, {
|
|
416
445
|
type: 'UnionTypeAnnotation',
|
|
417
446
|
memberType: unionTypes[0],
|
|
418
447
|
});
|
|
419
448
|
}
|
|
420
449
|
|
|
450
|
+
function emitStringLiteralUnion(
|
|
451
|
+
nullable: boolean,
|
|
452
|
+
hasteModuleName: string,
|
|
453
|
+
typeAnnotation: $FlowFixMe,
|
|
454
|
+
parser: Parser,
|
|
455
|
+
): Nullable<StringLiteralUnionTypeAnnotation> {
|
|
456
|
+
const stringLiterals =
|
|
457
|
+
parser.getStringLiteralUnionTypeAnnotationStringLiterals(
|
|
458
|
+
typeAnnotation.types,
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
return wrapNullable(nullable, {
|
|
462
|
+
type: 'StringLiteralUnionTypeAnnotation',
|
|
463
|
+
types: stringLiterals.map(stringLiteral => ({
|
|
464
|
+
type: 'StringLiteralTypeAnnotation',
|
|
465
|
+
value: stringLiteral,
|
|
466
|
+
})),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
421
470
|
function translateArrayTypeAnnotation(
|
|
422
471
|
hasteModuleName: string,
|
|
423
472
|
types: TypeDeclarationMap,
|
|
@@ -722,6 +771,7 @@ module.exports = {
|
|
|
722
771
|
emitString,
|
|
723
772
|
emitStringish,
|
|
724
773
|
emitStringProp,
|
|
774
|
+
emitStringLiteral,
|
|
725
775
|
emitMixed,
|
|
726
776
|
emitUnion,
|
|
727
777
|
emitPartial,
|
|
@@ -112,6 +112,7 @@ export interface Spec extends TurboModule {
|
|
|
112
112
|
readonly passNumber: (arg: number) => void;
|
|
113
113
|
readonly passString: (arg: string) => void;
|
|
114
114
|
readonly passStringish: (arg: Stringish) => void;
|
|
115
|
+
readonly passStringLiteral: (arg: 'A String Literal') => void;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
|
@@ -115,6 +115,7 @@ export interface Spec extends TurboModule {
|
|
|
115
115
|
readonly passNumber: (arg: number) => void;
|
|
116
116
|
readonly passString: (arg: string) => void;
|
|
117
117
|
readonly passStringish: (arg: Stringish) => void;
|
|
118
|
+
readonly passStringLiteral: (arg: 'A String Literal') => void;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
|
@@ -28,6 +28,7 @@ const _require3 = require('../../parsers-primitives'),
|
|
|
28
28
|
emitPromise = _require3.emitPromise,
|
|
29
29
|
emitRootTag = _require3.emitRootTag,
|
|
30
30
|
emitUnion = _require3.emitUnion,
|
|
31
|
+
emitStringLiteral = _require3.emitStringLiteral,
|
|
31
32
|
translateArrayTypeAnnotation = _require3.translateArrayTypeAnnotation,
|
|
32
33
|
typeAliasResolution = _require3.typeAliasResolution,
|
|
33
34
|
typeEnumResolution = _require3.typeEnumResolution;
|
|
@@ -387,6 +388,21 @@ function translateTypeAnnotation(
|
|
|
387
388
|
case 'TSUnionType': {
|
|
388
389
|
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
|
|
389
390
|
}
|
|
391
|
+
case 'TSLiteralType': {
|
|
392
|
+
const literal = typeAnnotation.literal;
|
|
393
|
+
switch (literal.type) {
|
|
394
|
+
case 'StringLiteral': {
|
|
395
|
+
return emitStringLiteral(nullable, literal.value);
|
|
396
|
+
}
|
|
397
|
+
default: {
|
|
398
|
+
throw new UnsupportedTypeAnnotationParserError(
|
|
399
|
+
hasteModuleName,
|
|
400
|
+
typeAnnotation,
|
|
401
|
+
parser.language(),
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
390
406
|
default: {
|
|
391
407
|
const commonType = emitCommonTypes(
|
|
392
408
|
hasteModuleName,
|
|
@@ -40,6 +40,7 @@ const {
|
|
|
40
40
|
emitPromise,
|
|
41
41
|
emitRootTag,
|
|
42
42
|
emitUnion,
|
|
43
|
+
emitStringLiteral,
|
|
43
44
|
translateArrayTypeAnnotation,
|
|
44
45
|
typeAliasResolution,
|
|
45
46
|
typeEnumResolution,
|
|
@@ -396,6 +397,21 @@ function translateTypeAnnotation(
|
|
|
396
397
|
case 'TSUnionType': {
|
|
397
398
|
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
|
|
398
399
|
}
|
|
400
|
+
case 'TSLiteralType': {
|
|
401
|
+
const literal = typeAnnotation.literal;
|
|
402
|
+
switch (literal.type) {
|
|
403
|
+
case 'StringLiteral': {
|
|
404
|
+
return emitStringLiteral(nullable, literal.value);
|
|
405
|
+
}
|
|
406
|
+
default: {
|
|
407
|
+
throw new UnsupportedTypeAnnotationParserError(
|
|
408
|
+
hasteModuleName,
|
|
409
|
+
typeAnnotation,
|
|
410
|
+
parser.language(),
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
399
415
|
default: {
|
|
400
416
|
const commonType = emitCommonTypes(
|
|
401
417
|
hasteModuleName,
|
|
@@ -126,6 +126,9 @@ class TypeScriptParser {
|
|
|
126
126
|
};
|
|
127
127
|
return [...new Set(membersTypes.map(remapLiteral))];
|
|
128
128
|
}
|
|
129
|
+
getStringLiteralUnionTypeAnnotationStringLiterals(membersTypes) {
|
|
130
|
+
return membersTypes.map(item => item.literal.value);
|
|
131
|
+
}
|
|
129
132
|
parseFile(filename) {
|
|
130
133
|
const contents = fs.readFileSync(filename, 'utf8');
|
|
131
134
|
return this.parseString(contents, filename);
|
|
@@ -117,6 +117,12 @@ class TypeScriptParser implements Parser {
|
|
|
117
117
|
return [...new Set(membersTypes.map(remapLiteral))];
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
getStringLiteralUnionTypeAnnotationStringLiterals(
|
|
121
|
+
membersTypes: $FlowFixMe[],
|
|
122
|
+
): string[] {
|
|
123
|
+
return membersTypes.map((item: $FlowFixMe) => item.literal.value);
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
parseFile(filename: string): SchemaType {
|
|
121
127
|
const contents = fs.readFileSync(filename, 'utf8');
|
|
122
128
|
|