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: detect mutations within assignments expressions #12411

Closed
wants to merge 3 commits into from

Conversation

dummdidumm
Copy link
Member

This enhances our "variable was mutated" detection to also recognize that foo in [foo[1]] = [..] was mutated. This allows us to be more granular about detecting mutations to each expressions in legacy mode, which fixes #12169

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

This enhances our "variable was mutated" detection to also recognize that `foo` in `[foo[1]] = [..]` was mutated. This allows us to be more granular about detecting mutations to each expressions in legacy mode, which fixes #12169
Copy link

changeset-bot bot commented Jul 11, 2024

🦋 Changeset detected

Latest commit: 9b9a268

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +69 to +75
case 'MemberExpression':
if (include_member_expressions) {
// Only the `a` from `[a.b[c].d]` is of interest to us here
const id = object(param);
if (id) nodes.push(id);
}
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what any of this is doing. If we revert all the changes in this file and keep the ones in 2-analyze/index.js, the test still passes. Do we need it? It sets off my spidey senses

Copy link
Member Author

@dummdidumm dummdidumm Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try running the legacy runtime test suite, you'll see one test failing then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out what was triggering my spidey senses — this causes mutations and reassignments to be treated the same way, resulting in less efficient code in the [array[1], array[0]] = [array[0], array[1]] case. It's an edge case to be sure but I thought it worthwhile to get to the bottom of it anyway — opened #12429 with a very slightly different approach

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.

Svelte 5 migration: erroneous $state declaration when each block present
3 participants