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

fix when LHS of a reactive assignment is a member expression #4213

Merged
merged 1 commit into from
Jan 6, 2020

Conversation

Conduitry
Copy link
Member

Fixes #4212. In DOM mode, we were declaring the variable automatically, which is almost certainly never going to be helpful (and broke stuff like using it to update document.title). In SSE mode, we were writing actually invalid code (let document.title = ...). This simply skips the automatic declaration of the variable when the LHS of the assignment is a MemberExpression.

@Conduitry
Copy link
Member Author

Hmm this isn't quite the right solution, as it doesn't handle this (wacky) situation:

$: ({ key: document.title } = foo);

I'm not sure what the best way to handle this is. If we wanted to add an option for extract_names to skip names used in MemberExpressions, that would have to go in periscopic, and suddenly this isn't so quick to fix anymore.

@antony
Copy link
Member

antony commented Jan 5, 2020

This reminds me of this issue: #3310

Encouraging operations on document to be made by a <svelte:document> tag might be a good way to get around complexities such as this.

@Conduitry
Copy link
Member Author

Regardless of <svelte:document> I still think we should do something about this.

I've decided to just merge this as-is, which should cover the majority of cases that actually occur in real life. I'll open an issue to discuss the new feature over in periscopic's repo, and then eventually we can fix this properly here.

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

Successfully merging this pull request may close these issues.

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