[JS/TS] Negating a -0.0 literal emits --0 and fails with SyntaxError

Open Beginner friendly
#5,280 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
compilers

Research direction

Start by locating the unary-minus parenthesization check described in the issue, which currently tests whether the value is less than 0.0, and trace how it handles the -0.0 literal. Use the repro to confirm the generated JavaScript or TypeScript no longer contains invalid --0, then verify the output is valid and evaluates to 0.000000.

Written by the indexing model from the issue text.

Description

Description

Negating a -0.0 float literal (directly or after inlining) emits --0 in JavaScript and TypeScript output, which fails at parse time as a prefix decrement on a literal because the unary-minus parenthesization check only tests value < 0.0 (which is false for -0.0).

Repro code
let x = -(-0.0)
printfn "%f" x
Expected and actual results

Expected result:

Compiles to valid JavaScript/TypeScript (e.g. const x = -(-0); or 0), and outputs 0.000000 like .NET F#.

Actual result:

Fable compiles the binding to const x = --0;, which Node.js rejects at parse time with:

SyntaxError: Invalid left-hand side expression in prefix operation
Related information
  • Fable version: 5.27.0
  • Operating system: macOS / Linux

Credit: https://ucsbplse.github.io/

Dominant language
F#
Stars
3.2k
Forks
335
Avg merge
18h 57m
Merged PRs (30d)
154

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fable-compiler/Fable

All issues in fable-compiler/Fable

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.