@ts-for-gir/lib
Version:
Typescript .d.ts generator from GIR for gjs
31 lines • 1.23 kB
JavaScript
import { TypeIdentifier, NullableType } from "../gir.js";
import { GirVisitor } from "../visitor.js";
export class FunctionParametersVisitor extends GirVisitor {
makeEnumParamsNullable(node) {
return node.copy({
parameters: node.parameters.map(param => {
const type = param.type.deepUnwrap();
if (type instanceof TypeIdentifier) {
// Get the namespace where this type should be defined
const ns = node.namespace.assertInstalledImport(type.namespace);
// Check if the type is an enum
const isEnumType = !!ns.getEnum(type.name);
// If it is, make the parameter nullable
if (isEnumType) {
return param.copy({
type: new NullableType(param.type)
});
}
}
return param;
})
});
}
visitFunction = (node) => {
return this.makeEnumParamsNullable(node);
};
visitClassFunction = (node) => {
return this.makeEnumParamsNullable(node);
};
}
//# sourceMappingURL=function-parameters.js.map