nitro-codegen
Version:
The code-generator for react-native-nitro-modules.
59 lines (58 loc) • 1.65 kB
JavaScript
import {} from '../SourceFile.js';
export class OptionalType {
wrappingType;
constructor(wrappingType) {
this.wrappingType = wrappingType;
}
get canBePassedByReference() {
// depends whether the wrapping type is heavy to copy or not.
return this.wrappingType.canBePassedByReference;
}
get kind() {
return 'optional';
}
get needsBraces() {
switch (this.wrappingType.kind) {
case 'function':
return true;
default:
return false;
}
}
getCode(language) {
const wrapping = this.wrappingType.getCode(language);
switch (language) {
case 'c++':
return `std::optional<${wrapping}>`;
case 'swift':
if (this.needsBraces) {
return `(${wrapping})?`;
}
else {
return `${wrapping}?`;
}
case 'kotlin':
if (this.needsBraces) {
return `(${wrapping})?`;
}
else {
return `${wrapping}?`;
}
default:
throw new Error(`Language ${language} is not yet supported for OptionalType!`);
}
}
getExtraFiles() {
return this.wrappingType.getExtraFiles();
}
getRequiredImports() {
return [
{
language: 'c++',
name: 'optional',
space: 'system',
},
...this.wrappingType.getRequiredImports(),
];
}
}