mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix bad formatting of generated C++ code (#39212)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39212 ## Changelog: [Internal] - Some of the generated C++ code was badly formatted - even though it's normally not supposed to be read by humans, sometimes it's still useful/needed, so it helps when it's more readable. Reviewed By: christophpurrer Differential Revision: D48827010 fbshipit-source-id: 3481af68ee6158902007c431e72e631d852c8b3c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
904d3e8ec9
commit
0c292f3934
@@ -9,6 +9,10 @@
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
import type {
|
||||
NativeModuleBaseTypeAnnotation,
|
||||
NamedShape,
|
||||
} from '../../CodegenSchema';
|
||||
|
||||
import type {
|
||||
Nullable,
|
||||
@@ -219,6 +223,18 @@ function createStructsString(
|
||||
resolveAlias: AliasResolver,
|
||||
enumMap: NativeModuleEnumMap,
|
||||
): string {
|
||||
const getCppType = (
|
||||
v: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>,
|
||||
) =>
|
||||
translatePrimitiveJSTypeToCpp(
|
||||
moduleName,
|
||||
v.typeAnnotation,
|
||||
false,
|
||||
typeName => `Unsupported type for param "${v.name}". Found: ${typeName}`,
|
||||
resolveAlias,
|
||||
enumMap,
|
||||
);
|
||||
|
||||
return Object.keys(aliasMap)
|
||||
.map(alias => {
|
||||
const value = aliasMap[alias];
|
||||
@@ -227,28 +243,22 @@ function createStructsString(
|
||||
}
|
||||
const structName = `${moduleName}Base${alias}`;
|
||||
const templateParameterWithTypename = value.properties
|
||||
.map((v, i) => 'typename P' + i)
|
||||
.map((v, i) => `typename P${i}`)
|
||||
.join(', ');
|
||||
const templateParameter = value.properties
|
||||
.map((v, i) => 'P' + i)
|
||||
.join(', ');
|
||||
const paramemterConversion = value.properties
|
||||
.map((v, i) => {
|
||||
const translatedParam = translatePrimitiveJSTypeToCpp(
|
||||
moduleName,
|
||||
v.typeAnnotation,
|
||||
false,
|
||||
typeName =>
|
||||
`Unsupported type for param "${v.name}". Found: ${typeName}`,
|
||||
resolveAlias,
|
||||
enumMap,
|
||||
);
|
||||
return ` static ${translatedParam} ${v.name}ToJs(jsi::Runtime &rt, P${i} value) {
|
||||
const debugParameterConversion = value.properties
|
||||
.map(
|
||||
(v, i) => ` static ${getCppType(v)} ${
|
||||
v.name
|
||||
}ToJs(jsi::Runtime &rt, P${i} value) {
|
||||
return bridging::toJs(rt, value);
|
||||
}`;
|
||||
})
|
||||
.join('\n');
|
||||
return `#pragma mark - ${structName}
|
||||
}`,
|
||||
)
|
||||
.join('\n\n');
|
||||
return `
|
||||
#pragma mark - ${structName}
|
||||
|
||||
template <${templateParameterWithTypename}>
|
||||
struct ${structName} {
|
||||
@@ -277,28 +287,28 @@ ${value.properties
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
${paramemterConversion}
|
||||
${debugParameterConversion}
|
||||
#endif
|
||||
|
||||
static jsi::Object toJs(
|
||||
jsi::Runtime &rt,
|
||||
const ${structName}<${templateParameter}> &value,
|
||||
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
||||
auto result = facebook::jsi::Object(rt);
|
||||
${value.properties
|
||||
.map((v, i) => {
|
||||
if (v.optional) {
|
||||
return ` if (value.${v.name}) {
|
||||
result.setProperty(rt, "${v.name}", bridging::toJs(rt, value.${v.name}.value(), jsInvoker));
|
||||
}`;
|
||||
} else {
|
||||
return ` result.setProperty(rt, "${v.name}", bridging::toJs(rt, value.${v.name}, jsInvoker));`;
|
||||
}
|
||||
})
|
||||
.join('\n')}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
jsi::Runtime &rt,
|
||||
const ${structName}<${templateParameter}> &value,
|
||||
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
||||
auto result = facebook::jsi::Object(rt);
|
||||
${value.properties
|
||||
.map((v, i) => {
|
||||
if (v.optional) {
|
||||
return ` if (value.${v.name}) {
|
||||
result.setProperty(rt, "${v.name}", bridging::toJs(rt, value.${v.name}.value(), jsInvoker));
|
||||
}`;
|
||||
} else {
|
||||
return ` result.setProperty(rt, "${v.name}", bridging::toJs(rt, value.${v.name}, jsInvoker));`;
|
||||
}
|
||||
})
|
||||
.join('\n')}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
`;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user