Skip to content

Precedence issue when comparing numbers in component HTML code #3564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
antony opened this issue Sep 13, 2019 · 3 comments
Closed

Precedence issue when comparing numbers in component HTML code #3564

antony opened this issue Sep 13, 2019 · 3 comments
Labels

Comments

@antony
Copy link
Member

antony commented Sep 13, 2019

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.

@Conduitry Conduitry added the bug label Sep 13, 2019
@Conduitry
Copy link
Member

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.

@damianpumar
Copy link
Contributor

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

@Conduitry
Copy link
Member

Fixed by #3539, test added in #3722.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants