diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-30 17:20:02 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-30 17:20:02 +0100 |
| commit | 075435ee62dfe934de840d60ee71dcfef7aea654 (patch) | |
| tree | bbe96436b64219d9735a2447da64c1ce12566897 /src | |
| parent | 743fa1538dbf767a619be51db09a88146bd86c8c (diff) | |
Support Box and Shared in typescript-types
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java index 3832f35..c26b73d 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java @@ -1,5 +1,6 @@ package org.zwobble.hobgoblin.compiler.output.generators.typescript; +import org.zwobble.hobgoblin.compiler.builtins.NativeTypes; import org.zwobble.hobgoblin.compiler.output.lang.typescript.TypescriptWriter; import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.*; import org.zwobble.hobgoblin.compiler.types.*; @@ -41,7 +42,7 @@ public class TypescriptGenerator { } public TypescriptExpression generateTypeExpression(Type value) { - return switch (value) { + return switch (collapseType(value)) { case ConstructedType constructedType -> { yield new TypescriptConstructedType( generateTypeExpression(constructedType.constructor().genericType()), @@ -71,4 +72,19 @@ public class TypescriptGenerator { } }; } + + public Type collapseType(Type type) { + if (!(type instanceof ConstructedNativeType constructedNativeType)) { + return type; + } + + if ( + !constructedNativeType.constructor().equals(NativeTypes.SHARED) && + !constructedNativeType.constructor().equals(NativeTypes.BOX) + ) { + return type; + } + + return constructedNativeType.args().getFirst(); + } } |
