Skip to content

Attempting to rename destructured slot variable keys results in a compilation error #8556

@joelmukuthu

Description

@joelmukuthu

Describe the bug

When using slot variables, if you have a variable that's an object and you try to destructure it there's no problem:

<!-- this is fine: -->
<Component let:data={{ foo, bar, baz }} />

However, if you try to rename some key in the object, or destructure a nested object, a compilation error is thrown:

<!-- this fails: -->
<Component let:data={{ foo: fooRenamed }} />
<!-- so does this: -->
<Component let:data={{ bar: { nestedInBar } }} />

Interestringly, the Svelte for VS Code extension doesn't show any errors on the destructured code, perhaps because it's valid javascript.

Reproduction

https://svelte.dev/repl/98917cf206794f20a4d3c45d012583be?version=3.58.0

Logs

Stack trace from svelte.repl:

TypeError: Cannot read properties of undefined (reading 'index')
    at get_slot_definition.ts:60:88
    at Array.map (<anonymous>)
    at get_slot_definition (get_slot_definition.ts:60:33)
    at new SlotTemplateWrapper (SlotTemplate.ts:57:4)
    at index.ts:92:52
    at Array.map (<anonymous>)
    at new InlineComponentWrapper (index.ts:92:39)
    at new FragmentWrapper (Fragment.ts:124:21)
    at new Renderer (Renderer.ts:90:19)
    at dom (index.ts:23:19)

System Info

Svelte: v3.58.0
All browsers

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompilerChanges relating to the compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions