-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: allow to access private fields after this
reassignment
#11487
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: allow to access private fields after this
reassignment
#11487
Conversation
🦋 Changeset detectedLatest commit: 24ab911 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Do we need to add getters here? Can't we just rewrite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment
No we can't, because after const instance = this;
someFunctionSomewhereElse(instance) |
Are you sure? There are syntactical restrictions on where you can use private fields that should make this a non-issue. Can you show me a counterexample? |
(What I mean is that |
Counter example. It's not possible for us to know what is what here (I mean, maybe we can with much more elaborate analysis, but I don't think it's worth it). Mhhhhm or maybe we can just assume that when it's there that it works? Mhm, maybe it's enough to tweak the |
That wouldn't even need the check on |
Ignore Svelte transformations for a moment and consider this case: class A {
#blah = 1;
x() {
this.y(this);
}
y(instance) {
console.group('conditional access');
if (#blah in instance) {
console.log('#blah', instance.#blah);
}
console.groupEnd();
console.group('unconditional access');
console.log('#blah', instance.#blah);
console.groupEnd();
}
}
class B {
#blah = 2;
} If you do Any time you see |
I stand corrected, it is indeed much simpler to just always check the private property access 👍 adjusted the PR |
Svelte 5 rewrite
Closes #11480 and #11476
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 notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint