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

Can not compile complex {#if} #3447

Closed
Kauto opened this issue Aug 22, 2019 · 2 comments · Fixed by #3478
Closed

Can not compile complex {#if} #3447

Kauto opened this issue Aug 22, 2019 · 2 comments · Fixed by #3478
Labels

Comments

@Kauto
Copy link

Kauto commented Aug 22, 2019

While using a complex {#if} statement, svelte is compiling to invalid javascript.

<script>
	let item = {
		divider: [1],
		sub: {
			first: '/first',
			second: '/2',
			third: '/3'
	  }
	}
</script>

{#each Object.entries(item.sub) as [subName, path], i}
{#if (item.divider && item.divider.includes(i))}
<div class="divider"></div>
{/if}
<a href="{path}">{subName}</a>
{/each}
Module parse failed: Unexpected token (285:7)
File was processed with these loaders:
 * ./node_modules/svelte-loader/index.js
You may need an additional loader to handle the result of these loaders.
| 
|               p(changed, ctx) {
>                       if () show_if = (ctx.item.divider && ctx.item.divider.includes(ctx.i))
| 
|                       if (show_if) {

To Reproduce
Look at the code produced in this REPL:
https://svelte.dev/repl/8a129823894a48cb944245fb7bc1d6fe?version=3.9.1

you can see the error in the JS-output in line 71.

Expected behavior
Code compiles.

Severity
It was working in old versions, so now I have to downgrade.

@Conduitry Conduitry added the bug label Aug 22, 2019
@Conduitry
Copy link
Member

Yep, thanks. This worked in 3.9.0. Presumably caused by #3438.

@Rich-Harris
Copy link
Member

Fixed in 3.9.2! thanks

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

Successfully merging a pull request may close this issue.

3 participants