Revert "Align TurboModule EventEmitter payload types across platforms (#58063)"

This reverts commit ab2ea649e6.
This commit is contained in:
Fabrizio Cucci committed 2026-09-21 14:42:15 +01:00
1 parent 19a3184981
commit 070af03ab3
23 files changed
+10 -441

No files matched your search

@@ -40,7 +40,6 @@ const {
getModules,
isArrayRecursiveMember,
isDirectRecursiveMember,
throwIfUnsupportedEventEmitterPayload,
} = require('./Utils');
type FilesOutput = Map<string, string>;
@@ -639,11 +638,6 @@ function translateEventEmitterToCpp(
resolveAlias: AliasResolver,
enumMap: NativeModuleEnumMap,
): EventEmitterCpp {
throwIfUnsupportedEventEmitterPayload(
eventEmitter.name,
eventEmitter.typeAnnotation.typeAnnotation,
);
const isVoidTypeAnnotation =
eventEmitter.typeAnnotation.typeAnnotation.type === 'VoidTypeAnnotation';
const templateName = `${toPascalCase(eventEmitter.name)}Type`;
@@ -28,7 +28,6 @@ const {parseValidUnionType, toPascalCase} = require('../Utils');
const {
createAliasResolver,
getModules,
throwIfUnsupportedEventEmitterPayload,
throwIfUnsupportedPromiseArrayBuffer,
} = require('./Utils');
@@ -142,9 +141,6 @@ function translateEventEmitterTypeToJavaType(
imports: Set<string>,
): string {
const typeAnnotation = eventEmitter.typeAnnotation.typeAnnotation;
throwIfUnsupportedEventEmitterPayload(eventEmitter.name, typeAnnotation);
switch (typeAnnotation.type) {
case 'StringTypeAnnotation':
return 'String';
@@ -183,8 +179,12 @@ function translateEventEmitterTypeToJavaType(
case 'ArrayTypeAnnotation':
imports.add('com.facebook.react.bridge.ReadableArray');
return 'ReadableArray';
case 'DoubleTypeAnnotation':
case 'FloatTypeAnnotation':
case 'Int32TypeAnnotation':
case 'VoidTypeAnnotation':
// Void emitters take no argument, so the caller never asks for a type.
case 'ArrayBufferTypeAnnotation':
// TODO: Add support for these types
throw new Error(
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
);
@@ -11,15 +11,12 @@
import type {NativeModuleEventEmitterShape} from '../../../CodegenSchema';
const {parseValidUnionType, toPascalCase} = require('../../Utils');
const {throwIfUnsupportedEventEmitterPayload} = require('../Utils');
function getEventEmitterTypeObjCType(
eventEmitter: NativeModuleEventEmitterShape,
): string {
const typeAnnotation = eventEmitter.typeAnnotation.typeAnnotation;
throwIfUnsupportedEventEmitterPayload(eventEmitter.name, typeAnnotation);
switch (typeAnnotation.type) {
case 'StringTypeAnnotation':
return 'NSString *_Nonnull';
@@ -42,9 +39,6 @@ function getEventEmitterTypeObjCType(
}
case 'NumberTypeAnnotation':
case 'NumberLiteralTypeAnnotation':
case 'DoubleTypeAnnotation':
case 'FloatTypeAnnotation':
case 'Int32TypeAnnotation':
return 'NSNumber *_Nonnull';
case 'BooleanTypeAnnotation':
case 'BooleanLiteralTypeAnnotation':
@@ -55,8 +49,11 @@ function getEventEmitterTypeObjCType(
return 'NSDictionary *';
case 'ArrayTypeAnnotation':
return 'NSArray<id<NSObject>> *';
case 'DoubleTypeAnnotation':
case 'FloatTypeAnnotation':
case 'Int32TypeAnnotation':
case 'VoidTypeAnnotation':
// Void emitters take no argument, so both callers skip this function.
// TODO: Add support for these types
throw new Error(
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`,
);
@@ -118,29 +118,10 @@ function throwIfUnsupportedPromiseArrayBuffer(
}
}
// ArrayBuffer is not emittable on any platform: Android emitters always carry a
// folly::dynamic payload, which cannot hold raw bytes, and neither the ObjC nor
// the C++ emitter contract can hand out a buffer that outlives the emit call.
// The parser rejects this too; the guard here also covers schemas built without
// going through the parser.
function throwIfUnsupportedEventEmitterPayload(
eventEmitterName: string,
typeAnnotation: NativeModuleTypeAnnotation,
): void {
if (typeAnnotation.type === 'ArrayBufferTypeAnnotation') {
throw new Error(
`Unsupported eventType for ${eventEmitterName}. Found: ${typeAnnotation.type}. ` +
'ArrayBuffer is not supported as an EventEmitter payload on any platform. ' +
'Pass the ArrayBuffer through a method instead.',
);
}
}
module.exports = {
createAliasResolver,
getModules,
isDirectRecursiveMember,
isArrayRecursiveMember,
throwIfUnsupportedEventEmitterPayload,
throwIfUnsupportedPromiseArrayBuffer,
};
@@ -130,36 +130,6 @@ const EVENT_EMITTER_MODULES: SchemaType = {
},
},
},
{
name: 'onEvent7',
optional: false,
typeAnnotation: {
type: 'EventEmitterTypeAnnotation',
typeAnnotation: {
type: 'DoubleTypeAnnotation',
},
},
},
{
name: 'onEvent8',
optional: false,
typeAnnotation: {
type: 'EventEmitterTypeAnnotation',
typeAnnotation: {
type: 'FloatTypeAnnotation',
},
},
},
{
name: 'onEvent9',
optional: false,
typeAnnotation: {
type: 'EventEmitterTypeAnnotation',
typeAnnotation: {
type: 'Int32TypeAnnotation',
},
},
},
],
methods: [
{
@@ -10,37 +10,9 @@
'use strict';
import type {SchemaType} from '../../../CodegenSchema';
const fixtures = require('../__test_fixtures__/fixtures.js');
const generator = require('../GenerateModuleH.js');
const ARRAY_BUFFER_EVENT_EMITTER_SCHEMA: SchemaType = {
modules: {
NativeSampleTurboModule: {
type: 'NativeModule',
aliasMap: {},
enumMap: {},
spec: {
eventEmitters: [
{
name: 'onBuffer',
optional: false,
typeAnnotation: {
type: 'EventEmitterTypeAnnotation',
typeAnnotation: {
type: 'ArrayBufferTypeAnnotation',
},
},
},
],
methods: [],
},
moduleName: 'SampleTurboModule',
},
},
};
describe('GenerateModuleH', () => {
Object.keys(fixtures)
.sort()
@@ -57,13 +29,4 @@ describe('GenerateModuleH', () => {
).toMatchSnapshot();
});
});
it('throws for an EventEmitter with an ArrayBuffer payload', () => {
expect(() =>
generator.generate(
'array_buffer_event_emitter_throws',
ARRAY_BUFFER_EVENT_EMITTER_SCHEMA,
),
).toThrow(/ArrayBuffer is not supported as an EventEmitter payload/);
});
});
@@ -71,40 +71,4 @@ describe('GenerateModuleHObjCpp', () => {
),
).toThrow(/Promise<ArrayBuffer> is not supported/);
});
it('throws for an EventEmitter with an ArrayBuffer payload', () => {
const schema: SchemaType = {
modules: {
NativeSampleTurboModule: {
type: 'NativeModule',
aliasMap: {},
enumMap: {},
spec: {
eventEmitters: [
{
name: 'onBuffer',
optional: false,
typeAnnotation: {
type: 'EventEmitterTypeAnnotation',
typeAnnotation: {
type: 'ArrayBufferTypeAnnotation',
},
},
},
],
methods: [],
},
moduleName: 'SampleTurboModule',
},
},
};
expect(() =>
generator.generate(
'array_buffer_event_emitter_throws',
schema,
'com.facebook.fbreact.specs',
false,
),
).toThrow(/ArrayBuffer is not supported as an EventEmitter payload/);
});
});
@@ -64,35 +64,4 @@ describe('GenerateModuleJavaSpec', () => {
generator.generate('array_buffer_promise_throws', schema),
).toThrow(/Promise<ArrayBuffer> is not supported/);
});
it('throws for an EventEmitter with an ArrayBuffer payload', () => {
const schema: SchemaType = {
modules: {
NativeSampleTurboModule: {
type: 'NativeModule',
aliasMap: {},
enumMap: {},
spec: {
eventEmitters: [
{
name: 'onBuffer',
optional: false,
typeAnnotation: {
type: 'EventEmitterTypeAnnotation',
typeAnnotation: {
type: 'ArrayBufferTypeAnnotation',
},
},
},
],
methods: [],
},
moduleName: 'SampleTurboModule',
},
},
};
expect(() =>
generator.generate('array_buffer_event_emitter_throws', schema),
).toThrow(/ArrayBuffer is not supported as an EventEmitter payload/);
});
});
@@ -1083,9 +1083,6 @@ protected:
eventEmitterMap_[\\"onEvent4\\"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
eventEmitterMap_[\\"onEvent5\\"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
eventEmitterMap_[\\"onEvent6\\"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
eventEmitterMap_[\\"onEvent7\\"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
eventEmitterMap_[\\"onEvent8\\"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
eventEmitterMap_[\\"onEvent9\\"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
}
void emitOnEvent1() {
@@ -1126,27 +1123,6 @@ protected:
return bridging::toJs(rt, eventValue, jsInvoker);
});
}
template <typename OnEvent7Type> void emitOnEvent7(OnEvent7Type value) {
static_assert(bridging::supportsFromJs<OnEvent7Type, double>, \\"value cannnot be converted to double\\");
static_cast<AsyncEventEmitter<jsi::Value>&>(*eventEmitterMap_[\\"onEvent7\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value {
return bridging::toJs(rt, eventValue, jsInvoker);
});
}
template <typename OnEvent8Type> void emitOnEvent8(OnEvent8Type value) {
static_assert(bridging::supportsFromJs<OnEvent8Type, double>, \\"value cannnot be converted to double\\");
static_cast<AsyncEventEmitter<jsi::Value>&>(*eventEmitterMap_[\\"onEvent8\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value {
return bridging::toJs(rt, eventValue, jsInvoker);
});
}
template <typename OnEvent9Type> void emitOnEvent9(OnEvent9Type value) {
static_assert(bridging::supportsFromJs<OnEvent9Type, int>, \\"value cannnot be converted to int\\");
static_cast<AsyncEventEmitter<jsi::Value>&>(*eventEmitterMap_[\\"onEvent9\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value {
return bridging::toJs(rt, eventValue, jsInvoker);
});
}
private:
static jsi::Value __voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) {
static_assert(
@@ -607,9 +607,6 @@ facebook::react::EventEmitterCallback _eventEmitterCallback;
- (void)emitOnEvent4:(BOOL)value;
- (void)emitOnEvent5:(NSDictionary *)value;
- (void)emitOnEvent6:(NSArray<id<NSObject>> *)value;
- (void)emitOnEvent7:(NSNumber *_Nonnull)value;
- (void)emitOnEvent8:(NSNumber *_Nonnull)value;
- (void)emitOnEvent9:(NSNumber *_Nonnull)value;
@end
namespace facebook::react {
@@ -292,27 +292,6 @@ public abstract class NativeSampleTurboModuleSpec extends ReactContextBaseJavaMo
}
}
protected final void emitOnEvent7(double value) {
CxxCallbackImpl eventEmitterCallback = mEventEmitterCallback;
if (eventEmitterCallback != null) {
eventEmitterCallback.invoke(\\"onEvent7\\", value);
}
}
protected final void emitOnEvent8(double value) {
CxxCallbackImpl eventEmitterCallback = mEventEmitterCallback;
if (eventEmitterCallback != null) {
eventEmitterCallback.invoke(\\"onEvent8\\", value);
}
}
protected final void emitOnEvent9(double value) {
CxxCallbackImpl eventEmitterCallback = mEventEmitterCallback;
if (eventEmitterCallback != null) {
eventEmitterCallback.invoke(\\"onEvent9\\", value);
}
}
@ReactMethod
@DoNotStrip
public abstract void voidFunc();
@@ -280,9 +280,6 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboMo
eventEmitterMap_[\\"onEvent4\\"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
eventEmitterMap_[\\"onEvent5\\"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
eventEmitterMap_[\\"onEvent6\\"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
eventEmitterMap_[\\"onEvent7\\"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
eventEmitterMap_[\\"onEvent8\\"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
eventEmitterMap_[\\"onEvent9\\"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
configureEventEmitterCallback();
}
@@ -366,27 +366,6 @@ Map {
eventEmitterCallback(\\"onEvent6\\", value);
}
}
- (void)emitOnEvent7:(NSNumber *_Nonnull)value
{
auto eventEmitterCallback = _eventEmitterCallback;
if (eventEmitterCallback) {
eventEmitterCallback(\\"onEvent7\\", value);
}
}
- (void)emitOnEvent8:(NSNumber *_Nonnull)value
{
auto eventEmitterCallback = _eventEmitterCallback;
if (eventEmitterCallback) {
eventEmitterCallback(\\"onEvent8\\", value);
}
}
- (void)emitOnEvent9:(NSNumber *_Nonnull)value
{
auto eventEmitterCallback = _eventEmitterCallback;
if (eventEmitterCallback) {
eventEmitterCallback(\\"onEvent9\\", value);
}
}
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper
{
@@ -412,9 +391,6 @@ namespace facebook::react {
eventEmitterMap_[\\"onEvent4\\"] = std::make_shared<AsyncEventEmitter<id>>();
eventEmitterMap_[\\"onEvent5\\"] = std::make_shared<AsyncEventEmitter<id>>();
eventEmitterMap_[\\"onEvent6\\"] = std::make_shared<AsyncEventEmitter<id>>();
eventEmitterMap_[\\"onEvent7\\"] = std::make_shared<AsyncEventEmitter<id>>();
eventEmitterMap_[\\"onEvent8\\"] = std::make_shared<AsyncEventEmitter<id>>();
eventEmitterMap_[\\"onEvent9\\"] = std::make_shared<AsyncEventEmitter<id>>();
setEventEmitterCallback([eventEmitterMap = eventEmitterMap_](const std::string &name, id value) {
auto it = eventEmitterMap.find(name);
if (it != eventEmitterMap.end() && it->second) {
@@ -18,7 +18,6 @@ const {
throwIfArgumentPropsAreNull,
throwIfArrayElementTypeAnnotationIsUnsupported,
throwIfBubblingTypeIsNull,
throwIfEventEmitterPayloadTypeIsUnsupported,
throwIfEventHasNoName,
throwIfIncorrectModuleRegistryCallArgument,
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
@@ -826,35 +825,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => {
});
});
describe('throwIfEventEmitterPayloadTypeIsUnsupported', () => {
const {
UnsupportedModuleEventEmitterPayloadTypeParserError,
} = require('../errors.js');
const moduleName = 'moduleName';
it('throws the error if the payload is an ArrayBuffer', () => {
expect(() => {
throwIfEventEmitterPayloadTypeIsUnsupported(
moduleName,
undefined,
'onBuffer',
{type: 'ArrayBufferTypeAnnotation'},
);
}).toThrow(UnsupportedModuleEventEmitterPayloadTypeParserError);
});
it('does not throw the error if the payload is a supported type', () => {
expect(() => {
throwIfEventEmitterPayloadTypeIsUnsupported(
moduleName,
undefined,
'onCount',
{type: 'DoubleTypeAnnotation'},
);
}).not.toThrow();
});
});
describe('throwIfPartialNotAnnotatingTypeParameter', () => {
const flowParser = new FlowParser();
const typescriptParser = new TypeScriptParser();
@@ -27,7 +27,6 @@ const {
UnsupportedArrayElementTypeAnnotationParserError,
UnsupportedFunctionParamTypeAnnotationParserError,
UnsupportedFunctionReturnTypeAnnotationParserError,
UnsupportedModuleEventEmitterPayloadTypeParserError,
UnsupportedModuleEventEmitterPropertyParserError,
UnsupportedModuleEventEmitterTypePropertyParserError,
UnsupportedModulePropertyParserError,
@@ -197,25 +196,6 @@ function throwIfEventEmitterEventTypeIsUnsupported(
}
}
// ArrayBuffer is not emittable on any platform: Android emitters always carry a
// folly::dynamic payload, which cannot hold raw bytes, and neither the ObjC nor
// the C++ emitter contract can hand out a buffer that outlives the emit call.
function throwIfEventEmitterPayloadTypeIsUnsupported(
nativeModuleName: string,
propertyValue: $FlowFixMe,
propertyName: string,
payloadTypeAnnotation: NativeModuleTypeAnnotation,
) {
if (payloadTypeAnnotation.type === 'ArrayBufferTypeAnnotation') {
throw new UnsupportedModuleEventEmitterPayloadTypeParserError(
nativeModuleName,
propertyValue,
propertyName,
'ArrayBuffer',
);
}
}
function throwIfModuleTypeIsUnsupported(
nativeModuleName: string,
propertyValue: $FlowFixMe,
@@ -438,7 +418,6 @@ module.exports = {
throwIfUntypedModule,
throwIfEventEmitterTypeIsUnsupported,
throwIfEventEmitterEventTypeIsUnsupported,
throwIfEventEmitterPayloadTypeIsUnsupported,
throwIfModuleTypeIsUnsupported,
throwIfMoreThanOneModuleInterfaceParserError,
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
-16
View File
@@ -111,21 +111,6 @@ class UnsupportedModuleEventEmitterPropertyParserError extends ParserError {
}
}
class UnsupportedModuleEventEmitterPayloadTypeParserError extends ParserError {
constructor(
nativeModuleName: string,
propertyValue: $FlowFixMe,
propertyName: string,
payloadType: string,
) {
super(
nativeModuleName,
propertyValue,
`EventEmitter '${propertyName}' cannot have payload type '${payloadType}'.`,
);
}
}
class UnsupportedModulePropertyParserError extends ParserError {
constructor(
nativeModuleName: string,
@@ -471,7 +456,6 @@ module.exports = {
UnsupportedEnumDeclarationParserError,
UnsupportedModuleEventEmitterTypePropertyParserError,
UnsupportedModuleEventEmitterPropertyParserError,
UnsupportedModuleEventEmitterPayloadTypeParserError,
UnsupportedModulePropertyParserError,
UnsupportedObjectPropertyTypeAnnotationParserError,
UnsupportedObjectPropertyWithIndexerTypeAnnotationParserError,
@@ -350,31 +350,6 @@ export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;
const NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_EVENT_EMITTER = `
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
import type {TurboModule} from '../RCTExport';
import type {EventEmitter} from '../CodegenTypes';
import * as TurboModuleRegistry from '../TurboModuleRegistry';
export interface Spec extends TurboModule {
+onBuffer: EventEmitter<ArrayBuffer>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;
module.exports = {
NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT,
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
@@ -389,5 +364,4 @@ module.exports = {
NUMERIC_VALUES_ENUM_NATIVE_MODULE,
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY,
NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_EVENT_EMITTER,
};
@@ -667,7 +667,7 @@ const NATIVE_MODULE_WITH_EVENT_EMITTERS = `
'use strict';
import type {TurboModule} from '../RCTExport';
import type {Double, EventEmitter, Float, Int32} from '../CodegenTypes';
import type {EventEmitter} from '../CodegenTypes';
import * as TurboModuleRegistry from '../TurboModuleRegistry';
export type ObjectStruct = {
@@ -686,9 +686,6 @@ export interface Spec extends TurboModule {
+onEvent5: EventEmitter<ObjectStruct>;
+onEvent6: EventEmitter<ObjectStruct[]>;
+onEvent7: EventEmitter<MappedObject>;
+onEvent8: EventEmitter<Double>;
+onEvent9: EventEmitter<Float>;
+onEvent10: EventEmitter<Int32>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
@@ -6,8 +6,6 @@ exports[`RN Codegen Flow Parser Fails with error message MAP_WITH_EXTRA_KEYS_NAT
exports[`RN Codegen Flow Parser Fails with error message MIXED_VALUES_ENUM_NATIVE_MODULE 1`] = `"Module NativeSampleTurboModule: Failed parsing the enum SomeEnum in NativeSampleTurboModule with the error: Enums can not be mixed- they all must be either blank, number, or string values."`;
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_EVENT_EMITTER 1`] = `"Module NativeSampleTurboModule: EventEmitter 'onBuffer' cannot have payload type 'ArrayBuffer'."`;
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'."`;
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."`;
@@ -2121,36 +2119,6 @@ exports[`RN Codegen Flow Parser can generate fixture NATIVE_MODULE_WITH_EVENT_EM
}
}
}
},
{
'name': 'onEvent8',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'DoubleTypeAnnotation'
}
}
},
{
'name': 'onEvent9',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'FloatTypeAnnotation'
}
}
},
{
'name': 'onEvent10',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'Int32TypeAnnotation'
}
}
}
],
'methods': []
@@ -42,7 +42,6 @@ import type {
const {
throwIfConfigNotfound,
throwIfEventEmitterEventTypeIsUnsupported,
throwIfEventEmitterPayloadTypeIsUnsupported,
throwIfEventEmitterTypeIsUnsupported,
throwIfIncorrectModuleRegistryCallArgument,
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
@@ -552,13 +551,6 @@ function buildEventEmitterSchema(
parser,
);
throwIfEventEmitterPayloadTypeIsUnsupported(
hasteModuleName,
typeAnnotation.typeParameters.params[0],
key.name,
eventTypeAnnotation,
);
return {
name: eventemitterName,
optional: Boolean(property.optional),
@@ -286,27 +286,6 @@ export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;
const NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_EVENT_EMITTER = `
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
export interface Spec extends TurboModule {
readonly onBuffer: EventEmitter<ArrayBuffer>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;
module.exports = {
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
@@ -320,5 +299,4 @@ module.exports = {
NUMERIC_VALUES_ENUM_NATIVE_MODULE,
MAP_WITH_EXTRA_KEYS_NATIVE_MODULE,
NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_OBJECT_PROPERTY,
NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_EVENT_EMITTER,
};
@@ -766,7 +766,6 @@ const NATIVE_MODULE_WITH_EVENT_EMITTERS = `
*/
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
import type {Double, Float, Int32} from 'react-native/Libraries/Types/CodegenTypes';
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
export type ObjectStruct = {
@@ -785,9 +784,6 @@ export interface Spec extends TurboModule {
readonly onEvent5: EventEmitter<ObjectStruct>;
readonly onEvent6: EventEmitter<ObjectStruct[]>;
readonly onEvent7: EventEmitter<MappedObject>;
readonly onEvent8: EventEmitter<Double>;
readonly onEvent9: EventEmitter<Float>;
readonly onEvent10: EventEmitter<Int32>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
@@ -6,8 +6,6 @@ exports[`RN Codegen TypeScript Parser Fails with error message MAP_WITH_EXTRA_KE
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."`;
exports[`RN Codegen TypeScript Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_BUFFER_IN_EVENT_EMITTER 1`] = `"Module NativeSampleTurboModule: EventEmitter 'onBuffer' cannot have payload type 'ArrayBuffer'."`;
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'."`;
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."`;
@@ -2345,36 +2343,6 @@ exports[`RN Codegen TypeScript Parser can generate fixture NATIVE_MODULE_WITH_EV
}
}
}
},
{
'name': 'onEvent8',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'DoubleTypeAnnotation'
}
}
},
{
'name': 'onEvent9',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'FloatTypeAnnotation'
}
}
},
{
'name': 'onEvent10',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'Int32TypeAnnotation'
}
}
}
],
'methods': []