mirror of https://github.com/sveltejs/svelte
fix: allow to access private fields after `this` reassignment (#11487)
Fixes #11480 Fixes #11476pull/11474/head
parent
0d5a32d5f7
commit
fa3e98e8c6
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: allow to access private fields after `this` reassignment
|
@ -0,0 +1,10 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
async test({ assert, logs }) {
|
||||
assert.deepEqual(logs, ['init', 1, 'init', 1]);
|
||||
}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
<script>
|
||||
class Counter {
|
||||
#count = $state();
|
||||
|
||||
constructor(){
|
||||
const instance = this;
|
||||
instance.#count = 1;
|
||||
}
|
||||
|
||||
get count(){
|
||||
return this.#count;
|
||||
}
|
||||
|
||||
get count2() {
|
||||
const instance = this;
|
||||
return instance.#count;
|
||||
}
|
||||
}
|
||||
const counter = new Counter();
|
||||
|
||||
$inspect(counter.count)
|
||||
$inspect(counter.count2)
|
||||
</script>
|
Loading…
Reference in new issue