From 93c7437d22224ac72818a4cd4ed4d9beeedaac79 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 13:43:59 +0100 Subject: Add new calls to TypeScript AST --- .../output/lang/typescript/TypescriptWriter.java | 16 +++++++ .../lang/typescript/ast/TypescriptExpression.java | 2 +- .../lang/typescript/ast/TypescriptNewCall.java | 54 ++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNewCall.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 de38ea6..1110e96 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 @@ -228,6 +228,10 @@ public class TypescriptWriter implements AutoCloseable { this.writeFieldAccess(fieldAccess); } + case TypescriptNewCall newCall -> { + this.writeNewCall(newCall); + } + case TypescriptNumberLiteral numberLiteral -> { this.writeNumberLiteral(numberLiteral); } @@ -258,6 +262,18 @@ public class TypescriptWriter implements AutoCloseable { this.writeIdentifier(fieldAccess.fieldName()); } + private void writeNewCall(TypescriptNewCall newCall) throws IOException { + this.writer.write("new "); + this.writeExpression(newCall.receiver()); + this.writer.write("("); + writeWithSeparator( + newCall.args(), + this::writeExpression, + () -> this.writer.write(", ") + ); + this.writer.write(")"); + } + private void writeNumberLiteral(TypescriptNumberLiteral numberLiteral) throws IOException { this.writer.write(Double.toString(numberLiteral.value())); } 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 58dab10..1cf2e81 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.TypescriptFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptRef { +public sealed interface TypescriptExpression permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptBinaryOperation, 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 { 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/TypescriptNewCall.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNewCall.java new file mode 100644 index 0000000..f9305bb --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNewCall.java @@ -0,0 +1,54 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall imports + +public record TypescriptNewCall( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression receiver, + java.util.List args +) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.arbitrary().build(), java.util.List.of()); + } + + public record Builder( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression receiver, + java.util.List args + ) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder withReceiver(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression receiver) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder withReceiver(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder receiver) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder(receiver.build(), args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder withArgs(java.util.List args) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder addArg(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression arg) { + var args = new java.util.ArrayList(this.args); + args.add(arg); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder addArg(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder arg) { + var args = new java.util.ArrayList(this.args); + args.add(arg.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder(receiver, args); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall body +} -- cgit v1.2.3