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

feat: support migration of single assignment labeled statements #13461

Merged
merged 7 commits into from
Oct 4, 2024

Conversation

paoloricciuti
Copy link
Member

@paoloricciuti paoloricciuti commented Oct 1, 2024

Svelte 5 rewrite

I took a shot at closing #13460

Also closes #13459

It seems to work fine but i don't know if i'm missing some weird use case i was not able to think about.

Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (main).

If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is svelte-4 and not main.

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

Copy link

changeset-bot bot commented Oct 1, 2024

🦋 Changeset detected

Latest commit: 8ba0012

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

update_idx === -1 &&
(declaration_idx !== -1 ||
(labeled_idx !== -1 && assignment_idx !== -1) ||
(labeled_idx === -1 && assignment_idx === -1))
Copy link
Member

Choose a reason for hiding this comment

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

This might be a bit simpler if you're not searching for the index but rather the object directly. Not as much -1, and no reference.path[idx] above

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah i usually go with indices just because this just stores a reference to a number instead of an object but that's silly in this case.

/** @type {number} */ (labeled_to_remove.start),
/** @type {number} */ (labeled_to_remove.end)
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to do this up here? What speaks against doing inside the VariableDeclaration visitor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh actually this was initially needed because i was converting even blocks with multiple assignments but that's no buono so i reverted that change and forgot that now i can do it in VariableDeclaration. Fixing now.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Almost there 😃

packages/svelte/src/compiler/migrate/index.js Outdated Show resolved Hide resolved
packages/svelte/src/compiler/migrate/index.js Show resolved Hide resolved
packages/svelte/src/compiler/migrate/index.js Show resolved Hide resolved
packages/svelte/src/compiler/migrate/index.js Show resolved Hide resolved
$: almost_infinity = count * 128;

let should_be_state;
$: should_be_state = 42;
Copy link
Member

Choose a reason for hiding this comment

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

I also saw things like

	$: should_also_be_state = 42;

without a preceeding let with the same name in the wild. Would be good to handle that aswell. and transform that into let should_also_be_state = $state(42)

Copy link
Member Author

Choose a reason for hiding this comment

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

I planned to do that as well but since that is not a variable declaration i should've repeated a lot of code from here...i planned to do this as a separate PR to not complicate things too much in this. Should i go for this in this PR too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Scratch that...it was different. Pushing now.

@dummdidumm dummdidumm merged commit aa3f002 into main Oct 4, 2024
9 checks passed
@dummdidumm dummdidumm deleted the support-single-assignment-labeled-migrations branch October 4, 2024 13:16
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.

Migrate to $state instead of run
2 participants