Skip to content
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

Parentheses with comma operator in #if causes "Expression expected" #231

Closed
Th0rN13 opened this issue Jun 26, 2020 · 8 comments
Closed

Parentheses with comma operator in #if causes "Expression expected" #231

Th0rN13 opened this issue Jun 26, 2020 · 8 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers

Comments

@Th0rN13
Copy link

Th0rN13 commented Jun 26, 2020

Describe the bug
Comma operator in parentheses causes the error "Expression expected"
I found it in {#if }, but there may be similar behavior in other places.
It not very usable, but can be used for debug

To Reproduce
Steps to reproduce the behavior:

{#if (true, false)}
  content
{/if}

Expected behavior
No error

System (please complete the following information):

  • OS: Windows
  • IDE: VSCode
  • Plugin/Package: Svelte Beta
@Th0rN13 Th0rN13 added the bug Something isn't working label Jun 26, 2020
@jasonlyu123
Copy link
Member

jasonlyu123 commented Jun 26, 2020

Something the error is compile errors from svelte compiler. Do you found any problems like this but has no problems building? Or did I misunderstand what you mean? Because these examples are not valid syntax.

@Th0rN13
Copy link
Author

Th0rN13 commented Jun 26, 2020

This is valid syntax, and compiles without errors, and works as expected

@jasonlyu123
Copy link
Member

jasonlyu123 commented Jun 26, 2020

Sorry I must have miss something when checking if it could compile earlier. I honestly doesn't know what this syntax can do lol.

@Th0rN13
Copy link
Author

Th0rN13 commented Jun 26, 2020

Do you mean any expression with parentheses and comma, like a function call?

No, i mean this syntax - comma operator. I wrap condition in parentheses

If i use

{#if prop === propCompare}
  content
{/if}

and want to temporarily change condition to true, but don't want fully remove condition, i use

{#if (prop === propCompare, true)}
  content
{/if}

This calculate conditions and use last operand in comma operator

Yes, i can use this without parentheses, like {#if prop === propCompare, true}, and it works good, but i use parentheses for visibility to me.

@jasonlyu123
Copy link
Member

Thanks for pointing that out. Learned something. We must check this in various transformation in sveltetsx.

@jasonlyu123
Copy link
Member

Await block also has this. but in both cases, the problem is not with comma but the extra parentheses

@arpitkalla
Copy link
Contributor

Hey, I was looking into this issue and identified the problem was with appendLeft-ing the extra parenthesis as opposed to overwriting. I pointed it in the PR but my patch removes extra parenthesis around the guard. The "Expression expected" error should be removed, will test that out too.

@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Jul 1, 2020
@jasonlyu123
Copy link
Member

str.overwrite(awaitBlock.start, awaitBlock.expression.start, '{() => {let _$$p = (');

str.overwrite(attr.start, attr.expression.start, `{...__sveltets_ensureType(Boolean, !!(`);

These two also has similar problem

@dummdidumm dummdidumm added good first issue Good for newcomers and removed Fixed Fixed in master branch. Pending production release. labels Jul 2, 2020
@jasonlyu123 jasonlyu123 linked a pull request Jul 11, 2020 that will close this issue
@jasonlyu123 jasonlyu123 added the Fixed Fixed in master branch. Pending production release. label Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants