Svelte: Precedence issue when comparing numbers in component HTML code

Created on 13 Sep 2019  路  3Comments  路  Source: sveltejs/svelte

Describe the bug
Trying to compare two numbers inline in HTML code blocks causes incorrect code to be generated, resulting in incorrect results.

{1 === 1} shows as false.

To Reproduce
https://svelte.dev/repl/60c43a6dd4ec4d7a8d1337342a48695b?version=3.12.1

Or try {1 === 1} in your code.

Expected behavior
(1 === 1) === true

Output is:

t0_value = 1 === 1 + ""

and should be something like:

t0_value = (1 === 1) + ""

Information about your Svelte project:

  • Svelte 3.12.1

Severity
This doesn't block, but is severe, since any such comparisons made will be wrong, and this could break a number of pre-existing components.

bug

All 3 comments

This was broken by #3394. There are a few places in the code where we're looking at the precedence of the top-level operator in an expression and deciding whether we need to wrap it in parentheses, but simplest would be to just always wrap it.

I don't know whether this would be affected or fixed by #3539.

Hi guys!, I reviewed this issue using "code-red" branch mentioned in #3539 and work fine!

Fixed by #3539, test added in #3722.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AntoninBeaufort picture AntoninBeaufort  路  3Comments

Rich-Harris picture Rich-Harris  路  3Comments

bestguy picture bestguy  路  3Comments

lnryan picture lnryan  路  3Comments

thoughtspile picture thoughtspile  路  3Comments