Skip to content

Commit b568fbe

Browse files
committed
refactor: cleanup
1 parent 8bfe3d0 commit b568fbe

7 files changed

Lines changed: 11 additions & 51 deletions

File tree

packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/failures.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export interface Spec extends TurboModule {
322322
export default TurboModuleRegistry.getEnforcing<Spec>('MixedValuesEnumNativeModule');
323323
`;
324324

325-
const NATIVE_MODULE_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY = `
325+
const NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY = `
326326
/**
327327
* Copyright (c) Meta Platforms, Inc. and affiliates.
328328
*
@@ -351,7 +351,6 @@ export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
351351
`;
352352

353353
module.exports = {
354-
NATIVE_MODULE_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY,
355354
NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT,
356355
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
357356
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
@@ -364,4 +363,5 @@ module.exports = {
364363
MIXED_VALUES_ENUM_NATIVE_MODULE,
365364
NUMERIC_VALUES_ENUM_NATIVE_MODULE,
366365
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
366+
NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY,
367367
};

packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export enum SomeEnum {
1313
^"
1414
`;
1515
16-
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULE_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY 1`] = `"Module NativeSampleTurboModule: Object property '[object Object]' cannot have type 'ArrayBuffer'."`;
16+
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY 1`] = `"Module NativeSampleTurboModule: Object property '[object Object]' cannot have type 'ArrayBuffer'."`;
1717
1818
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT 1`] = `"Module NativeSampleTurboModule: Generic 'Array' must have type parameters."`;
1919

packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type {
1717

1818
const {
1919
MissingTypeParameterGenericParserError,
20-
ParserError,
2120
UnnamedFunctionParamParserError,
2221
UnsupportedGenericParserError,
2322
UnsupportedTypeAnnotationParserError,
@@ -718,26 +717,6 @@ describe('Flow Module Parser', () => {
718717
expect(isReturnTypeAnnotationNullable).toBe(false);
719718
});
720719

721-
it('should parse methods that have a return type of Promise<ArrayBuffer>', () => {
722-
const module = parseModule(`
723-
import type {TurboModule} from 'RCTExport';
724-
import * as TurboModuleRegistry from 'TurboModuleRegistry';
725-
export interface Spec extends TurboModule {
726-
load(): Promise<ArrayBuffer>,
727-
}
728-
export default TurboModuleRegistry.get<Spec>('Foo');
729-
`);
730-
const [functionTypeAnnotation] = unwrapNullable(
731-
module.spec.methods[0].typeAnnotation,
732-
);
733-
const [returnTypeAnnotation] = unwrapNullable(
734-
functionTypeAnnotation.returnTypeAnnotation,
735-
);
736-
expect(returnTypeAnnotation.type).toBe('PromiseTypeAnnotation');
737-
const [elementType] = unwrapNullable(returnTypeAnnotation.elementType);
738-
expect(elementType.type).toBe('ArrayBufferTypeAnnotation');
739-
});
740-
741720
[true, false].forEach(IS_RETURN_TYPE_NULLABLE => {
742721
const RETURN_TYPE_DESCRIPTION = IS_RETURN_TYPE_NULLABLE
743722
? 'a nullable'

packages/react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/failures.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export interface Spec extends TurboModule {
261261
export default TurboModuleRegistry.getEnforcing<Spec>('MapWithExtraKeysNativeModule');
262262
`;
263263

264-
const NATIVE_MODULE_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY = `
264+
const NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY = `
265265
/**
266266
* Copyright (c) Meta Platforms, Inc. and affiliates.
267267
*
@@ -287,7 +287,6 @@ export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
287287
`;
288288

289289
module.exports = {
290-
NATIVE_MODULE_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY,
291290
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
292291
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
293292
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM,
@@ -299,4 +298,5 @@ module.exports = {
299298
MIXED_VALUES_ENUM_NATIVE_MODULE,
300299
NUMERIC_VALUES_ENUM_NATIVE_MODULE,
301300
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
301+
NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY,
302302
};

packages/react-native-codegen/src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`RN Codegen TypeScript Parser Fails with error message MAP_WITH_EXTRA_KE
66

77
exports[`RN Codegen TypeScript Parser Fails with error message MIXED_VALUES_ENUM_NATIVE_MODULE 1`] = `"Module NativeSampleTurboModule: Failed parsing the enum SomeEnum in NativeSampleTurboModule with the error: Enum values can not be mixed. They all must be either blank, number, or string values."`;
88

9-
exports[`RN Codegen TypeScript Parser Fails with error message NATIVE_MODULE_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY 1`] = `"Module NativeSampleTurboModule: Object property '[object Object]' cannot have type 'ArrayBuffer'."`;
9+
exports[`RN Codegen TypeScript Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY 1`] = `"Module NativeSampleTurboModule: Object property '[object Object]' cannot have type 'ArrayBuffer'."`;
1010

1111
exports[`RN Codegen TypeScript Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT 1`] = `"Module NativeSampleTurboModule: Generic 'Array' must have type parameters."`;
1212

packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type {
1717

1818
const {
1919
MissingTypeParameterGenericParserError,
20-
ParserError,
2120
UnnamedFunctionParamParserError,
2221
UnsupportedGenericParserError,
2322
UnsupportedTypeAnnotationParserError,
@@ -794,26 +793,6 @@ describe('TypeScript Module Parser', () => {
794793
expect(isReturnTypeAnnotationNullable).toBe(false);
795794
});
796795

797-
it('should parse methods that have a return type of Promise<ArrayBuffer>', () => {
798-
const module = parseModule(`
799-
import type {TurboModule} from 'RCTExport';
800-
import * as TurboModuleRegistry from 'TurboModuleRegistry';
801-
export interface Spec extends TurboModule {
802-
load(): Promise<ArrayBuffer>;
803-
}
804-
export default TurboModuleRegistry.get<Spec>('Foo');
805-
`);
806-
const [functionTypeAnnotation] = unwrapNullable(
807-
module.spec.methods[0].typeAnnotation,
808-
);
809-
const [returnTypeAnnotation] = unwrapNullable(
810-
functionTypeAnnotation.returnTypeAnnotation,
811-
);
812-
expect(returnTypeAnnotation.type).toBe('PromiseTypeAnnotation');
813-
const [elementType] = unwrapNullable(returnTypeAnnotation.elementType);
814-
expect(elementType.type).toBe('ArrayBufferTypeAnnotation');
815-
});
816-
817796
[true, false].forEach(IS_RETURN_TYPE_NULLABLE => {
818797
const RETURN_TYPE_DESCRIPTION = IS_RETURN_TYPE_NULLABLE
819798
? 'a nullable'

packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,22 @@ class NativeCxxModuleExampleExample extends React.Component<{}, State> {
108108
getArrayBuffer: () => {
109109
const view = new Uint8Array([1, 2, 3, 4, 5]);
110110
const buffer = NativeCxxModuleExample?.getArrayBuffer(view.buffer);
111-
return new Uint8Array(buffer).toString();
111+
return new Uint8Array(buffer || []).toString();
112112
},
113113
processAsyncBuffer: async () => {
114114
const view = new Uint8Array([10, 20, 30, 40, 50]);
115115
const nativeBuffer = NativeCxxModuleExample?.createNativeBuffer(10);
116116

117117
const [byteSum, zeroCopyByteSum] = await Promise.all([
118118
NativeCxxModuleExample?.processAsyncBuffer(view.buffer),
119-
NativeCxxModuleExample?.processAsyncBuffer(nativeBuffer),
119+
nativeBuffer != null
120+
? NativeCxxModuleExample?.processAsyncBuffer(nativeBuffer)
121+
: Promise.resolve(0),
120122
]);
121123

122124
this._setResult(
123125
'processAsyncBuffer',
124-
`sum=${String(byteSum + zeroCopyByteSum)}`,
126+
`sum=${(byteSum ?? 0) + (zeroCopyByteSum ?? 0)}`,
125127
);
126128
},
127129
getAsyncBuffer: () =>

0 commit comments

Comments
 (0)