Supporting void function return type

This commit is contained in:
K35
2022-01-01 15:03:43 +00:00
parent 478094f2c3
commit 579055d8fb
7 changed files with 21 additions and 10 deletions

View File

@ -185,7 +185,7 @@ export default function get_ir(parsed: Parsed): IR {
if (!depends.some((a) => a === fnc.return_type))
depends.push(fnc.return_type);
} else {
if (builtin.indexOf(fnc.return_type) < 0) {
if (fnc.return_type !== "void" && builtin.indexOf(fnc.return_type) < 0) {
throw new IRError(
fnc,
`Type ${fnc.return_type} is not defined`

View File

@ -15,6 +15,7 @@ const conversion = {
boolean: "boolean",
number: "number",
string: "string",
void: "void"
};
function toJSType(type: string): string {
@ -215,7 +216,7 @@ export class TypescriptTarget extends CompileTarget {
a(
0,
this.generateImport(
"{ verify_number, verify_string, verify_boolean }",
"{ verify_number, verify_string, verify_boolean, verify_void }",
"./service_base"
)
);
@ -312,7 +313,7 @@ export class TypescriptTarget extends CompileTarget {
a(
0,
this.generateImport(
"{ verify_number, verify_string, verify_boolean }",
"{ verify_number, verify_string, verify_boolean, verify_void }",
"./service_base"
)
);
@ -360,7 +361,7 @@ export class TypescriptTarget extends CompileTarget {
a(2, ``);
a(2, `p.push(ctx);`);
a(2, `return this.${fnc.name}.call(this, ...p);`);
a(2, `return this.${fnc.name}.call(this, ...p)${fnc.return == "void" ? ".then(res => undefined)" : ""};`);
a(1, `}`);
a(0, ``);
}