From 94832ef6823bb14effb60edb134ffc65067433e4 Mon Sep 17 00:00:00 2001 From: K35 Date: Wed, 5 Jan 2022 09:21:01 +0000 Subject: [PATCH] Making apply return a class --- src/targets/typescript.ts | 64 +-------------------------------------- 1 file changed, 1 insertion(+), 63 deletions(-) diff --git a/src/targets/typescript.ts b/src/targets/typescript.ts index 8d1a0eb..c3dbc3d 100644 --- a/src/targets/typescript.ts +++ b/src/targets/typescript.ts @@ -128,7 +128,7 @@ export class TypescriptTarget extends CompileTarget { ); { a(1, `if(typeof data !== "object") throw new VerificationError("${def.name}", undefined, data);`) - a(1, `let res = {} as any;`); + a(1, `let res = new ${def.name}() as any;`); def.fields.forEach((field) => { a(1, `if(data["${field.name}"] !== null && data["${field.name}"] !== undefined) {`) if (field.array) { @@ -157,68 +157,6 @@ export class TypescriptTarget extends CompileTarget { a(0, ``); - // a(0, `export function verify_${def.name}(data: ${def.name}) {`); - // { - // def.fields.forEach((field) => { - // a( - // 1, - // `if(data["${field.name}"] !== null && data["${field.name}"] !== undefined ) {` - // ); - - // const verifyType = (varName: string, off = 0) => { - // switch (field.type) { - // case "string": - // a( - // 2 + off, - // `if(typeof ${varName} !== "string") throw new VerificationError("string", "${field.name}", ${varName});` - // ); - // break; - // case "number": - // a( - // 2 + off, - // `if(typeof ${varName} !== "number") throw new VerificationError("number", "${field.name}", ${varName});` - // ); - // break; - // case "boolean": - // a( - // 2 + off, - // `if(typeof ${varName} !== "boolean") throw new VerificationError("boolean", "${field.name}", ${varName});` - // ); - // break; - // default: - // a( - // 2 + off, - // `verify_${field.type}(${varName});` - // ); - // } - // }; - - // if (field.array) { - // a( - // 2, - // `` - // ); - // a(2, `for(const elm of data["${field.name}"]) {`); - // 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, `for(const key in data["${field.name}"]) {`); - // verifyType(`data["${field.name}"][key]`, 1); - // a(2, `}`); - // } else { - // verifyType(`data["${field.name}"]`); - // } - // a(1, "}"); - // a(0, ``); - // }); - // a(1, `return data`); - // } - // a(0, `}`); - this.writeFormattedFile(this.getFileName(def.name), lines.join("\n")); }