mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Omit getConstants for codegening if object is empty
Summary: Old codegen was omitting `getConstants` if it was empty. So do our. There's no point in providing this getter in this case. Reviewed By: RSNara Differential Revision: D16762230 fbshipit-source-id: 721df13a00848d23108329b152115c0f0aee8eb9
This commit is contained in:
committed by
Facebook Github Bot
parent
c0304aaa9b
commit
a5ea7200da
@@ -239,6 +239,12 @@ module.exports = {
|
||||
)
|
||||
.replace('::_ARGS_::', nativeArgs);
|
||||
if (prop.name === 'getConstants') {
|
||||
if (
|
||||
prop.typeAnnotation.returnTypeAnnotation.properties &&
|
||||
prop.typeAnnotation.returnTypeAnnotation.properties.length === 0
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
return constants.replace(/::_MODULE_NAME_::/, name);
|
||||
}
|
||||
return implementation;
|
||||
|
||||
@@ -114,6 +114,15 @@ function tranlsateMethodForImplementation(property): string {
|
||||
.slice(1)
|
||||
.join(':')
|
||||
.concat(':');
|
||||
if (
|
||||
property.name === 'getConstants' &&
|
||||
property.typeAnnotation.returnTypeAnnotation.type ===
|
||||
'ObjectTypeAnnotation' &&
|
||||
property.typeAnnotation.returnTypeAnnotation.properties &&
|
||||
property.typeAnnotation.returnTypeAnnotation.properties.length === 0
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
return propertyTemplate
|
||||
.replace(
|
||||
/::_KIND_::/g,
|
||||
@@ -217,10 +226,19 @@ module.exports = {
|
||||
.replace(
|
||||
'::_PROPERTIES_MAP_::',
|
||||
properties
|
||||
.map(({name: propertyName, typeAnnotation: {params}}) =>
|
||||
proprertyDefTemplate
|
||||
.replace(/::_PROPERTY_NAME_::/g, propertyName)
|
||||
.replace(/::_ARGS_COUNT_::/g, params.length.toString()),
|
||||
.map(
|
||||
({
|
||||
name: propertyName,
|
||||
typeAnnotation: {params, returnTypeAnnotation},
|
||||
}) =>
|
||||
propertyName === 'getConstants' &&
|
||||
returnTypeAnnotation.type === 'ObjectTypeAnnotation' &&
|
||||
returnTypeAnnotation.properties &&
|
||||
returnTypeAnnotation.properties.length === 0
|
||||
? ''
|
||||
: proprertyDefTemplate
|
||||
.replace(/::_PROPERTY_NAME_::/g, propertyName)
|
||||
.replace(/::_ARGS_COUNT_::/g, params.length.toString()),
|
||||
)
|
||||
.join('\n'),
|
||||
)
|
||||
|
||||
@@ -44,6 +44,11 @@ function flatObjects(
|
||||
.filter(
|
||||
annotation =>
|
||||
(annotation.name === 'GetConstantsReturnType') === forConstants,
|
||||
)
|
||||
.filter(
|
||||
annotation =>
|
||||
annotation.name !== 'GetConstantsReturnType' ||
|
||||
annotation.properties.length > 0,
|
||||
);
|
||||
|
||||
let flattenObjects: Array<{|
|
||||
|
||||
+13
@@ -331,6 +331,19 @@ const TWO_MODULES_DIFFERENT_FILES: SchemaType = {
|
||||
nativeModules: {
|
||||
Sample2TurboModule: {
|
||||
properties: [
|
||||
{
|
||||
name: 'getConstants',
|
||||
typeAnnotation: {
|
||||
type: 'FunctionTypeAnnotation',
|
||||
returnTypeAnnotation: {
|
||||
nullable: false,
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: [],
|
||||
},
|
||||
params: [],
|
||||
optional: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'voidFunc',
|
||||
typeAnnotation: {
|
||||
|
||||
+4
@@ -156,6 +156,9 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
|
||||
: TurboModule(\\"SampleTurboModule\\", jsInvoker) {
|
||||
methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc};
|
||||
}
|
||||
static jsi::Value __hostFunction_NativeSample2TurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return static_cast<NativeSample2TurboModuleCxxSpecJSI *>(&turboModule)->getConstants(rt);
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSample2TurboModuleCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
static_cast<NativeSample2TurboModuleCxxSpecJSI *>(&turboModule)->voidFunc(rt);
|
||||
@@ -164,6 +167,7 @@ static jsi::Value __hostFunction_NativeSample2TurboModuleCxxSpecJSI_voidFunc(jsi
|
||||
|
||||
NativeSample2TurboModuleCxxSpecJSI::NativeSample2TurboModuleCxxSpecJSI(std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: TurboModule(\\"Sample2TurboModule\\", jsInvoker) {
|
||||
methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSample2TurboModuleCxxSpecJSI_getConstants};
|
||||
methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSample2TurboModuleCxxSpecJSI_voidFunc};
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -136,6 +136,7 @@ protected:
|
||||
NativeSample2TurboModuleCxxSpecJSI(std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
|
||||
public:
|
||||
virtual jsi::Object getConstants(jsi::Runtime &rt) = 0;
|
||||
virtual void voidFunc(jsi::Runtime &rt) = 0;
|
||||
|
||||
};
|
||||
|
||||
+1
@@ -362,6 +362,7 @@ Map {
|
||||
|
||||
|
||||
@protocol NativeSample2TurboModuleSpec <RCTBridgeModule, RCTTurboModule>
|
||||
|
||||
- (void) voidFunc;
|
||||
@end
|
||||
|
||||
|
||||
+2
@@ -181,6 +181,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(id<RCTTurboModule
|
||||
: ObjCTurboModule(\\"SampleTurboModule\\", instance, jsInvoker) {
|
||||
methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc};
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSample2TurboModuleSpecJSI_voidFunc(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, VoidKind, \\"voidFunc\\", @selector(voidFunc), args, count);
|
||||
@@ -188,6 +189,7 @@ static facebook::jsi::Value __hostFunction_NativeSample2TurboModuleSpecJSI_voidF
|
||||
|
||||
NativeSample2TurboModuleSpecJSI::NativeSample2TurboModuleSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: ObjCTurboModule(\\"Sample2TurboModule\\", instance, jsInvoker) {
|
||||
|
||||
methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSample2TurboModuleSpecJSI_voidFunc};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user