Skip to content

Commit

Permalink
[JS/TS] Fix #4025: No reflection for pojos (#4048)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxime Mangel <[email protected]>
  • Loading branch information
alfonsogarciacaro and MangelMaxime authored Feb 19, 2025
1 parent b1541eb commit 5271a71
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
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

* [JS/TS] Fix #4025: No reflection info for pojos (by @alfonsogarciacaro)
* [JS/TS] Fix #4049: decimal/bigint to integer conversion checks (by @ncave)

## 5.0.0-alpha.10 - 2025-02-16
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

* [JS/TS] Fix #4025: No reflection info for pojos (by @alfonsogarciacaro)
* [JS/TS] Fix #4049: decimal/bigint to integer conversion checks (by @ncave)

## 5.0.0-alpha.10 - 2025-02-16
Expand Down
5 changes: 4 additions & 1 deletion src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ module Reflection =
|> List.toArray

match com.GetEntity(entRef) with
| Patterns.Try (Util.tryFindAnyEntAttribute [ Atts.stringEnum; Atts.erase; Atts.tsTaggedUnion ]) (att, _) as ent ->
| Patterns.Try (Util.tryFindAnyEntAttribute [ Atts.stringEnum
Atts.erase
Atts.tsTaggedUnion
Atts.pojoDefinedByConsArgs ]) (att, _) as ent ->
match att with
| Atts.stringEnum -> primitiveTypeInfo "string"
| Atts.erase ->
Expand Down
25 changes: 19 additions & 6 deletions tests/Js/Main/JsInteropTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,27 @@ module TaggedUnion =

#if FABLE_COMPILER
module PojoDefinedByConsArgs =
open Fable.Core.JS

[<Pojo; AllowNullLiteral>]
[<JS.Pojo; AllowNullLiteral>]
type Person( name : string ) =
member val name = name

[<Pojo; AllowNullLiteral>]
[<JS.Pojo; AllowNullLiteral>]
type User( id: int, name: string, ?age: int ) =
inherit Person(name)
member val id = id
member val age = age with get, set
member val name = name

[<Pojo; AllowNullLiteral>]
type Team = {
Leader: User
}

[<JS.Pojo; AllowNullLiteral>]
type BaseBag<'T>() =
new ( bag : 'T) = BaseBag()
member val bag: 'T = jsNative

[<Pojo; AllowNullLiteral>]
[<JS.Pojo; AllowNullLiteral>]
type UserBag<'ExtraData> private () =
inherit BaseBag<int>()
new ( bag : int, data: 'ExtraData, ?userId : int) = UserBag()
Expand Down Expand Up @@ -382,6 +384,17 @@ module PojoDefinedByConsArgs =
user.age |> equal None
user.age <- Some 42
user.age |> equal (Some 42)

testCase "Declared types can reference Pojo class" <| fun _ ->
let expected = [|"Fable.Tests.JsInterop.PojoDefinedByConsArgs.User"|]

FSharp.Reflection.FSharpType.GetRecordFields typeof<Team>
|> Array.map (fun f -> f.PropertyType.FullName)
|> equal expected

FSharp.Reflection.FSharpType.GetRecordFields typeof<{| Leader: User |}>
|> Array.map (fun f -> f.PropertyType.FullName)
|> equal expected
]
#endif

Expand Down

0 comments on commit 5271a71

Please sign in to comment.