Svelte: Compiler fail when exporting prop with assignment expression as default value

Created on 10 Aug 2019  路  3Comments  路  Source: sveltejs/svelte

Describe the bug
When a prop is declared and its default value contain assignment, the compiler will throw up.

Logs

Error: TODO this should not happen!
    at dom (/ceres/node_modules/svelte/compiler.js:17865:20)
    at compile (/ceres/node_modules/svelte/compiler.js:23840:16)
    at preprocessPromise.then.code (/ceres/node_modules/rollup-plugin-svelte/index.js:252:22)
    at process._tickCallback (internal/process/next_tick.js:68:7)

To Reproduce
Can be reproduced in REPL:

<script>
    let name = 'world';
    let something;
    export let prop = (something = 1);
</script>

<h1>Hello {name}!</h1>

You get the TODO this should not happen message at REPL bottom.

I was actually using rollup and preprocessed svelte files with babel to get optional chaining syntax support. I got this "TODO" error when I wrote something like export let x = a?.b. I eventually discovered that the optional chaining will transpile into code with in expression assignments. The assignment is what actually killed svelte compiler.

Expected behavior
Just work as it should be.

Information about your Svelte project:

  • Svelte version: 3.7.1
  • Operating system: macOS 10.13.4
  • Browser: irrelevant
  • Webpack or Rollup: Rollup, but irrelevant

Severity
Not quite severe, but the error tip is frustrating. It doesn't tell me what's wrong or where to fix. I wasted an hour to find out the cause.

bug has pr

All 3 comments

This isn't restricted to props. This also throws that error:

<script>
    let foo;
    let bar = foo = 1;
</script>

as does this example based on #3393:

<script>
    let foo;
    let bar = foo++;
</script>

Interestingly, this is fine:

<script>
    let foo;
    let bar;
    bar = foo = 1;
</script>

I think i can fix it

Update 18.08.2019
still work =)

Update 20.08.2019
found solution, mr in progress

This was fixed back in 3.10.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sskyy picture sskyy  路  3Comments

angelozehr picture angelozehr  路  3Comments

Rich-Harris picture Rich-Harris  路  3Comments

davidcallanan picture davidcallanan  路  3Comments

robnagler picture robnagler  路  3Comments