Skip to content

Assigning to a member expression in a reactive statement shouldn't auto-declare the variable #4212

@Conduitry

Description

@Conduitry

Describe the bug
A reactive assignment that looks like $: document.title = whatever; doesn't work, because the compiler (unhelpfully, in this case) auto-declares document for us, and - since that is now undefined - the assignment document.title = whatever; is a runtime error.

Logs
TypeError: document is undefined

To Reproduce

<script>
  $: document.title = 'foo';
</script>

Expected behavior
This should simply assign to the global document and not attempt to automatically declare it

Stacktraces

Information about your Svelte project:
Svelte 3.16.7 - independent of browser or bundler.

Severity
Moderate, probably. We do specifically mention this syntax in the docs, and it doesn't work.

Additional context
I believe this will simply be a matter of adjusting the logic here for when we bail out and decide we don't need to auto-declare the variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions