summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-09-04 15:22:06 +0100
committerMichael Williamson <mike@zwobble.org>2026-09-04 15:25:14 +0100
commit94ca8de6bc11f194bdf3a0415aad2eb66e222c45 (patch)
tree691279348a97897379c03d8c5f66ea63333babb1 /src/main/java
parent8b1ee9a26a378a4456e800be314ab765be94b368 (diff)
Add custom code to TypeScript output
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java37
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptCustomArea.java32
2 files changed, 57 insertions, 12 deletions
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 ebb7aba..d177b58 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
@@ -48,20 +48,24 @@ public class TypescriptWriter implements AutoCloseable {
public void writeModule(TypescriptModule module) throws IOException {
this.writer.writeHeader();
- if (module.body().isEmpty()) {
- return;
- }
+ writeCustomArea(new TypescriptCustomArea("imports"));
+ this.writer.newLine();
- writeWithSeparator(
- module.body(),
- this::writeStatement,
- () -> {
- writer.newLine();
- writer.newLine();
- }
- );
+ if (!module.body().isEmpty()) {
+ writeWithSeparator(
+ module.body(),
+ this::writeStatement,
+ () -> {
+ writer.newLine();
+ writer.newLine();
+ }
+ );
- this.writer.newLine();
+ this.writer.newLine();
+ this.writer.newLine();
+ }
+
+ writeCustomArea(new TypescriptCustomArea("body"));
}
// == Statements ==
@@ -117,8 +121,11 @@ public class TypescriptWriter implements AutoCloseable {
}
);
this.writer.newLine();
+ this.writer.newLine();
}
+ writeCustomArea(new TypescriptCustomArea(classDeclaration.name().value() + ", body"));
+
this.writer.dedent();
this.writer.write("}");
}
@@ -440,4 +447,10 @@ public class TypescriptWriter implements AutoCloseable {
private void writeIdentifier(TypescriptIdentifier name) throws IOException {
this.writer.write(name.value());
}
+
+ // == Custom areas ==
+
+ private void writeCustomArea(TypescriptCustomArea customArea) throws IOException {
+ this.writer.writeCustomArea(customArea.name());
+ }
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptCustomArea.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptCustomArea.java
new file mode 100644
index 0000000..cd3fd54
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptCustomArea.java
@@ -0,0 +1,32 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea imports
+
+public record TypescriptCustomArea(
+ String name
+) {
+ public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea.Builder("");
+ }
+
+ public record Builder(
+ String name
+ ) {
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea(name);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea.Builder withName(String name) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea.Builder(name);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCustomArea body
+}