Making apply return a class

This commit is contained in:
K35 2022-01-05 09:21:01 +00:00
parent 99563959c6
commit 94832ef682

View File

@ -128,7 +128,7 @@ export class TypescriptTarget extends CompileTarget {
); );
{ {
a(1, `if(typeof data !== "object") throw new VerificationError("${def.name}", undefined, data);`) 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) => { def.fields.forEach((field) => {
a(1, `if(data["${field.name}"] !== null && data["${field.name}"] !== undefined) {`) a(1, `if(data["${field.name}"] !== null && data["${field.name}"] !== undefined) {`)
if (field.array) { if (field.array) {
@ -157,68 +157,6 @@ export class TypescriptTarget extends CompileTarget {
a(0, ``); 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")); this.writeFormattedFile(this.getFileName(def.name), lines.join("\n"));
} }