Skip to content

Regression in Fable 3 when emitting functions via Emit attribute #2249

@inosik

Description

@inosik

Description

There's a regression in Fable 3, when the Emit attribute is used to emit a function. This was reported by @atheck. I reduced the repro sample.

The original code emits a non-trivial function with the Emit attribute, which might be a "happens to work, but never actually supported" thing, so feel free to close this.

Repro code

open Fable.Core

[<Emit "return $0">]
let id (x : 'a) : 'a = jsNative

let x = id 42

REPL

Expected and actual results

This is what we get in the REPL:

export const x = function () {
  return 42;
}();

And this is what we get with Fable 3:

export const x = return 42;

In Fable 2, Babel might have recognized this and wrapped it in an IIFE by itself. In Fable 3 however, we don't use Babel anymore, so that's probably why this regressed.

In Fable.Core 4, the Emit attribute has an additional parameter isStatement, added in #2138. When it's set to true, Fable turns the code in an IIFE, instead of printing it as-is. @alfonsogarciacaro maybe you noticed this back then already and added the new parameter for that reason.

Related information

  • Fable version: 3.0.0-nagareyama-beta-005
  • Operating system: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions