From efe3fbdf030badf685fbcc4e98345c183b048ec6 Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Fri, 25 Oct 2024 21:42:51 +0200 Subject: [PATCH 1/2] [JS] Allow `[]` to work on members Fix #3929 --- src/Fable.Cli/CHANGELOG.md | 1 + src/Fable.Transforms/FSharp2Fable.fs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index f2d4e7acf..22e32d739 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [Rust] Added decision tree multiple target references (by @ncave) * [Rust] Added Char surrogate tests for completeness (by @ncave) * [JS] Add `System.String.Normalize` support (by @DashieTM) +* [JS] Allow `[]` to work on members (by @MangelMaxime) ### Fixed diff --git a/src/Fable.Transforms/FSharp2Fable.fs b/src/Fable.Transforms/FSharp2Fable.fs index 68bba6663..b4e46594c 100644 --- a/src/Fable.Transforms/FSharp2Fable.fs +++ b/src/Fable.Transforms/FSharp2Fable.fs @@ -1920,6 +1920,9 @@ let private transformMemberDecl // Ignore members generated by the F# compiler (for comparison and equality) elif isCompilerGenerated memb args then [] + // Ignore members that are decorated with [] + elif hasAttrib Atts.erase memb.Attributes then + [] elif memb.IsOverrideOrExplicitInterfaceImplementation then if not memb.IsCompilerGenerated then match memb.DeclaringEntity with From e311a46327dd93c3b7b102e7afbc7eaaed8e923d Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Fri, 25 Oct 2024 21:58:23 +0200 Subject: [PATCH 2/2] tests: add integration for using `Erase` on members --- .../Integration/Integration/CompilationTests.fs | 2 +- .../Integration/data/eraseAttribute/Members.fs | 15 +++++++++++++++ .../data/eraseAttribute/Members.js.expected | 15 +++++++++++++++ .../data/eraseAttribute/eraseAttribute.fsproj | 17 +++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/Integration/data/eraseAttribute/Members.fs create mode 100644 tests/Integration/Integration/data/eraseAttribute/Members.js.expected create mode 100644 tests/Integration/Integration/data/eraseAttribute/eraseAttribute.fsproj diff --git a/tests/Integration/Integration/CompilationTests.fs b/tests/Integration/Integration/CompilationTests.fs index 1e1930856..7591eb56d 100644 --- a/tests/Integration/Integration/CompilationTests.fs +++ b/tests/Integration/Integration/CompilationTests.fs @@ -10,7 +10,7 @@ let tests = Directory.EnumerateDirectories(data) |> Seq.map (fun testCaseDir -> // testCaseAsync - (Path.GetDirectoryName(testCaseDir)) + testCaseDir (async { let project = Directory.GetFileSystemEntries(testCaseDir, "*.fsproj") |> Seq.exactlyOne diff --git a/tests/Integration/Integration/data/eraseAttribute/Members.fs b/tests/Integration/Integration/data/eraseAttribute/Members.fs new file mode 100644 index 000000000..73b0961ef --- /dev/null +++ b/tests/Integration/Integration/data/eraseAttribute/Members.fs @@ -0,0 +1,15 @@ +module EraseAttributeMembers + +open Fable.Core + +type input() = + + [] + member this.onChange + with set (_: obj -> unit) = () + + +type input with + + [] + member this.onChange2 set (_: obj -> unit) = () diff --git a/tests/Integration/Integration/data/eraseAttribute/Members.js.expected b/tests/Integration/Integration/data/eraseAttribute/Members.js.expected new file mode 100644 index 000000000..756a8a176 --- /dev/null +++ b/tests/Integration/Integration/data/eraseAttribute/Members.js.expected @@ -0,0 +1,15 @@ +import { class_type } from "./fable_modules/fable-library-js.4.22.0/Reflection.js"; + +export class input { + constructor() { + } +} + +export function input_$reflection() { + return class_type("EraseAttributeMembers.input", undefined, input); +} + +export function input_$ctor() { + return new input(); +} + diff --git a/tests/Integration/Integration/data/eraseAttribute/eraseAttribute.fsproj b/tests/Integration/Integration/data/eraseAttribute/eraseAttribute.fsproj new file mode 100644 index 000000000..3fd608576 --- /dev/null +++ b/tests/Integration/Integration/data/eraseAttribute/eraseAttribute.fsproj @@ -0,0 +1,17 @@ + + + + net8.0 + Major + true + + + + + + + + + + +