Skip to content

Commit

Permalink
[JS/TS] Don't generate the setter code if a property is decorated wit…
Browse files Browse the repository at this point in the history
…h `[<Erase>]`

Fix #3948

c
  • Loading branch information
MangelMaxime committed Jan 2, 2025
1 parent b4eb58f commit 7425ce1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [TS] Make discriminated union `.Is*` properties works (@MangelMaxime)
* [JS/TS/Python] Fix `h` in `DateTime.ToString` (@MangelMaxime)
* [JS/TS] Fix `hh` in `DateTime.ToString` (@MangelMaxime)
* [JS/TS] Don't generate the setter code if a property is decorated with `[<Erase>]` (@MangelMaxime)

## 5.0.0-alpha.3 - 2024-12-18

Expand Down
9 changes: 8 additions & 1 deletion src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,14 @@ let private transformMemberDecl
elif isCompilerGenerated memb args then
[]
// Ignore members that are decorated with [<Erase>]
elif hasAttrib Atts.erase memb.Attributes then
elif
hasAttrib Atts.erase memb.Attributes
// Attributes are not universally propagated so for setter properties we need
// to check the declaring entity, https://github.com/fable-compiler/Fable/issues/3948
|| (memb.IsPropertySetterMethod
&& memb.DeclaringEntity.IsSome
&& hasAttrib Atts.erase memb.DeclaringEntity.Value.Attributes)
then
[]
elif memb.IsOverrideOrExplicitInterfaceImplementation then
if not memb.IsCompilerGenerated then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ErasedTypeWithProperty

open Fable.Core

[<Erase>]
type internal LanguageInjectionAttribute() =

[<Erase>]
member val Prefix = "" with get, set

// Force Fable to generate a file, otherwise because everything is erased, it will not generate anything
let a = 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

export const a = 0;

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<Compile Include="Members.fs" />
<Compile Include="ErasedTypeWithProperty.fs" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 7425ce1

Please sign in to comment.