From 3a6771834e55a64c04337bb0ee83fbfc57524edf Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 15:07:22 +0100 Subject: Add constructed types to TypeScript AST --- .../lang/typescript/TypescriptWriterTests.java | 15 +++++++ .../ast/TypescriptConstructedTypeMatcher.java | 47 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstructedTypeMatcher.java (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java index 7ca267a..2606dd4 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java @@ -298,6 +298,21 @@ public class TypescriptWriterTests { assertThat(string, equalTo("x = 42.0")); } + // === Constructed types === + + @Test + public void constructedType() throws IOException { + var typescript = TypescriptConstructedType.arbitrary() + .withReceiver(ref("A")) + .addArg(ref("B")) + .addArg(ref("C")) + .build(); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("A")); + } + // === Field accesses === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstructedTypeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstructedTypeMatcher.java new file mode 100644 index 0000000..98a206e --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstructedTypeMatcher.java @@ -0,0 +1,47 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher imports + +public final class TypescriptConstructedTypeMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher isTypescriptConstructedType() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptConstructedTypeMatcher( + java.util.List> submatchers + ) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher withReceiver(org.zwobble.precisely.Matcher receiver) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("receiver", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType::receiver, (org.zwobble.precisely.Matcher) receiver)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher withArgs(org.zwobble.precisely.Matcher> args) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("args", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType::args, (org.zwobble.precisely.Matcher) args)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedTypeMatcher body +} -- cgit v1.2.3