From 83f64c3f47c95b746b2bb14ef26ee5533e5ed579 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 09:43:56 +0100 Subject: Add body to constructors in TypeScript AST --- .../output/lang/typescript/TypescriptWriterTests.java | 16 ++++++++++++++++ .../ast/TypescriptClassConstructorMatcher.java | 6 ++++++ 2 files changed, 22 insertions(+) (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 690a676..29781b9 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 @@ -161,6 +161,22 @@ public class TypescriptWriterTests { }""")); } + @Test + public void classConstructorWithBody() throws IOException { + var typescript = TypescriptClassConstructor.arbitrary() + .addBodyElement(TypescriptExpressionStatement.arbitrary().withExpression(num(1))) + .addBodyElement(TypescriptExpressionStatement.arbitrary().withExpression(num(2))) + .build(); + + var string = write(writer -> writer.writeClassElement(typescript)); + + assertThat(string, equalTo(""" + constructor() { + 1.0; + 2.0; + }""")); + } + // === Class field declarations === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java index 081372d..7157675 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java @@ -36,6 +36,12 @@ public final class TypescriptClassConstructorMatcher implements org.zwobble.prec return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher withBody(org.zwobble.precisely.Matcher> body) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructor::body, (org.zwobble.precisely.Matcher) body)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher(submatchers); + } + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher body // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher body } -- cgit v1.2.3