Skip to content

[JS] Fable 4 -> Fable 5 unnecessary parentheses in ternary expressions #4295

Closed

Description

@Lanayx

I'm starting converting Oxpecker.Solid plugin to Fable 5 and I've found some inconsistencies.

Oxpecker.Solid:

if x = 1 then h1() else h2()

Fable4 jsx:

{ (x  === 1) ? <h1></h1> : <h2></h2> }

Fable5 jsx:

{ (x === 1) ? (<h1 />) : (<h2 />) }

Full Repro (command is dotnet fable --noCache --exclude Oxpecker.Solid.FablePlugin --extension .jsx)

While I remember that self-closing tag was added by @shayanhabibi in #4037 , were extra parentheses for ternary operator added intentionally?

UPDATE: Interestingly in some cases paretheses are not added

Activity

  1. MangelMaxime commented on Dec 8, 2025

    @MangelMaxime
    Member

    Hello,

    In general Fable makes no guarantee in how the generated code looks like.

    Does the additional parentheses cause an issues ?

  2. Lanayx commented on Dec 8, 2025

    @Lanayx
    ContributorAuthor

    @MangelMaxime No, additional parentheses doesn't cause any issue (except that they make output a bit less readable), I just asked if you know why it was added, it could signal that some unwanted changes were introduced.
    Today I've realized that I can find it out myself by checking different versions and found out that extra parentheses appeared in 5.0.0-alpha.13, so it looks like it was this issue and this commit.
    But looking at the changes, I'm not sure where those extra parentheses come from.

  3. MangelMaxime commented on Dec 9, 2025

    @MangelMaxime
    Member

    I believe the additional parentheses are added because we now don't rewrite as aggressively the output.

    We are now emitting standard Fable expr, by default Fable wrap expression in certain scenario with parentheses to ensure that they are scopes/executed correctly.

    I am closing because I don't think something needs to be acted on for now. We can revisit later if needed

  4. changed the title [-][JS] Fable 4 -> Fable 5 jsx inconsistency[/-] [+][JS] Fable 4 -> Fable 5 unnecessary parentheses in ternary expressions[/+] on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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