Skip to content

Commit

Permalink
[JS/TS] Fix regression, generate let variable when using import o…
Browse files Browse the repository at this point in the history
…n a private mutable variable (#3941)
  • Loading branch information
MangelMaxime authored Oct 25, 2024
1 parent fa17df3 commit 94cf161
Show file tree
Hide file tree
Showing 5 changed files with 35 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 @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [Rust] Fixed try finally handler order of execution (by @ncave)
* [JS/TS/Python/Rust] Fixed String.StartsWith/EndsWith (#3934) (by @ncave)
* [All/Rust] Removed Regex.Replace from hot paths (by @ncave)
* [JS] Fix regression, generate `let` variable when using `import` on a private mutable variable (by @MangelMaxime)

## 4.22.0 - 2024-10-02

Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ let private transformImportValue com r typ name (memb: FSharpMemberOrFunctionOrV
"Imported members cannot be mutable and public, please make it private: " + name
|> addError com [] None

let memberRef = Fable.GeneratedMember.Value(name, typ)
let memberRef = Fable.GeneratedMember.Value(name, typ, isMutable = memb.IsMutable)
transformImport com r typ name [] memberRef selector path

let private transformMemberValue
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/Integration/data/import/PrivateMutableImport.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module PrivateMutableImport

open Fable.Core.JsInterop

type ToastrOptions =
abstract Thing : string with get, set

[<RequireQualifiedAccess>]
module Toastr =
let mutable private theOptions: ToastrOptions =
//()
import "path" "toastr"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { path } from "toastr";

export let Toastr_theOptions = path;

17 changes: 17 additions & 0 deletions tests/Integration/Integration/data/import/import.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RollForward>Major</RollForward>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="PrivateMutableImport.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fable.Core" Version="4.2.0" />
</ItemGroup>

</Project>

0 comments on commit 94cf161

Please sign in to comment.