From 4bf4004fc90073d816d1431df5bc5845547b814e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 4 Sep 2026 09:47:27 +0100 Subject: Add const declaration to TypeScript AST --- .../lang/typescript/TypescriptWriterTests.java | 27 +++++++++++ .../ast/TypescriptConstDeclarationMatcher.java | 53 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstDeclarationMatcher.java (limited to 'src/test/java/org') 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 b45e5c4..5a7c488 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 @@ -133,6 +133,33 @@ public class TypescriptWriterTests { )); } + // === Class declarations === + + @Test + public void constDeclarationWithoutExplicitType() throws IOException { + var typescript = TypescriptConstDeclaration.arbitrary() + .withName(id("x")) + .withValue(num(42)) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo("const x = 42.0;")); + } + + @Test + public void constDeclarationWithExplicitType() throws IOException { + var typescript = TypescriptConstDeclaration.arbitrary() + .withName(id("x")) + .withType(ref("number")) + .withValue(num(42)) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo("const x: number = 42.0;")); + } + // === Export statements === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstDeclarationMatcher.java new file mode 100644 index 0000000..278d885 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstDeclarationMatcher.java @@ -0,0 +1,53 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher imports + +public final class TypescriptConstDeclarationMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher isTypescriptConstDeclaration() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptConstDeclarationMatcher( + 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.TypescriptConstDeclaration.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher withName(org.zwobble.precisely.Matcher name) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration::name, (org.zwobble.precisely.Matcher) name)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher 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.TypescriptConstDeclaration::type, (org.zwobble.precisely.Matcher) type)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher withValue(org.zwobble.precisely.Matcher value) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration::value, (org.zwobble.precisely.Matcher) value)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher body +} -- cgit v1.2.3