Skip to content

Commit

Permalink
Add test case with scalar struct field and constant value
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Sep 13, 2023
1 parent 666c010 commit 3af16d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/jennies/typescript/rawtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func formatType(def ast.Type, typesPkg string) string {
case ast.KindEnum:
return formatAnonymousEnum(def.AsEnum())
case ast.KindScalar:
// This scalar actually refers to a constant
if def.AsScalar().Value != nil {
return formatScalar(def.AsScalar().Value)
}

return formatScalarKind(def.AsScalar().ScalarKind)

default:
Expand Down
9 changes: 9 additions & 0 deletions testdata/jennies/rawtypes/struct_with_scalar_fields.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
"Scalar": {"ScalarKind": "string"}
}
},
{
"Name": "FieldStringWithConstantValue",
"Required": true,
"Type": {
"Kind": "scalar",
"Scalar": {"ScalarKind": "string", "Value": "auto"}
}
},

{
"Name": "FieldFloat32",
Expand Down Expand Up @@ -146,6 +154,7 @@ export interface SomeStruct {
fieldBool: boolean;
fieldBytes: string;
fieldString: string;
fieldStringWithConstantValue: "auto";
fieldFloat32: number;
fieldFloat64: number;
fieldUint8: number;
Expand Down

0 comments on commit 3af16d6

Please sign in to comment.