From 45f1e6ae35ff66159f301d96354f6b3756d91557 Mon Sep 17 00:00:00 2001 From: R-unic Date: Sat, 30 Sep 2023 22:24:51 -0400 Subject: [PATCH] feat: support enum declarations --- src/code-generator.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/code-generator.ts b/src/code-generator.ts index 706d738..5e78708 100644 --- a/src/code-generator.ts +++ b/src/code-generator.ts @@ -59,6 +59,8 @@ import { ThrowStatement, ModuleDeclaration, ModuleBlock, + EnumDeclaration, + EnumMember, Statement, HeritageClause, SwitchStatement, @@ -469,6 +471,34 @@ export default class CodeGenerator extends StringBuilder { } // CLASS STUFF STATEMENTS + case SyntaxKind.EnumDeclaration: { + const declaration = node; + this.walkModifiers(declaration); + this.append("enum "); + this.walk(declaration.name); + this.pushIndentation(); + this.newLine(); + + for (const member of declaration.members) + this.walk(member); + + this.popIndentation(); + this.newLine(); + this.append("end"); + this.newLine(); + break; + } + case SyntaxKind.EnumMember: { + const member = node; + this.walk(member.name); + if (member.initializer) { + this.append(" = "); + this.walk(member.initializer); + } + + this.newLine(); + break; + } case SyntaxKind.InterfaceDeclaration: { return this.error(node, "Interfaces are not supported.", "UnsupportedInterfaces") }