From 9de4242330fe137133327533f24073613da8d201 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 11:16:26 +0100 Subject: Add export names statement to TypeScript AST --- .../output/lang/typescript/TypescriptWriter.java | 18 +++++++++ .../ast/TypescriptExportNamesStatement.java | 44 ++++++++++++++++++++++ .../lang/typescript/ast/TypescriptStatement.java | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatement.java (limited to 'src/main/java') diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java index b2674c6..99ad2e4 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java @@ -72,6 +72,10 @@ public class TypescriptWriter implements AutoCloseable { this.writeClassDeclaration(classDeclaration); } + case TypescriptExportNamesStatement exportNamesStatement -> { + this.writeExportNamesStatement(exportNamesStatement); + } + case TypescriptExpressionStatement expressionStatement -> { this.writeExpressionStatement(expressionStatement); } @@ -102,6 +106,20 @@ public class TypescriptWriter implements AutoCloseable { this.writer.write("}"); } + private void writeExportNamesStatement( + TypescriptExportNamesStatement exportNamesStatement + ) throws IOException { + this.writer.write("export {"); + + writeWithSeparator( + exportNamesStatement.names(), + this::writeIdentifier, + () -> this.writer.write(", ") + ); + + this.writer.write("};"); + } + private void writeExpressionStatement( TypescriptExpressionStatement expressionStatement ) throws IOException { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatement.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatement.java new file mode 100644 index 0000000..4912f68 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatement.java @@ -0,0 +1,44 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement imports + +public record TypescriptExportNamesStatement( + java.util.List names +) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(java.util.List.of()); + } + + public record Builder( + java.util.List names + ) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement(names); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder withNames(java.util.List names) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(names); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder addName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier name) { + var names = new java.util.ArrayList(this.names); + names.add(name); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(names); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder addName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.Builder name) { + var names = new java.util.ArrayList(this.names); + names.add(name.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(names); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement body +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptStatement.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptStatement.java index 9a47c84..6d24493 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptStatement.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptStatement.java @@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement imports // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement imports -public sealed interface TypescriptStatement permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpressionStatement { +public sealed interface TypescriptStatement permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpressionStatement { public interface Builder { public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement build(); -- cgit v1.2.3