From 9ae0aa5e9fe3ae8e52c48fc1ad23ee047752ff89 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 31 Aug 2026 23:05:34 +0100 Subject: Add typeof to TypeScript AST --- .../lang/typescript/TypescriptWriterTests.java | 13 +++++++ .../typescript/ast/TypescriptTypeofMatcher.java | 41 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeofMatcher.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 b6f666e..8348743 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 @@ -432,6 +432,19 @@ public class TypescriptWriterTests { assertThat(string, equalTo("x")); } + // === typeof === + + @Test + public void typeof() throws IOException { + var typescript = TypescriptTypeof.arbitrary() + .withExpression(ref("x")) + .build(); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("typeof x")); + } + // === Type unions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeofMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeofMatcher.java new file mode 100644 index 0000000..88feb0b --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeofMatcher.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.TypescriptTypeofMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeofMatcher imports + +public final class TypescriptTypeofMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeofMatcher isTypescriptTypeof() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeofMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptTypeofMatcher( + 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.TypescriptTypeof.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeofMatcher withExpression(org.zwobble.precisely.Matcher expression) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("expression", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof::expression, (org.zwobble.precisely.Matcher) expression)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeofMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeofMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeofMatcher body +} -- cgit v1.2.3