Small bug-fixes and improvements

This commit is contained in:
K35 2022-01-02 22:17:31 +00:00
parent cf49fca928
commit 363dcf3e7d
4 changed files with 13 additions and 8 deletions

View File

@ -7288,7 +7288,7 @@ var log = (0, import_debug.default)("app");
var builtin = ["number", "string", "boolean"];
var IRError = class extends Error {
constructor(statement, message) {
super("Error Compiling: " + message);
super("Error building IR: " + message);
this.statement = statement;
}
};
@ -7384,7 +7384,7 @@ function get_ir(parsed) {
depends.push(fnc.return_type.type);
} else {
if (fnc.return_type.type !== "void" && builtin.indexOf(fnc.return_type.type) < 0) {
throw new IRError(fnc, `Type ${fnc.return_type} is not defined`);
throw new IRError(fnc, `Type ${fnc.return_type.type} is not defined`);
}
}
}
@ -7621,7 +7621,7 @@ var TypescriptTarget = class extends CompileTarget {
verifyType("elm", 1);
a(2, `}`);
} else if (field.map) {
a(2, `if(typeof data["${field.name}"] !== "object") throw new VerificationError("object", ${field.name}, data["${field.name}"]);`);
a(2, `if(typeof data["${field.name}"] !== "object") throw new VerificationError("object", "${field.name}", data["${field.name}"]);`);
a(2, `for(const key in data["${field.name}"]) {`);
verifyType(`data["${field.name}"][key]`, 1);
a(2, `}`);
@ -7644,6 +7644,7 @@ var TypescriptTarget = class extends CompileTarget {
}
t.forEach((l) => lines.push(" ".repeat(i) + l.trim()));
};
a(0, this.generateImport("{ VerificationError }", "./ts_base"));
a(0, `enum ${def.name} {`);
for (const value of def.values) {
a(1, `${value.name}=${value.value},`);

View File

@ -1,6 +1,6 @@
{
"name": "@hibas123/jrpcgen",
"version": "1.0.6",
"version": "1.0.9",
"main": "lib/index.js",
"license": "MIT",
"packageManager": "yarn@3.1.1",

View File

@ -6,7 +6,7 @@ const builtin = ["number", "string", "boolean"];
export class IRError extends Error {
constructor(public statement: StatementNode, message: string) {
super("Error Compiling: " + message);
super("Error building IR: " + message);
}
}
@ -198,7 +198,7 @@ export default function get_ir(parsed: Parsed): IR {
if (fnc.return_type.type !== "void" && builtin.indexOf(fnc.return_type.type) < 0) {
throw new IRError(
fnc,
`Type ${fnc.return_type} is not defined`
`Type ${fnc.return_type.type} is not defined`
);
}
}

View File

@ -199,7 +199,7 @@ export class TypescriptTarget extends CompileTarget {
} else if (field.map) {
a(
2,
`if(typeof data["${field.name}"] !== "object") throw new VerificationError("object", ${field.name}, data["${field.name}"]);`
`if(typeof data["${field.name}"] !== "object") throw new VerificationError("object", "${field.name}", data["${field.name}"]);`
);
a(2, `for(const key in data["${field.name}"]) {`);
verifyType(`data["${field.name}"][key]`, 1);
@ -225,6 +225,7 @@ export class TypescriptTarget extends CompileTarget {
}
t.forEach((l) => lines.push(" ".repeat(i) + l.trim()));
};
a(0, this.generateImport("{ VerificationError }", "./ts_base"));
a(0, `enum ${def.name} {`);
for (const value of def.values) {
@ -246,7 +247,10 @@ export class TypescriptTarget extends CompileTarget {
a(0, `}`);
a(0, ``);
a(0, `export function verify_${def.name} (data: ${def.name}) {`);
a(1, `if(${def.name}[data] == undefined) throw new VerificationError("${def.name}", undefined, data);`);
a(
1,
`if(${def.name}[data] == undefined) throw new VerificationError("${def.name}", undefined, data);`
);
a(1, `return data`);
a(0, `}`);