[JS/TS] Negating a -0.0 literal emits --0 and fails with SyntaxError
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
- Tech stack
- javascript, typescript
- 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
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fable-compiler/Fable
-
agentic-workflows automation repo-assist
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fable-compiler/Fable#4531 ·
Maintainers usually reply within 1 day
-
agentic-workflows automation repo-assist
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
fable-compiler/Fable#4522 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
fable-compiler/Fable#5281 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 57/100
fable-compiler/Fable#5279 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 5/5 Over a week Newbie friendliness 25/100
fable-compiler/Fable#5272 ·
Maintainers usually reply within 1 day
All issues in fable-compiler/Fable
Similar issues
-
compiler: `void` inside a constant array or object literal throws in `PureFunctionConstant.keyOf`Openarea: compiler
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug gc sev-3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
GaloisInc/llvm-pretty#211 ·
-
crash mlir
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
llvm/llvm-project#239604 · 1 comment ·
Maintainers usually reply within 1 day
-
bug good first issue self-hosted compiler
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
AeroForger/AeroFyl#1 ·