diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-31 23:05:34 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-31 23:05:34 +0100 |
| commit | 9ae0aa5e9fe3ae8e52c48fc1ad23ee047752ff89 (patch) | |
| tree | aad16ffcaf395fe1fd0051d552b3617528f11624 /src/main/java | |
| parent | b853399ce5ab5adb1a8899265d106ae1ab96bb35 (diff) | |
Add typeof to TypeScript AST
Diffstat (limited to 'src/main/java')
3 files changed, 46 insertions, 1 deletions
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 +} |
