Skip to content

fix: mark accessors and immutable as deprecated #11277

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

Merged
merged 20 commits into from
Apr 24, 2024
Merged

fix: mark accessors and immutable as deprecated #11277

merged 20 commits into from
Apr 24, 2024

Conversation

Rich-Harris
Copy link
Member

immutable was already deprecated insofar as you'd get a message during options validation (which, incidentally, isn't ideal — it's treated separately from all other compiler warnings. need to come up with a better system. i have some ideas), but it wasn't deprecated in the CompileOptions types. This fixes that.

It also marks accessors as deprecated, and makes it not do anything in runes mode, which will allow us to remove it in Svelte 6.

A couple of other things that fell out of this:

  • thanks to feat: include script and svelte:options attributes in ast #11241, we can warn on individual attributes on <svelte:options>, so in addition to warning if encountering accessors or immutable there, we improve the customElement warning
  • some runtime-runes tests relied on accessors. In runes mode, the component object passed into test functions is now a proxy, and the tests themselves have been updated to wrap prop changes in flushSync

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 Apr 21, 2024

🦋 Changeset detected

Latest commit: 2bad3f3

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

@@ -303,7 +319,7 @@ async function run_test_variant(
htmlEqualWithOptions: assert_html_equal_with_options
},
variant,
component: instance,
component: runes ? props : instance,
Copy link
Member

Choose a reason for hiding this comment

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

this will surprise us down the line when we want to invoke actual exports on the instance. We should merge the objects instead

Copy link
Member

Choose a reason for hiding this comment

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

Adjusted that

Copy link
Member Author

Choose a reason for hiding this comment

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

Surely a better fix would be to pass them in separately? component eventually gets renamed to props, and there's an additional instance property passed to tests.

Copy link
Member

@dummdidumm dummdidumm Apr 24, 2024

Choose a reason for hiding this comment

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

The adjustments also ensure that I don't have to wrap every usage site with flushSync which I think is better.
I don't care if it's one or two properties.

Copy link
Member Author

Choose a reason for hiding this comment

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

Until you do something like component.todos.push(...), at which point you're in the uncanny valley (because it doesn't invoke the set trap which calls flushSync). Merging them is a kludge. Really, I've come to the view that we shouldn't be setting props in the tests anyway, because things are so much easier to debug if you can just copy-paste stuff into the playground. I'd much prefer that we work towards having a clear distinction (even if we're stymied by legacy mode for the forseeable future) rather than having layers of magic around our tests

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.

Made a few changes to the test suite, looks good from my side

@Rich-Harris Rich-Harris merged commit 476f217 into main Apr 24, 2024
8 checks passed
@Rich-Harris Rich-Harris deleted the deprecations branch April 24, 2024 14:57
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.

2 participants