From 9ae0aa5e9fe3ae8e52c48fc1ad23ee047752ff89 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 31 Aug 2026 23:05:34 +0100 Subject: Add typeof to TypeScript AST --- .../output/lang/typescript/TypescriptWriter.java | 9 ++++++ .../lang/typescript/ast/TypescriptExpression.java | 2 +- .../lang/typescript/ast/TypescriptTypeof.java | 36 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeof.java (limited to 'src/main/java') diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java index 7931855..63e4e72 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java @@ -277,6 +277,10 @@ public class TypescriptWriter implements AutoCloseable { this.writeRef(ref); } + case TypescriptTypeof typeof -> { + this.writeTypeof(typeof); + } + case TypescriptTypeUnion typeUnion -> { this.writeTypeUnion(typeUnion); } @@ -345,6 +349,11 @@ public class TypescriptWriter implements AutoCloseable { this.writeIdentifier(ref.name()); } + private void writeTypeof(TypescriptTypeof typeof) throws IOException { + this.writer.write("typeof "); + this.writeExpression(typeof.expression()); + } + private void writeTypeUnion(TypescriptTypeUnion typeUnion) throws IOException { writeWithSeparator( typeUnion.variants(), diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java index b8e79d3..0e5fe02 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java @@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression imports // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression imports -public sealed interface TypescriptExpression permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptBinaryOperation, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptRef, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion { +public sealed interface TypescriptExpression permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptBinaryOperation, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptRef, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion { public interface Builder { public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression build(); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeof.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeof.java new file mode 100644 index 0000000..7410c1d --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeof.java @@ -0,0 +1,36 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof imports + +public record TypescriptTypeof( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression expression +) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.arbitrary().build()); + } + + public record Builder( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression expression + ) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof(expression); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder withExpression(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression expression) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder(expression); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder withExpression(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder expression) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder(expression.build()); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof body +} -- cgit v1.2.3