diff options
8 files changed, 116 insertions, 23 deletions
diff --git a/hobgoblin/src/output/lang/typescript/ast.hob b/hobgoblin/src/output/lang/typescript/ast.hob index 8a254b6..a363fb0 100644 --- a/hobgoblin/src/output/lang/typescript/ast.hob +++ b/hobgoblin/src/output/lang/typescript/ast.hob @@ -46,7 +46,11 @@ struct TypescriptConstDeclaration { } struct TypescriptExportNamesStatement { - field names: List[TypescriptIdentifier]; + field exports: List[TypescriptNamedExport]; +} + +struct TypescriptNamedExport { + field exportName: TypescriptIdentifier; } struct TypescriptExpressionStatement { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java index 293143c..e80e298 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java @@ -205,7 +205,7 @@ public class TypescriptTypesGenerator implements Generator { ) ), new TypescriptExportNamesStatement(List.of( - typescriptTypeName + new TypescriptNamedExport(typescriptTypeName) )) ) )); @@ -330,7 +330,9 @@ public class TypescriptTypesGenerator implements Generator { body, structDefinition.docComment() ), - new TypescriptExportNamesStatement(List.of(typescriptTypeName)) + new TypescriptExportNamesStatement(List.of( + new TypescriptNamedExport(typescriptTypeName) + )) ); } @@ -353,7 +355,11 @@ public class TypescriptTypesGenerator implements Generator { ) ), // TODO: represent type exports properly in AST - new TypescriptExportNamesStatement(List.of(TypescriptIdentifier.of("type " + typescriptTypeName.value()))) + new TypescriptExportNamesStatement(List.of( + new TypescriptNamedExport( + TypescriptIdentifier.of("type " + typescriptTypeName.value()) + ) + )) ); } 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 18a2475..764ebe7 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 @@ -183,8 +183,10 @@ public class TypescriptWriter implements AutoCloseable { this.writer.write("export {"); writeWithSeparator( - exportNamesStatement.names(), - this::writeIdentifier, + exportNamesStatement.exports(), + export -> { + this.writeIdentifier(export.exportName()); + }, () -> this.writer.write(", ") ); 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 index 4912f68..580ab1b 100644 --- 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 @@ -6,33 +6,33 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement imports public record TypescriptExportNamesStatement( - java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> names + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport> exports ) 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<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> names + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport> exports ) 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); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement(exports); } - public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder withNames(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> 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 withExports(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport> exports) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(exports); } - 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<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier>(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 addExport(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport export) { + var exports = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport>(this.exports); + exports.add(export); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(exports); } - 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<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier>(this.names); - names.add(name.build()); - return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(names); + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder addExport(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder export) { + var exports = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport>(this.exports); + exports.add(export.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder(exports); } // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.Builder body diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExport.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExport.java new file mode 100644 index 0000000..47048c4 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExport.java @@ -0,0 +1,36 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport imports + +public record TypescriptNamedExport( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName +) { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.arbitrary().build()); + } + + public record Builder( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName + ) { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport(exportName); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder withExportName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder(exportName); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder withExportName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.Builder exportName) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder(exportName.build()); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport body +} 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 ff10ffe..8e7daa4 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 @@ -221,8 +221,8 @@ public class TypescriptWriterTests { @Test public void exportNamesStatement() throws IOException { var typescript = TypescriptExportNamesStatement.arbitrary() - .addName(id("x")) - .addName(id("y")) + .addExport(export(id("x"))) + .addExport(export(id("y"))) .build(); var string = write(writer -> writer.writeStatement(typescript)); @@ -596,6 +596,10 @@ public class TypescriptWriterTests { // == Utilities == + private static TypescriptNamedExport export(TypescriptIdentifier name) { + return TypescriptNamedExport.arbitrary().withExportName(name).build(); + } + private static TypescriptIdentifier id(String name) { return TypescriptIdentifier.of(name); } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatementMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatementMatcher.java index 0acb02f..6d1bdb6 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatementMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExportNamesStatementMatcher.java @@ -30,9 +30,9 @@ public final class TypescriptExportNamesStatementMatcher implements org.zwobble. return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement.class, this.submatchers); } - public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatementMatcher withNames(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier>> names) { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatementMatcher withExports(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport>> exports) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement>>(this.submatchers); - submatchers.add(org.zwobble.precisely.Matchers.has("names", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement::names, (org.zwobble.precisely.Matcher) names)); + submatchers.add(org.zwobble.precisely.Matchers.has("exports", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatement::exports, (org.zwobble.precisely.Matcher) exports)); return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExportNamesStatementMatcher(submatchers); } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExportMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExportMatcher.java new file mode 100644 index 0000000..b5d514e --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExportMatcher.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.TypescriptNamedExportMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher imports + +public final class TypescriptNamedExportMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher isTypescriptNamedExport() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport>> submatchers; + + private TypescriptNamedExportMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport>> 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<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher withExportName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> exportName) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("exportName", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport::exportName, (org.zwobble.precisely.Matcher) exportName)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher body +} |
