@react-native/codegen 0.77.0-nightly-20240930-513e9669e → 0.77.0-nightly-20241002-d19a2178b
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 +1 -1
- package/lib/CodegenSchema.js.flow +1 -1
- package/lib/generators/__test_fixtures__/fixtures.js +3 -0
- package/lib/generators/__test_fixtures__/fixtures.js.flow +3 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js +15 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +15 -0
- package/lib/parsers/errors.js +8 -0
- package/lib/parsers/errors.js.flow +10 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js +28 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +29 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +2 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +2 -0
- package/lib/parsers/flow/modules/index.js +8 -0
- package/lib/parsers/flow/modules/index.js.flow +9 -0
- package/lib/parsers/parsers-primitives.js +6 -0
- package/lib/parsers/parsers-primitives.js.flow +6 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +25 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +26 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +2 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +2 -0
- package/lib/parsers/typescript/modules/index.js +11 -0
- package/lib/parsers/typescript/modules/index.js.flow +13 -0
- package/package.json +2 -2
package/lib/CodegenSchema.d.ts
CHANGED
|
@@ -347,7 +347,7 @@ export interface NativeModuleTypeAliasTypeAnnotation {
|
|
|
347
347
|
|
|
348
348
|
export interface NativeModulePromiseTypeAnnotation {
|
|
349
349
|
readonly type: 'PromiseTypeAnnotation';
|
|
350
|
-
readonly elementType
|
|
350
|
+
readonly elementType: Nullable<NativeModuleBaseTypeAnnotation> | VoidTypeAnnotation;
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
export type UnionTypeAnnotationMemberType =
|
|
@@ -333,7 +333,7 @@ export type NativeModuleTypeAliasTypeAnnotation = $ReadOnly<{
|
|
|
333
333
|
|
|
334
334
|
export type NativeModulePromiseTypeAnnotation = $ReadOnly<{
|
|
335
335
|
type: 'PromiseTypeAnnotation',
|
|
336
|
-
elementType
|
|
336
|
+
elementType: VoidTypeAnnotation | Nullable<NativeModuleBaseTypeAnnotation>,
|
|
337
337
|
}>;
|
|
338
338
|
|
|
339
339
|
export type UnionTypeAnnotationMemberType =
|
|
@@ -448,6 +448,9 @@ const SIMPLE_NATIVE_MODULES = {
|
|
|
448
448
|
type: 'FunctionTypeAnnotation',
|
|
449
449
|
returnTypeAnnotation: {
|
|
450
450
|
type: 'PromiseTypeAnnotation',
|
|
451
|
+
elementType: {
|
|
452
|
+
type: 'VoidTypeAnnotation',
|
|
453
|
+
},
|
|
451
454
|
},
|
|
452
455
|
params: [
|
|
453
456
|
{
|
|
@@ -467,6 +470,9 @@ const SIMPLE_NATIVE_MODULES = {
|
|
|
467
470
|
type: 'FunctionTypeAnnotation',
|
|
468
471
|
returnTypeAnnotation: {
|
|
469
472
|
type: 'PromiseTypeAnnotation',
|
|
473
|
+
elementType: {
|
|
474
|
+
type: 'VoidTypeAnnotation',
|
|
475
|
+
},
|
|
470
476
|
},
|
|
471
477
|
params: [
|
|
472
478
|
{
|
|
@@ -1356,6 +1362,9 @@ const REAL_MODULE_EXAMPLE = {
|
|
|
1356
1362
|
type: 'FunctionTypeAnnotation',
|
|
1357
1363
|
returnTypeAnnotation: {
|
|
1358
1364
|
type: 'PromiseTypeAnnotation',
|
|
1365
|
+
elementType: {
|
|
1366
|
+
type: 'VoidTypeAnnotation',
|
|
1367
|
+
},
|
|
1359
1368
|
},
|
|
1360
1369
|
params: [
|
|
1361
1370
|
{
|
|
@@ -1376,6 +1385,9 @@ const REAL_MODULE_EXAMPLE = {
|
|
|
1376
1385
|
type: 'FunctionTypeAnnotation',
|
|
1377
1386
|
returnTypeAnnotation: {
|
|
1378
1387
|
type: 'PromiseTypeAnnotation',
|
|
1388
|
+
elementType: {
|
|
1389
|
+
type: 'VoidTypeAnnotation',
|
|
1390
|
+
},
|
|
1379
1391
|
},
|
|
1380
1392
|
params: [
|
|
1381
1393
|
{
|
|
@@ -1402,6 +1414,9 @@ const REAL_MODULE_EXAMPLE = {
|
|
|
1402
1414
|
type: 'FunctionTypeAnnotation',
|
|
1403
1415
|
returnTypeAnnotation: {
|
|
1404
1416
|
type: 'PromiseTypeAnnotation',
|
|
1417
|
+
elementType: {
|
|
1418
|
+
type: 'VoidTypeAnnotation',
|
|
1419
|
+
},
|
|
1405
1420
|
},
|
|
1406
1421
|
params: [
|
|
1407
1422
|
{
|
|
@@ -453,6 +453,9 @@ const SIMPLE_NATIVE_MODULES: SchemaType = {
|
|
|
453
453
|
type: 'FunctionTypeAnnotation',
|
|
454
454
|
returnTypeAnnotation: {
|
|
455
455
|
type: 'PromiseTypeAnnotation',
|
|
456
|
+
elementType: {
|
|
457
|
+
type: 'VoidTypeAnnotation',
|
|
458
|
+
},
|
|
456
459
|
},
|
|
457
460
|
params: [
|
|
458
461
|
{
|
|
@@ -472,6 +475,9 @@ const SIMPLE_NATIVE_MODULES: SchemaType = {
|
|
|
472
475
|
type: 'FunctionTypeAnnotation',
|
|
473
476
|
returnTypeAnnotation: {
|
|
474
477
|
type: 'PromiseTypeAnnotation',
|
|
478
|
+
elementType: {
|
|
479
|
+
type: 'VoidTypeAnnotation',
|
|
480
|
+
},
|
|
475
481
|
},
|
|
476
482
|
params: [
|
|
477
483
|
{
|
|
@@ -1365,6 +1371,9 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
|
|
|
1365
1371
|
type: 'FunctionTypeAnnotation',
|
|
1366
1372
|
returnTypeAnnotation: {
|
|
1367
1373
|
type: 'PromiseTypeAnnotation',
|
|
1374
|
+
elementType: {
|
|
1375
|
+
type: 'VoidTypeAnnotation',
|
|
1376
|
+
},
|
|
1368
1377
|
},
|
|
1369
1378
|
params: [
|
|
1370
1379
|
{
|
|
@@ -1385,6 +1394,9 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
|
|
|
1385
1394
|
type: 'FunctionTypeAnnotation',
|
|
1386
1395
|
returnTypeAnnotation: {
|
|
1387
1396
|
type: 'PromiseTypeAnnotation',
|
|
1397
|
+
elementType: {
|
|
1398
|
+
type: 'VoidTypeAnnotation',
|
|
1399
|
+
},
|
|
1388
1400
|
},
|
|
1389
1401
|
params: [
|
|
1390
1402
|
{
|
|
@@ -1411,6 +1423,9 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
|
|
|
1411
1423
|
type: 'FunctionTypeAnnotation',
|
|
1412
1424
|
returnTypeAnnotation: {
|
|
1413
1425
|
type: 'PromiseTypeAnnotation',
|
|
1426
|
+
elementType: {
|
|
1427
|
+
type: 'VoidTypeAnnotation',
|
|
1428
|
+
},
|
|
1414
1429
|
},
|
|
1415
1430
|
params: [
|
|
1416
1431
|
{
|
package/lib/parsers/errors.js
CHANGED
|
@@ -183,6 +183,13 @@ class UnsupportedObjectPropertyTypeAnnotationParserError extends ParserError {
|
|
|
183
183
|
super(nativeModuleName, propertyAST, message);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
+
class UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError extends ParserError {
|
|
187
|
+
constructor(nativeModuleName, propertyAST) {
|
|
188
|
+
let message =
|
|
189
|
+
"'ObjectTypeAnnotation' cannot contain both an indexer and properties.";
|
|
190
|
+
super(nativeModuleName, propertyAST, message);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
186
193
|
class UnsupportedObjectPropertyValueTypeAnnotationParserError extends ParserError {
|
|
187
194
|
constructor(
|
|
188
195
|
nativeModuleName,
|
|
@@ -357,6 +364,7 @@ module.exports = {
|
|
|
357
364
|
UnsupportedModuleEventEmitterPropertyParserError,
|
|
358
365
|
UnsupportedModulePropertyParserError,
|
|
359
366
|
UnsupportedObjectPropertyTypeAnnotationParserError,
|
|
367
|
+
UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError,
|
|
360
368
|
UnsupportedObjectPropertyValueTypeAnnotationParserError,
|
|
361
369
|
UnsupportedObjectDirectRecursivePropertyParserError,
|
|
362
370
|
UnusedModuleInterfaceParserError,
|
|
@@ -237,6 +237,15 @@ class UnsupportedObjectPropertyTypeAnnotationParserError extends ParserError {
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
+
class UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError extends ParserError {
|
|
241
|
+
constructor(nativeModuleName: string, propertyAST: $FlowFixMe) {
|
|
242
|
+
let message =
|
|
243
|
+
"'ObjectTypeAnnotation' cannot contain both an indexer and properties.";
|
|
244
|
+
|
|
245
|
+
super(nativeModuleName, propertyAST, message);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
240
249
|
class UnsupportedObjectPropertyValueTypeAnnotationParserError extends ParserError {
|
|
241
250
|
constructor(
|
|
242
251
|
nativeModuleName: string,
|
|
@@ -455,6 +464,7 @@ module.exports = {
|
|
|
455
464
|
UnsupportedModuleEventEmitterPropertyParserError,
|
|
456
465
|
UnsupportedModulePropertyParserError,
|
|
457
466
|
UnsupportedObjectPropertyTypeAnnotationParserError,
|
|
467
|
+
UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError,
|
|
458
468
|
UnsupportedObjectPropertyValueTypeAnnotationParserError,
|
|
459
469
|
UnsupportedObjectDirectRecursivePropertyParserError,
|
|
460
470
|
UnusedModuleInterfaceParserError,
|
|
@@ -253,6 +253,33 @@ export interface Spec extends TurboModule {
|
|
|
253
253
|
+getEnums: (a: SomeEnum) => string;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('MixedValuesEnumNativeModule');
|
|
257
|
+
`;
|
|
258
|
+
const MAP_WITH_EXTRA_KEYS_NATIVE_MODULE = `
|
|
259
|
+
/**
|
|
260
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
261
|
+
*
|
|
262
|
+
* This source code is licensed under the MIT license found in the
|
|
263
|
+
* LICENSE file in the root directory of this source tree.
|
|
264
|
+
*
|
|
265
|
+
* @flow strict-local
|
|
266
|
+
* @format
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
'use strict';
|
|
270
|
+
|
|
271
|
+
import type {TurboModule} from '../RCTExport';
|
|
272
|
+
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
|
273
|
+
|
|
274
|
+
type MapWithKey = {
|
|
275
|
+
[a: string]: ?string,
|
|
276
|
+
extra: string,
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface Spec extends TurboModule {
|
|
280
|
+
+getMap: (a: MapWithKey) => string;
|
|
281
|
+
}
|
|
282
|
+
|
|
256
283
|
export default TurboModuleRegistry.getEnforcing<Spec>('MixedValuesEnumNativeModule');
|
|
257
284
|
`;
|
|
258
285
|
module.exports = {
|
|
@@ -266,4 +293,5 @@ module.exports = {
|
|
|
266
293
|
TWO_NATIVE_EXTENDING_TURBO_MODULE,
|
|
267
294
|
EMPTY_ENUM_NATIVE_MODULE,
|
|
268
295
|
MIXED_VALUES_ENUM_NATIVE_MODULE,
|
|
296
|
+
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
|
|
269
297
|
};
|
|
@@ -265,6 +265,34 @@ export interface Spec extends TurboModule {
|
|
|
265
265
|
export default TurboModuleRegistry.getEnforcing<Spec>('MixedValuesEnumNativeModule');
|
|
266
266
|
`;
|
|
267
267
|
|
|
268
|
+
const MAP_WITH_EXTRA_KEYS_NATIVE_MODULE = `
|
|
269
|
+
/**
|
|
270
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
271
|
+
*
|
|
272
|
+
* This source code is licensed under the MIT license found in the
|
|
273
|
+
* LICENSE file in the root directory of this source tree.
|
|
274
|
+
*
|
|
275
|
+
* @flow strict-local
|
|
276
|
+
* @format
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
'use strict';
|
|
280
|
+
|
|
281
|
+
import type {TurboModule} from '../RCTExport';
|
|
282
|
+
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
|
283
|
+
|
|
284
|
+
type MapWithKey = {
|
|
285
|
+
[a: string]: ?string,
|
|
286
|
+
extra: string,
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export interface Spec extends TurboModule {
|
|
290
|
+
+getMap: (a: MapWithKey) => string;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('MixedValuesEnumNativeModule');
|
|
294
|
+
`;
|
|
295
|
+
|
|
268
296
|
module.exports = {
|
|
269
297
|
NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT,
|
|
270
298
|
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
|
|
@@ -276,4 +304,5 @@ module.exports = {
|
|
|
276
304
|
TWO_NATIVE_EXTENDING_TURBO_MODULE,
|
|
277
305
|
EMPTY_ENUM_NATIVE_MODULE,
|
|
278
306
|
MIXED_VALUES_ENUM_NATIVE_MODULE,
|
|
307
|
+
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
|
|
279
308
|
};
|
|
@@ -158,6 +158,7 @@ export type ObjectAlias = {|
|
|
|
158
158
|
label: string,
|
|
159
159
|
truthy: boolean,
|
|
160
160
|
|};
|
|
161
|
+
export type PureObjectAlias = ObjectAlias;
|
|
161
162
|
export type ReadOnlyAlias = $ReadOnly<ObjectAlias>;
|
|
162
163
|
|
|
163
164
|
export interface Spec extends TurboModule {
|
|
@@ -167,6 +168,7 @@ export interface Spec extends TurboModule {
|
|
|
167
168
|
+getArray: (a: Array<A>) => {| a: B |};
|
|
168
169
|
+getStringFromAlias: (a: ObjectAlias) => string;
|
|
169
170
|
+getStringFromNullableAlias: (a: ?ObjectAlias) => string;
|
|
171
|
+
+getStringFromPureAlias: (a: PureObjectAlias) => string;
|
|
170
172
|
+getStringFromReadOnlyAlias: (a: ReadOnlyAlias) => string;
|
|
171
173
|
+getStringFromNullableReadOnlyAlias: (a: ?ReadOnlyAlias) => string;
|
|
172
174
|
}
|
|
@@ -162,6 +162,7 @@ export type ObjectAlias = {|
|
|
|
162
162
|
label: string,
|
|
163
163
|
truthy: boolean,
|
|
164
164
|
|};
|
|
165
|
+
export type PureObjectAlias = ObjectAlias;
|
|
165
166
|
export type ReadOnlyAlias = $ReadOnly<ObjectAlias>;
|
|
166
167
|
|
|
167
168
|
export interface Spec extends TurboModule {
|
|
@@ -171,6 +172,7 @@ export interface Spec extends TurboModule {
|
|
|
171
172
|
+getArray: (a: Array<A>) => {| a: B |};
|
|
172
173
|
+getStringFromAlias: (a: ObjectAlias) => string;
|
|
173
174
|
+getStringFromNullableAlias: (a: ?ObjectAlias) => string;
|
|
175
|
+
+getStringFromPureAlias: (a: PureObjectAlias) => string;
|
|
174
176
|
+getStringFromReadOnlyAlias: (a: ReadOnlyAlias) => string;
|
|
175
177
|
+getStringFromNullableReadOnlyAlias: (a: ?ReadOnlyAlias) => string;
|
|
176
178
|
}
|
|
@@ -86,6 +86,8 @@ const _require = require('../../errors'),
|
|
|
86
86
|
UnsupportedEnumDeclarationParserError =
|
|
87
87
|
_require.UnsupportedEnumDeclarationParserError,
|
|
88
88
|
UnsupportedGenericParserError = _require.UnsupportedGenericParserError,
|
|
89
|
+
UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError =
|
|
90
|
+
_require.UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError,
|
|
89
91
|
UnsupportedTypeAnnotationParserError =
|
|
90
92
|
_require.UnsupportedTypeAnnotationParserError;
|
|
91
93
|
const _require2 = require('../../parsers-commons'),
|
|
@@ -227,6 +229,12 @@ function translateTypeAnnotation(
|
|
|
227
229
|
const indexers = typeAnnotation.indexers.filter(
|
|
228
230
|
member => member.type === 'ObjectTypeIndexer',
|
|
229
231
|
);
|
|
232
|
+
if (indexers.length > 0 && typeAnnotation.properties.length > 0) {
|
|
233
|
+
throw new UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError(
|
|
234
|
+
hasteModuleName,
|
|
235
|
+
typeAnnotation,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
230
238
|
if (indexers.length > 0) {
|
|
231
239
|
// check the property type to prevent developers from using unsupported types
|
|
232
240
|
// the return value from `translateTypeAnnotation` is unused
|
|
@@ -24,6 +24,7 @@ import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
|
|
|
24
24
|
const {
|
|
25
25
|
UnsupportedEnumDeclarationParserError,
|
|
26
26
|
UnsupportedGenericParserError,
|
|
27
|
+
UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError,
|
|
27
28
|
UnsupportedTypeAnnotationParserError,
|
|
28
29
|
} = require('../../errors');
|
|
29
30
|
const {
|
|
@@ -162,6 +163,14 @@ function translateTypeAnnotation(
|
|
|
162
163
|
const indexers = typeAnnotation.indexers.filter(
|
|
163
164
|
member => member.type === 'ObjectTypeIndexer',
|
|
164
165
|
);
|
|
166
|
+
|
|
167
|
+
if (indexers.length > 0 && typeAnnotation.properties.length > 0) {
|
|
168
|
+
throw new UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError(
|
|
169
|
+
hasteModuleName,
|
|
170
|
+
typeAnnotation,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
165
174
|
if (indexers.length > 0) {
|
|
166
175
|
// check the property type to prevent developers from using unsupported types
|
|
167
176
|
// the return value from `translateTypeAnnotation` is unused
|
|
@@ -318,6 +318,9 @@ function emitPromise(
|
|
|
318
318
|
) {
|
|
319
319
|
return wrapNullable(nullable, {
|
|
320
320
|
type: 'PromiseTypeAnnotation',
|
|
321
|
+
elementType: {
|
|
322
|
+
type: 'VoidTypeAnnotation',
|
|
323
|
+
},
|
|
321
324
|
});
|
|
322
325
|
} else {
|
|
323
326
|
try {
|
|
@@ -337,6 +340,9 @@ function emitPromise(
|
|
|
337
340
|
} catch {
|
|
338
341
|
return wrapNullable(nullable, {
|
|
339
342
|
type: 'PromiseTypeAnnotation',
|
|
343
|
+
elementType: {
|
|
344
|
+
type: 'VoidTypeAnnotation',
|
|
345
|
+
},
|
|
340
346
|
});
|
|
341
347
|
}
|
|
342
348
|
}
|
|
@@ -316,6 +316,9 @@ function emitPromise(
|
|
|
316
316
|
) {
|
|
317
317
|
return wrapNullable(nullable, {
|
|
318
318
|
type: 'PromiseTypeAnnotation',
|
|
319
|
+
elementType: {
|
|
320
|
+
type: 'VoidTypeAnnotation',
|
|
321
|
+
},
|
|
319
322
|
});
|
|
320
323
|
} else {
|
|
321
324
|
try {
|
|
@@ -335,6 +338,9 @@ function emitPromise(
|
|
|
335
338
|
} catch {
|
|
336
339
|
return wrapNullable(nullable, {
|
|
337
340
|
type: 'PromiseTypeAnnotation',
|
|
341
|
+
elementType: {
|
|
342
|
+
type: 'VoidTypeAnnotation',
|
|
343
|
+
},
|
|
338
344
|
});
|
|
339
345
|
}
|
|
340
346
|
}
|
|
@@ -199,6 +199,30 @@ export default TurboModuleRegistry.getEnforcing<Spec>(
|
|
|
199
199
|
'MixedValuesEnumNativeModule',
|
|
200
200
|
);
|
|
201
201
|
`;
|
|
202
|
+
const MAP_WITH_EXTRA_KEYS_NATIVE_MODULE = `
|
|
203
|
+
/**
|
|
204
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
205
|
+
*
|
|
206
|
+
* This source code is licensed under the MIT license found in the
|
|
207
|
+
* LICENSE file in the root directory of this source tree.
|
|
208
|
+
*
|
|
209
|
+
* @format
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
213
|
+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
|
|
214
|
+
|
|
215
|
+
type MapWithKey = {
|
|
216
|
+
[a: string]: string | null,
|
|
217
|
+
extra: string,
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface Spec extends TurboModule {
|
|
221
|
+
readonly getMap: (a: MapWithKey) => string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('MapWithExtraKeysNativeModule');
|
|
225
|
+
`;
|
|
202
226
|
module.exports = {
|
|
203
227
|
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
|
|
204
228
|
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
|
|
@@ -209,4 +233,5 @@ module.exports = {
|
|
|
209
233
|
TWO_NATIVE_EXTENDING_TURBO_MODULE,
|
|
210
234
|
EMPTY_ENUM_NATIVE_MODULE,
|
|
211
235
|
MIXED_VALUES_ENUM_NATIVE_MODULE,
|
|
236
|
+
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
|
|
212
237
|
};
|
|
@@ -208,6 +208,31 @@ export default TurboModuleRegistry.getEnforcing<Spec>(
|
|
|
208
208
|
);
|
|
209
209
|
`;
|
|
210
210
|
|
|
211
|
+
const MAP_WITH_EXTRA_KEYS_NATIVE_MODULE = `
|
|
212
|
+
/**
|
|
213
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
214
|
+
*
|
|
215
|
+
* This source code is licensed under the MIT license found in the
|
|
216
|
+
* LICENSE file in the root directory of this source tree.
|
|
217
|
+
*
|
|
218
|
+
* @format
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
222
|
+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
|
|
223
|
+
|
|
224
|
+
type MapWithKey = {
|
|
225
|
+
[a: string]: string | null,
|
|
226
|
+
extra: string,
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface Spec extends TurboModule {
|
|
230
|
+
readonly getMap: (a: MapWithKey) => string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('MapWithExtraKeysNativeModule');
|
|
234
|
+
`;
|
|
235
|
+
|
|
211
236
|
module.exports = {
|
|
212
237
|
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
|
|
213
238
|
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
|
|
@@ -218,4 +243,5 @@ module.exports = {
|
|
|
218
243
|
TWO_NATIVE_EXTENDING_TURBO_MODULE,
|
|
219
244
|
EMPTY_ENUM_NATIVE_MODULE,
|
|
220
245
|
MIXED_VALUES_ENUM_NATIVE_MODULE,
|
|
246
|
+
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
|
|
221
247
|
};
|
|
@@ -142,6 +142,7 @@ export type ObjectAlias = {
|
|
|
142
142
|
label: string;
|
|
143
143
|
truthy: boolean;
|
|
144
144
|
};
|
|
145
|
+
export type PureObjectAlias = ObjectAlias;
|
|
145
146
|
export type ReadOnlyAlias = Readonly<ObjectAlias>;
|
|
146
147
|
|
|
147
148
|
export interface Spec extends TurboModule {
|
|
@@ -151,6 +152,7 @@ export interface Spec extends TurboModule {
|
|
|
151
152
|
readonly getArray: (a: Array<A>) => {a: B};
|
|
152
153
|
readonly getStringFromAlias: (a: ObjectAlias) => string;
|
|
153
154
|
readonly getStringFromNullableAlias: (a: ObjectAlias | null) => string;
|
|
155
|
+
readonly getStringFromPureAlias: (a: PureObjectAlias) => string;
|
|
154
156
|
readonly getStringFromReadOnlyAlias: (a: ReadOnlyAlias) => string;
|
|
155
157
|
readonly getStringFromNullableReadOnlyAlias: (a: ReadOnlyAlias | null) => string;
|
|
156
158
|
}
|
|
@@ -146,6 +146,7 @@ export type ObjectAlias = {
|
|
|
146
146
|
label: string;
|
|
147
147
|
truthy: boolean;
|
|
148
148
|
};
|
|
149
|
+
export type PureObjectAlias = ObjectAlias;
|
|
149
150
|
export type ReadOnlyAlias = Readonly<ObjectAlias>;
|
|
150
151
|
|
|
151
152
|
export interface Spec extends TurboModule {
|
|
@@ -155,6 +156,7 @@ export interface Spec extends TurboModule {
|
|
|
155
156
|
readonly getArray: (a: Array<A>) => {a: B};
|
|
156
157
|
readonly getStringFromAlias: (a: ObjectAlias) => string;
|
|
157
158
|
readonly getStringFromNullableAlias: (a: ObjectAlias | null) => string;
|
|
159
|
+
readonly getStringFromPureAlias: (a: PureObjectAlias) => string;
|
|
158
160
|
readonly getStringFromReadOnlyAlias: (a: ReadOnlyAlias) => string;
|
|
159
161
|
readonly getStringFromNullableReadOnlyAlias: (a: ReadOnlyAlias | null) => string;
|
|
160
162
|
}
|
|
@@ -14,6 +14,8 @@ const _require = require('../../errors'),
|
|
|
14
14
|
UnsupportedEnumDeclarationParserError =
|
|
15
15
|
_require.UnsupportedEnumDeclarationParserError,
|
|
16
16
|
UnsupportedGenericParserError = _require.UnsupportedGenericParserError,
|
|
17
|
+
UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError =
|
|
18
|
+
_require.UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError,
|
|
17
19
|
UnsupportedTypeAnnotationParserError =
|
|
18
20
|
_require.UnsupportedTypeAnnotationParserError;
|
|
19
21
|
const _require2 = require('../../parsers-commons'),
|
|
@@ -302,6 +304,15 @@ function translateTypeAnnotation(
|
|
|
302
304
|
const indexSignatures = typeAnnotation.members.filter(
|
|
303
305
|
member => member.type === 'TSIndexSignature',
|
|
304
306
|
);
|
|
307
|
+
const properties = typeAnnotation.members.filter(
|
|
308
|
+
member => member.type === 'TSPropertySignature',
|
|
309
|
+
);
|
|
310
|
+
if (indexSignatures.length > 0 && properties.length > 0) {
|
|
311
|
+
throw new UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError(
|
|
312
|
+
hasteModuleName,
|
|
313
|
+
typeAnnotation,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
305
316
|
if (indexSignatures.length > 0) {
|
|
306
317
|
// check the property type to prevent developers from using unsupported types
|
|
307
318
|
// the return value from `translateTypeAnnotation` is unused
|
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
const {
|
|
29
29
|
UnsupportedEnumDeclarationParserError,
|
|
30
30
|
UnsupportedGenericParserError,
|
|
31
|
+
UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError,
|
|
31
32
|
UnsupportedTypeAnnotationParserError,
|
|
32
33
|
} = require('../../errors');
|
|
33
34
|
const {parseObjectProperty} = require('../../parsers-commons');
|
|
@@ -308,6 +309,18 @@ function translateTypeAnnotation(
|
|
|
308
309
|
const indexSignatures = typeAnnotation.members.filter(
|
|
309
310
|
member => member.type === 'TSIndexSignature',
|
|
310
311
|
);
|
|
312
|
+
|
|
313
|
+
const properties = typeAnnotation.members.filter(
|
|
314
|
+
member => member.type === 'TSPropertySignature',
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
if (indexSignatures.length > 0 && properties.length > 0) {
|
|
318
|
+
throw new UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError(
|
|
319
|
+
hasteModuleName,
|
|
320
|
+
typeAnnotation,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
311
324
|
if (indexSignatures.length > 0) {
|
|
312
325
|
// check the property type to prevent developers from using unsupported types
|
|
313
326
|
// the return value from `translateTypeAnnotation` is unused
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/codegen",
|
|
3
|
-
"version": "0.77.0-nightly-
|
|
3
|
+
"version": "0.77.0-nightly-20241002-d19a2178b",
|
|
4
4
|
"description": "Code generation tools for React Native",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"glob": "^7.1.1",
|
|
34
34
|
"hermes-parser": "0.23.1",
|
|
35
35
|
"invariant": "^2.2.4",
|
|
36
|
-
"jscodeshift": "^0.
|
|
36
|
+
"jscodeshift": "^17.0.0",
|
|
37
37
|
"nullthrows": "^1.1.1",
|
|
38
38
|
"yargs": "^17.6.2"
|
|
39
39
|
},
|