Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [TS] Correctly resolve type references for `TypeScriptTaggedUnion` (by @MangelMaxime and @jrwone0)
* [TS] Expose optional `stack` property on `Exception` (by @MangelMaxime)
* [Python] Fix `nonlocal`/`global` declarations generated inside `match/case` bodies causing `SyntaxError` (by @dbrattli)
* [Python] Fix exception variable captured in deferred closures causing `NameError` (PEP 3110 scoping) (by @dbrattli)
Expand Down
1 change: 1 addition & 0 deletions src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [TS] Correctly resolve type references for `TypeScriptTaggedUnion` (by @MangelMaxime and @jrwone0)
* [Python] Fix `nonlocal`/`global` declarations generated inside `match/case` bodies causing `SyntaxError` (by @dbrattli)
* [Python] Fix exception variable captured in deferred closures causing `NameError` (PEP 3110 scoping) (by @dbrattli)

Expand Down
17 changes: 10 additions & 7 deletions src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ let private transformNewUnion com ctx r fsType (unionCase: FSharpUnionCase) (arg

let fieldTypes = makeTypeGenArgs ctx.GenericArgs fieldTypes

Fable.NewAnonymousRecord(
tagExpr :: argExprs,
Array.append [| tagName |] fieldNames,
tagExpr.Type :: fieldTypes,
false
)
|> makeValue r
let expr =
Fable.NewAnonymousRecord(
tagExpr :: argExprs,
Array.append [| tagName |] fieldNames,
tagExpr.Type :: fieldTypes,
false
)
|> makeValue r

Fable.TypeCast(expr, makeType ctx.GenericArgs fsType)

| StringEnum(tdef, rule) ->
match argExprs with
Expand Down
33 changes: 33 additions & 0 deletions tests/Js/Main/JsInteropTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ module TaggedUnion =
| [<CompiledValue(Kind.Bar)>] Bar of Bar<Kind>
| [<CompiledValue(Kind.Baz)>] Baz of Baz<Kind>


[<RequireQualifiedAccess>]
[<TypeScriptTaggedUnion("type")>]
type SimpleFoo =
| Bar of baz: int

[<RequireQualifiedAccess>]
[<TypeScriptTaggedUnion("type")>]
type FooGeneric<'a> =
| Bar of baz: 'a

#if FABLE_COMPILER
module PojoDefinedByConsArgs =
[<JS.Pojo; AllowNullLiteral>]
Expand Down Expand Up @@ -960,6 +971,28 @@ let tests =
TaggedUnion.EnumTagged.Foo !!{| kind = TaggedUnion.Kind.Foo; foo = "hello" |} |> describe |> equal "foo: hello"
TaggedUnion.EnumTagged.Bar !!{| kind = TaggedUnion.Kind.Bar; bar = 42 |} |> describe |> equal "bar: 42"
TaggedUnion.EnumTagged.Baz !!{| kind = TaggedUnion.Kind.Baz; baz = false |} |> describe |> equal "baz: false"

// Fix https://github.com/fable-compiler/Fable/issues/4378
testCase "TypeScriptTaggedUnion produce the correct return type for a function" <| fun () ->
let getFoo (baz: int) =
(TaggedUnion.SimpleFoo.Bar baz)

let foo = getFoo 10

equal (TaggedUnion.SimpleFoo.Bar 10) foo

testCase "TypeScriptTaggedUnion produce the correct type for a value" <| fun () ->
let foo1 = TaggedUnion.SimpleFoo.Bar 10

equal (TaggedUnion.SimpleFoo.Bar 10) foo1

testCase "TypeScriptTaggedUnion produce the type even with generic type parameters" <| fun () ->
let getFooGeneric (baz: 'a) : TaggedUnion.FooGeneric<'a> =
(TaggedUnion.FooGeneric.Bar baz)

let fooGeneric = getFooGeneric 10

equal (TaggedUnion.FooGeneric.Bar 10) fooGeneric
#endif

testCase "Pattern matching with StringEnum works" <| fun () ->
Expand Down
Loading