diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index f2d4e7acf2..22e32d7392 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 68bba6663e..b4e46594c1 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 diff --git a/tests/Integration/Integration/CompilationTests.fs b/tests/Integration/Integration/CompilationTests.fs index 1e1930856c..7591eb56de 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 0000000000..73b0961ef4 --- /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 0000000000..756a8a1767 --- /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 0000000000..3fd6085760 --- /dev/null +++ b/tests/Integration/Integration/data/eraseAttribute/eraseAttribute.fsproj @@ -0,0 +1,17 @@ + + + + net8.0 + Major + true + + + + + + + + + + +