From 5a15eaebcad9fe95772d7391bb2cc5b1b2a8c0d2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 14:17:09 +0100 Subject: Mark fields as readonly in typescript-types --- .../output/lang/typescript/TypescriptWriterTests.java | 15 ++++++++++++++- .../ast/TypescriptClassFieldDeclarationMatcher.java | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (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 718f6e4..7ca267a 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 @@ -212,7 +212,7 @@ public class TypescriptWriterTests { } @Test - public void staticClassFieldDeclarationWithoutInitialValue() throws IOException { + public void staticClassFieldDeclaration() throws IOException { var typescript = TypescriptClassFieldDeclaration.arbitrary() .withVisibility(TypescriptVisibility.PUBLIC) .withName(id("a")) @@ -224,6 +224,19 @@ public class TypescriptWriterTests { assertThat(string, equalTo("public static a;")); } + @Test + public void readOnlyClassFieldDeclaration() throws IOException { + var typescript = TypescriptClassFieldDeclaration.arbitrary() + .withVisibility(TypescriptVisibility.PUBLIC) + .withName(id("a")) + .withIsReadOnly(true) + .build(); + + var string = write(writer -> writer.writeClassElement(typescript)); + + assertThat(string, equalTo("public readonly a;")); + } + @Test public void classFieldDeclarationWithExplicitType() throws IOException { var typescript = TypescriptClassFieldDeclaration.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java index 62a3f9e..f4afcc8 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java @@ -48,6 +48,12 @@ public final class TypescriptClassFieldDeclarationMatcher implements org.zwobble return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher withIsReadOnly(org.zwobble.precisely.Matcher isReadOnly) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("isReadOnly", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration::isReadOnly, (org.zwobble.precisely.Matcher) isReadOnly)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher withType(org.zwobble.precisely.Matcher> type) { var submatchers = new java.util.ArrayList>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration::type, (org.zwobble.precisely.Matcher) type)); -- cgit v1.2.3