diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-09-27 10:50:05 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-27 10:50:05 +0100 |
| commit | bfc98eb886211cbe7be00cee8db8e7ca1e6e13f5 (patch) | |
| tree | 0bab5de1ba74b2c57708cf4bf671525f7d6edc8d /src/main | |
| parent | 44bc89a7d3c587d26110983a806f933ac3de4333 (diff) | |
Support type-only exports in TypeScript AST
Diffstat (limited to 'src/main')
3 files changed, 19 insertions, 10 deletions
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 |
