From 3aa308d4e36325ba2ed82b10b2aca1eaab89efec Mon Sep 17 00:00:00 2001 From: Lorenz Holzbauer <73286868+lorenzholzbauer@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:11:16 +0000 Subject: [PATCH] minor (#663): added back ts ignore and fixed runtime type assignment --- kipper/target-js/src/code-generator.ts | 4 +++- kipper/target-ts/src/code-generator.ts | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kipper/target-js/src/code-generator.ts b/kipper/target-js/src/code-generator.ts index fdf17a603..65241bcaf 100644 --- a/kipper/target-js/src/code-generator.ts +++ b/kipper/target-js/src/code-generator.ts @@ -121,9 +121,11 @@ export class JavaScriptTargetCodeGenerator extends KipperTargetCodeGenerator { ], // The following object is the template for runtime types ["// @ts-ignore"], + ["class Property {constructor(name, type) {this.name = name;this.type = type;}}"], + ["// @ts-ignore"], [ "class Type {" + - "constructor(name, fields = [], methods = [], baseType = null) {" + + "constructor(name, fields, methods, baseType = null) {" + "this.name = name;" + "this.fields = fields;" + "this.methods = methods;" + diff --git a/kipper/target-ts/src/code-generator.ts b/kipper/target-ts/src/code-generator.ts index 850a062c7..c7a28c09c 100644 --- a/kipper/target-ts/src/code-generator.ts +++ b/kipper/target-ts/src/code-generator.ts @@ -19,6 +19,7 @@ import { createTSFunctionSignature, getTSFunctionSignature } from "./tools"; import { indentLines, JavaScriptTargetCodeGenerator, TargetJS } from "@kipper/target-js"; import { TargetTS } from "./target"; import type { InterfaceMemberDeclarationTypeSemantics } from "@kipper/core/lib/compiler/ast/nodes/declarations/type-declaration/interface-declaration/interface-member-declaration/interface-member-declaration-type-semantics"; +import { BuiltInRuntimeType } from "@kipper/target-js/lib/built-in-types"; /** * The TypeScript target-specific code generator for translating Kipper code into TypeScript. @@ -79,7 +80,13 @@ export class TypeScriptTargetCodeGenerator extends JavaScriptTargetCodeGenerator if (member instanceof InterfacePropertyDeclaration) { let property = member.getSemanticData(); let type = member.getTypeSemanticData(); - propertiesWithTypes += `"${property.identifier}": ${TargetJS.getRuntimeType(type.type)}, `; + let runtimeType = TargetJS.getRuntimeType(type.type); + if(runtimeType instanceof BuiltInRuntimeType){ + propertiesWithTypes += `new Property("${property.identifier}", ${TargetJS.internalObjectIdentifier}.builtIn.${runtimeType.name}),`; + } + else{ + propertiesWithTypes += `new Property(${property.identifier}, TESTEST), `; + } } } @@ -94,9 +101,9 @@ export class TypeScriptTargetCodeGenerator extends JavaScriptTargetCodeGenerator "Type(", '"' + interfaceName + '"', ",", - "[{", + "[", propertiesWithTypes, - "}]", + "]", ",", "[", methods,