summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hobgoblin/src/output/lang/typescript/ast.hob1
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescripttypes/TypescriptTypesGenerator.java8
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java3
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExport.java18
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java7
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExportMatcher.java6
6 files changed, 32 insertions, 11 deletions
diff --git a/hobgoblin/src/output/lang/typescript/ast.hob b/hobgoblin/src/output/lang/typescript/ast.hob
index a363fb0..ca37980 100644
--- a/hobgoblin/src/output/lang/typescript/ast.hob
+++ b/hobgoblin/src/output/lang/typescript/ast.hob
@@ -51,6 +51,7 @@ struct TypescriptExportNamesStatement {
struct TypescriptNamedExport {
field exportName: TypescriptIdentifier;
+ field typeOnly: Bool;
}
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 e80e298..ede1587 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(
- new TypescriptNamedExport(typescriptTypeName)
+ new TypescriptNamedExport(typescriptTypeName, false)
))
)
));
@@ -331,7 +331,7 @@ public class TypescriptTypesGenerator implements Generator {
structDefinition.docComment()
),
new TypescriptExportNamesStatement(List.of(
- new TypescriptNamedExport(typescriptTypeName)
+ new TypescriptNamedExport(typescriptTypeName, false)
))
);
}
@@ -354,10 +354,10 @@ public class TypescriptTypesGenerator implements Generator {
.toList()
)
),
- // TODO: represent type exports properly in AST
new TypescriptExportNamesStatement(List.of(
new TypescriptNamedExport(
- TypescriptIdentifier.of("type " + typescriptTypeName.value())
+ TypescriptIdentifier.of(typescriptTypeName.value()),
+ true
)
))
);
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 764ebe7..b2aa2a9 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
@@ -185,6 +185,9 @@ public class TypescriptWriter implements AutoCloseable {
writeWithSeparator(
exportNamesStatement.exports(),
export -> {
+ if (export.typeOnly()) {
+ this.writer.write("type ");
+ }
this.writeIdentifier(export.exportName());
},
() -> this.writer.write(", ")
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
index 47048c4..d021f46 100644
--- 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
@@ -6,25 +6,31 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast;
// 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
+ org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName,
+ boolean typeOnly
) {
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());
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.arbitrary().build(), false);
}
public record Builder(
- org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName
+ org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier exportName,
+ boolean typeOnly
) {
public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport build() {
- return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport(exportName);
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport(exportName, typeOnly);
}
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);
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder(exportName, typeOnly);
}
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());
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder(exportName.build(), typeOnly);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder withTypeOnly(boolean typeOnly) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder(exportName, typeOnly);
}
// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport.Builder 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 8e7daa4..4963e09 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
@@ -223,11 +223,12 @@ public class TypescriptWriterTests {
var typescript = TypescriptExportNamesStatement.arbitrary()
.addExport(export(id("x")))
.addExport(export(id("y")))
+ .addExport(exportType(id("z")))
.build();
var string = write(writer -> writer.writeStatement(typescript));
- assertThat(string, equalTo("export {x, y};"));
+ assertThat(string, equalTo("export {x, y, type z};"));
}
// === Expression statements ===
@@ -600,6 +601,10 @@ public class TypescriptWriterTests {
return TypescriptNamedExport.arbitrary().withExportName(name).build();
}
+ private static TypescriptNamedExport exportType(TypescriptIdentifier name) {
+ return TypescriptNamedExport.arbitrary().withExportName(name).withTypeOnly(true).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/TypescriptNamedExportMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedExportMatcher.java
index b5d514e..93612fe 100644
--- 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
@@ -36,6 +36,12 @@ public final class TypescriptNamedExportMatcher implements org.zwobble.precisely
return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExportMatcher withTypeOnly(org.zwobble.precisely.Matcher<? super java.lang.Boolean> typeOnly) {
+ 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("typeOnly", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedExport::typeOnly, (org.zwobble.precisely.Matcher) typeOnly));
+ 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
}