Skip to content

Commit

Permalink
[JS/TS] Rename PojoDefinedByConsArgs attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Feb 15, 2025
1 parent 1884dd2 commit c2e7c78
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
36 changes: 24 additions & 12 deletions src/Fable.Core/Fable.Core.JS.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,30 @@ module JSX =
let nothing: Element = nativeOnly

module JS =
type PojoDefinedByConsArgsAttribute() =
/// <summary>
/// Constructor calls to class decorated with this attribute will be compiled as JS pojos defined by the constructor arguments.
/// The class declaration will be erased, but in Typescript an interface will be generated.
/// </summary>
/// <example>
/// <code>
/// [&lt;Pojo&gt;]
/// type Person(name: string, ?age: int) =
/// member val name = name
/// member val age = age
///
/// let p = Person("Alice")
///
/// // Typescript
/// export interface Person {
/// name: string,
/// age?: number
/// }
///
/// export const p: Person = { name: "Alice" }
/// </code>
/// </example>
[<AttributeUsage(AttributeTargets.Class, AllowMultiple = false)>]
type PojoAttribute() =
inherit Attribute()

/// Used to remove the arguments of a surrounding function immediately calling a function decorated with this argument.
Expand Down Expand Up @@ -112,17 +135,6 @@ module JS =
/// that is representable as a Number value, which is approximately:
/// 2.2204460492503130808472633361816 x 10‍−‍16.
abstract EPSILON: float
/// <summary>
/// Returns true if passed value is finite.
/// Unlike the global isFinite, Number.isFinite doesn't forcibly convert the parameter to a
/// number. Only finite values of the type number, result in true.
/// </summary>
/// <param name="number">A numeric value.</param>
abstract isFinite: number: obj -> bool
/// <summary>Returns true if the value passed is an integer, false otherwise.</summary>
/// <param name="number">A numeric value.</param>
abstract isInteger: number: obj -> bool
/// <summary>
/// Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
/// number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
/// to a number. Only values of the type number, that are also NaN, result in true.
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ module Util =
let moduleOrClassExpr =
match tryGlobalOrImportedFSharpEntity com e with
| Some expr -> Some expr
// AttachMembers/PojoDefinedByConsArgs classes behave
// AttachMembers/Pojo classes behave
// the same as global/imported classes
| None when
com.Options.Language <> Rust
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Transforms.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module Atts =
let global_ = "Fable.Core.GlobalAttribute" // typeof<Fable.Core.GlobalAttribute>.FullName

[<Literal>]
let pojoDefinedByConsArgs = "Fable.Core.JS.PojoDefinedByConsArgsAttribute" // typeof<Fable.Core.JS.PojoDefinedByConsArgsAttribute>.FullName
let pojoDefinedByConsArgs = "Fable.Core.JS.PojoAttribute" // typeof<Fable.Core.JS.PojoAttribute>.FullName

[<Literal>]
let emit = "Fable.Core.Emit"
Expand Down
Binary file modified src/fable-metadata/lib/Fable.Core.dll
Binary file not shown.
12 changes: 4 additions & 8 deletions tests/Js/Main/JsInteropTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -319,27 +319,23 @@ module TaggedUnion =
module PojoDefinedByConsArgs =
open Fable.Core.JS

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

[<AllowNullLiteral>]
[<PojoDefinedByConsArgs>]
[<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

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

[<AllowNullLiteral>]
[<PojoDefinedByConsArgs>]
[<Pojo; AllowNullLiteral>]
type UserBag<'ExtraData> private () =
inherit BaseBag<int>()
new ( bag : int, data: 'ExtraData, ?userId : int) = UserBag()
Expand Down

0 comments on commit c2e7c78

Please sign in to comment.