mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Clean up old Cxx TM member generation (#43710)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43710 As we had already cut a branch for RN 0.74 https://github.com/facebook/react-native/releases/tag/v0.74.0-rc.1 We can delete this code already Changelog: [Internal] Reviewed By: shwanton Differential Revision: D55511382 fbshipit-source-id: 3ef15af338b5ad31b02e0a1eed7ac873566d9562
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1b4a0cd9f2
commit
04bf8cfb23
@@ -231,135 +231,53 @@ function createStructsString(
|
||||
enumMap,
|
||||
);
|
||||
|
||||
// TODO: T171006733 [Begin] Remove deprecated Cxx TMs structs after a new release.
|
||||
return (
|
||||
Object.keys(aliasMap)
|
||||
.map(alias => {
|
||||
const value = aliasMap[alias];
|
||||
if (value.properties.length === 0) {
|
||||
return '';
|
||||
return Object.keys(aliasMap)
|
||||
.map(alias => {
|
||||
const value = aliasMap[alias];
|
||||
if (value.properties.length === 0) {
|
||||
return '';
|
||||
}
|
||||
const structName = `${moduleName}${alias}`;
|
||||
const templateParameter = value.properties.filter(
|
||||
v =>
|
||||
!isDirectRecursiveMember(alias, v.typeAnnotation) &&
|
||||
!isArrayRecursiveMember(alias, v.typeAnnotation),
|
||||
);
|
||||
const templateParameterWithTypename = templateParameter
|
||||
.map((v, i) => `typename P${i}`)
|
||||
.join(', ');
|
||||
const templateParameterWithoutTypename = templateParameter
|
||||
.map((v, i) => `P${i}`)
|
||||
.join(', ');
|
||||
let i = -1;
|
||||
const templateMemberTypes = value.properties.map(v => {
|
||||
if (isDirectRecursiveMember(alias, v.typeAnnotation)) {
|
||||
return `std::unique_ptr<${structName}<${templateParameterWithoutTypename}>> ${v.name}`;
|
||||
} else if (isArrayRecursiveMember(alias, v.typeAnnotation)) {
|
||||
const [nullable] = unwrapNullable<NativeModuleTypeAnnotation>(
|
||||
v.typeAnnotation,
|
||||
);
|
||||
return (
|
||||
(nullable
|
||||
? `std::optional<std::vector<${structName}<${templateParameterWithoutTypename}>>>`
|
||||
: `std::vector<${structName}<${templateParameterWithoutTypename}>>`) +
|
||||
` ${v.name}`
|
||||
);
|
||||
} else {
|
||||
i++;
|
||||
return `P${i} ${v.name}`;
|
||||
}
|
||||
const structName = `${moduleName}Base${alias}`;
|
||||
const structNameNew = `${moduleName}${alias}`;
|
||||
const templateParameterWithTypename = value.properties
|
||||
.map((v, i) => `typename P${i}`)
|
||||
.join(', ');
|
||||
const templateParameter = value.properties
|
||||
.map((v, i) => 'P' + i)
|
||||
.join(', ');
|
||||
const debugParameterConversion = value.properties
|
||||
.map(
|
||||
(v, i) => ` static ${getCppType(alias, v)} ${
|
||||
v.name
|
||||
}ToJs(jsi::Runtime &rt, P${i} value) {
|
||||
});
|
||||
const debugParameterConversion = value.properties
|
||||
.map(
|
||||
v => ` static ${getCppType(alias, v)} ${
|
||||
v.name
|
||||
}ToJs(jsi::Runtime &rt, decltype(types.${v.name}) value) {
|
||||
return bridging::toJs(rt, value);
|
||||
}`,
|
||||
)
|
||||
.join('\n\n');
|
||||
return `
|
||||
#pragma mark - ${structName}
|
||||
|
||||
template <${templateParameterWithTypename}>
|
||||
struct [[deprecated("Use ${structNameNew} instead.")]] ${structName} {
|
||||
${value.properties.map((v, i) => ' P' + i + ' ' + v.name).join(';\n')};
|
||||
bool operator==(const ${structName} &other) const {
|
||||
return ${value.properties
|
||||
.map(v => `${v.name} == other.${v.name}`)
|
||||
.join(' && ')};
|
||||
}
|
||||
};
|
||||
|
||||
template <${templateParameterWithTypename}>
|
||||
struct [[deprecated("Use ${structNameNew}Bridging instead.")]] ${structName}Bridging {
|
||||
static ${structName}<${templateParameter}> fromJs(
|
||||
jsi::Runtime &rt,
|
||||
const jsi::Object &value,
|
||||
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
||||
${structName}<${templateParameter}> result{
|
||||
${value.properties
|
||||
.map(
|
||||
(v, i) =>
|
||||
` bridging::fromJs<P${i}>(rt, value.getProperty(rt, "${v.name}"), jsInvoker)`,
|
||||
)
|
||||
.join(',\n')}};
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
${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;
|
||||
}
|
||||
};
|
||||
|
||||
`;
|
||||
})
|
||||
.join('\n') +
|
||||
// TODO: T171006733 [End] Remove deprecated Cxx TMs structs after a new release.
|
||||
Object.keys(aliasMap)
|
||||
.map(alias => {
|
||||
const value = aliasMap[alias];
|
||||
if (value.properties.length === 0) {
|
||||
return '';
|
||||
}
|
||||
const structName = `${moduleName}${alias}`;
|
||||
const templateParameter = value.properties.filter(
|
||||
v =>
|
||||
!isDirectRecursiveMember(alias, v.typeAnnotation) &&
|
||||
!isArrayRecursiveMember(alias, v.typeAnnotation),
|
||||
);
|
||||
const templateParameterWithTypename = templateParameter
|
||||
.map((v, i) => `typename P${i}`)
|
||||
.join(', ');
|
||||
const templateParameterWithoutTypename = templateParameter
|
||||
.map((v, i) => `P${i}`)
|
||||
.join(', ');
|
||||
let i = -1;
|
||||
const templateMemberTypes = value.properties.map(v => {
|
||||
if (isDirectRecursiveMember(alias, v.typeAnnotation)) {
|
||||
return `std::unique_ptr<${structName}<${templateParameterWithoutTypename}>> ${v.name}`;
|
||||
} else if (isArrayRecursiveMember(alias, v.typeAnnotation)) {
|
||||
const [nullable] = unwrapNullable<NativeModuleTypeAnnotation>(
|
||||
v.typeAnnotation,
|
||||
);
|
||||
return (
|
||||
(nullable
|
||||
? `std::optional<std::vector<${structName}<${templateParameterWithoutTypename}>>>`
|
||||
: `std::vector<${structName}<${templateParameterWithoutTypename}>>`) +
|
||||
` ${v.name}`
|
||||
);
|
||||
} else {
|
||||
i++;
|
||||
return `P${i} ${v.name}`;
|
||||
}
|
||||
});
|
||||
const debugParameterConversion = value.properties
|
||||
.map(
|
||||
v => ` static ${getCppType(alias, v)} ${
|
||||
v.name
|
||||
}ToJs(jsi::Runtime &rt, decltype(types.${v.name}) value) {
|
||||
return bridging::toJs(rt, value);
|
||||
}`,
|
||||
)
|
||||
.join('\n\n');
|
||||
return `
|
||||
)
|
||||
.join('\n\n');
|
||||
return `
|
||||
#pragma mark - ${structName}
|
||||
|
||||
template <${templateParameterWithTypename}>
|
||||
@@ -422,9 +340,8 @@ ${value.properties
|
||||
};
|
||||
|
||||
`;
|
||||
})
|
||||
.join('\n')
|
||||
);
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
type NativeEnumMemberValueType = 'std::string' | 'int32_t' | 'float';
|
||||
|
||||
Reference in New Issue
Block a user