From b27ce73f66a025ce16d7158c0283fff7b3bf7f1a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 09:47:50 +0100 Subject: Add field accesses to TypeScript AST --- .../lang/typescript/TypescriptWriterTests.java | 14 +++++++ .../ast/TypescriptFieldAccessMatcher.java | 47 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptFieldAccessMatcher.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 29781b9..5c32084 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 @@ -248,6 +248,20 @@ public class TypescriptWriterTests { assertThat(string, equalTo("x = 42.0")); } + // === Field accesses === + + @Test + public void fieldAccess() throws IOException { + var typescript = TypescriptFieldAccess.arbitrary() + .withReceiver(ref("x")) + .withFieldName(id("y")) + .build(); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("x.y")); + } + // === Number literals === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptFieldAccessMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptFieldAccessMatcher.java new file mode 100644 index 0000000..974f485 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptFieldAccessMatcher.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.TypescriptFieldAccessMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher imports + +public final class TypescriptFieldAccessMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher isTypescriptFieldAccess() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptFieldAccessMatcher( + 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.TypescriptFieldAccess.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher 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.TypescriptFieldAccess::receiver, (org.zwobble.precisely.Matcher) receiver)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher withFieldName(org.zwobble.precisely.Matcher fieldName) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("fieldName", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccess::fieldName, (org.zwobble.precisely.Matcher) fieldName)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccessMatcher body +} -- cgit v1.2.3