diff --git a/lib/jrpc.js b/lib/jrpc.js index a622b78..7e8f409 100755 --- a/lib/jrpc.js +++ b/lib/jrpc.js @@ -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},`); diff --git a/package.json b/package.json index c0b684c..829e72f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/ir.ts b/src/ir.ts index fda8971..6a635b4 100644 --- a/src/ir.ts +++ b/src/ir.ts @@ -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` ); } } diff --git a/src/targets/typescript.ts b/src/targets/typescript.ts index bc03372..2a7c106 100644 --- a/src/targets/typescript.ts +++ b/src/targets/typescript.ts @@ -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, `}`);