Skip to content

Commit

Permalink
minor (#663): added back ts ignore and fixed runtime type assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzholzbauer committed Jul 17, 2024
1 parent 9694c40 commit 3aa308d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion kipper/target-js/src/code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;" +
Expand Down
13 changes: 10 additions & 3 deletions kipper/target-ts/src/code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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), `;
}
}
}

Expand All @@ -94,9 +101,9 @@ export class TypeScriptTargetCodeGenerator extends JavaScriptTargetCodeGenerator
"Type(",
'"' + interfaceName + '"',
",",
"[{",
"[",
propertiesWithTypes,
"}]",
"]",
",",
"[",
methods,
Expand Down

0 comments on commit 3aa308d

Please sign in to comment.