From 119324389887cf76e7e0f52bcb9c1067ede463d4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 15:16:58 +0100 Subject: Add type parameters to class declaration in TypeScript AST --- .../lang/typescript/TypescriptWriterTests.java | 17 +++++++++ .../ast/TypescriptClassDeclarationMatcher.java | 6 ++++ .../typescript/ast/TypescriptTypeParamMatcher.java | 41 ++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.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 2606dd4..81dd965 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 @@ -71,6 +71,23 @@ public class TypescriptWriterTests { )); } + @Test + public void classDeclarationWithTypeParams() throws IOException { + var typescript = TypescriptClassDeclaration.arbitrary() + .withName(id("X")) + .addTypeParam(TypescriptTypeParam.arbitrary().withName(id("Y"))) + .addTypeParam(TypescriptTypeParam.arbitrary().withName(id("Z"))) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo(""" + class X { + }""" + )); + } + + @Test public void classDeclarationWithElements() throws IOException { var typescript = TypescriptClassDeclaration.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java index 46eeaa2..188df2d 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java @@ -36,6 +36,12 @@ public final class TypescriptClassDeclarationMatcher implements org.zwobble.prec return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher withTypeParams(org.zwobble.precisely.Matcher> typeParams) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("typeParams", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration::typeParams, (org.zwobble.precisely.Matcher) typeParams)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher 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.TypescriptClassDeclaration::body, (org.zwobble.precisely.Matcher) body)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.java new file mode 100644 index 0000000..635fa27 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.java @@ -0,0 +1,41 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher imports + +public final class TypescriptTypeParamMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher isTypescriptTypeParam() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptTypeParamMatcher( + 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.TypescriptTypeParam.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher 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.TypescriptTypeParam::name, (org.zwobble.precisely.Matcher) name)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher body +} -- cgit v1.2.3