summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-09-04 09:40:50 +0100
committerMichael Williamson <mike@zwobble.org>2026-09-04 09:40:50 +0100
commit8dd50423a53f87f15464c467874684300b129ba8 (patch)
tree8474f64e0494216f8f983506ed7bffd8aed07778 /src/main/java
parent57f8396dd1c92e87be342d35880f1ca04a5a6c53 (diff)
Add object literal to TypeScript AST
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java23
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteral.java44
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteralProperty.java46
4 files changed, 114 insertions, 1 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 63e4e72..7719474 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
@@ -273,6 +273,10 @@ public class TypescriptWriter implements AutoCloseable {
this.writeNumberLiteral(numberLiteral);
}
+ case TypescriptObjectLiteral objectLiteral -> {
+ this.writeObjectLiteral(objectLiteral);
+ }
+
case TypescriptRef ref -> {
this.writeRef(ref);
}
@@ -345,6 +349,25 @@ public class TypescriptWriter implements AutoCloseable {
this.writer.write(Double.toString(numberLiteral.value()));
}
+ private void writeObjectLiteral(TypescriptObjectLiteral objectLiteral) throws IOException {
+ this.writer.write("{");
+
+ if (!objectLiteral.properties().isEmpty()) {
+ this.writer.indent();
+ for (var property : objectLiteral.properties()) {
+ this.writer.newLine();
+ this.writeIdentifier(property.name());
+ this.writer.write(": ");
+ this.writeExpression(property.value());
+ this.writer.write(",");
+ }
+ this.writer.dedent();
+ this.writer.newLine();
+ }
+
+ this.writer.write("}");
+ }
+
private void writeRef(TypescriptRef ref) throws IOException {
this.writeIdentifier(ref.name());
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java
index 0e5fe02..e047bca 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.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.TypescriptExpression imports
// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression imports
-public sealed interface TypescriptExpression permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptBinaryOperation, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptRef, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion {
+public sealed interface TypescriptExpression permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptBinaryOperation, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptRef, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeof, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion {
public interface Builder {
public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression build();
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteral.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteral.java
new file mode 100644
index 0000000..a051986
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteral.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.TypescriptObjectLiteral imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral imports
+
+public record TypescriptObjectLiteral(
+ java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty> properties
+) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression {
+ public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder(java.util.List.of());
+ }
+
+ public record Builder(
+ java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty> properties
+ ) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral(properties);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder withProperties(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty> properties) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder(properties);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder addPropertie(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty propertie) {
+ var properties = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty>(this.properties);
+ properties.add(propertie);
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder(properties);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder addPropertie(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder propertie) {
+ var properties = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty>(this.properties);
+ properties.add(propertie.build());
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder(properties);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteral body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteralProperty.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteralProperty.java
new file mode 100644
index 0000000..984eb19
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptObjectLiteralProperty.java
@@ -0,0 +1,46 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty imports
+
+public record TypescriptObjectLiteralProperty(
+ org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier name,
+ org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression value
+) {
+ public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.arbitrary().build(), org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.arbitrary().build());
+ }
+
+ public record Builder(
+ org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier name,
+ org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression value
+ ) {
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty(name, value);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder withName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier name) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder(name, value);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder withName(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.Builder name) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder(name.build(), value);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder withValue(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression value) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder(name, value);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder withValue(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder value) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder(name, value.build());
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptObjectLiteralProperty body
+}