Skip to content

Commit

Permalink
Fixes #3837
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Jun 13, 2024
1 parent 0913c0c commit 765fdb9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [All] Fixed Fable compiler hanging on some errors (#3842) (by @ncave)
* [JS/TS] Fixed DateTime.MinValue, DateTime.MaxValue (#3836) (by @ncave)
* [JS/TS] Fixed missing field using TypeScriptTaggedUnion (#3837) (by @ncave)

## 4.19.0 - 2024-06-10

Expand Down
5 changes: 3 additions & 2 deletions src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ type FsUnionCase(uci: FSharpUnionCase) =
| _ -> None
)

static member HasNamedFields(uci: FSharpUnionCase) =
not (uci.Fields.Count = 1 && uci.Fields[0].Name = "Item")
// static member HasNamedFields(uci: FSharpUnionCase) =
// not (uci.Fields.Count = 1 && uci.Fields[0].Name = "Item")
// true

interface Fable.UnionCase with
member _.Name = uci.Name
Expand Down
20 changes: 10 additions & 10 deletions src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let private transformNewUnion com ctx r fsType (unionCase: FSharpUnionCase) (arg

| TypeScriptTaggedUnion(_, _, tagName, rule) ->
match argExprs with
| [ argExpr ] when not (FsUnionCase.HasNamedFields unionCase) -> argExpr
// | [ argExpr ] when not (FsUnionCase.HasNamedFields unionCase) -> argExpr
| _ ->
let isCompiledValue, tagExpr =
match FsUnionCase.CompiledValue unionCase with
Expand Down Expand Up @@ -1176,16 +1176,16 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) appliedGenArgs fs

return Fable.Get(unionExpr, Fable.TupleIndex index, fieldType, r)
| TypeScriptTaggedUnion _ ->
if FsUnionCase.HasNamedFields unionCase then
let kind =
Fable.FieldInfo.Create(
FsField.FSharpFieldName field,
fieldType = makeType Map.empty field.FieldType
)
// if not (FsUnionCase.HasNamedFields unionCase) then
// return unionExpr
// else
let kind =
Fable.FieldInfo.Create(
FsField.FSharpFieldName field,
fieldType = makeType Map.empty field.FieldType
)

return Fable.Get(unionExpr, kind, fieldType, r)
else
return unionExpr
return Fable.Get(unionExpr, kind, fieldType, r)
| StringEnum _ ->
return
"StringEnum types cannot have fields"
Expand Down
12 changes: 6 additions & 6 deletions src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,12 @@ module Annotation =
AbstractMember.abstractProperty (prop, tagType, isComputed = isComputed)

match uci.UnionCaseFields with
| [ field ] when field.Name = "Item" ->
IntersectionTypeAnnotation
[|
field.FieldType |> resolveInlineType genArgs |> makeFieldAnnotation com ctx
ObjectTypeAnnotation [| tagMember |]
|]
// | [ field ] when field.Name = "Item" ->
// IntersectionTypeAnnotation
// [|
// field.FieldType |> resolveInlineType genArgs |> makeFieldAnnotation com ctx
// ObjectTypeAnnotation [| tagMember |]
// |]
| fields ->
let names, types =
fields |> List.map (fun fi -> fi.Name, fi.FieldType) |> List.unzip
Expand Down

0 comments on commit 765fdb9

Please sign in to comment.