mirror of https://github.com/sveltejs/svelte
fix: always use set for private identifiers (#14378)
* fix: always use set for private identifiers * we can simplify this further - no need to check the value was transformed, since the outcome of not returning immediately is the same but with extra steps * add explanatory note --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/14380/head
parent
85ec6fa276
commit
520055cf5c
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: always use set for private identifiers
|
@ -0,0 +1,17 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<p>42</p><p>1337</p><button></button>`,
|
||||
async test({ assert, target, instance }) {
|
||||
const [a, b] = target.querySelectorAll('p');
|
||||
const btn = target.querySelector('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn?.click();
|
||||
});
|
||||
|
||||
assert.equal(a.textContent, '1337');
|
||||
assert.equal(b.textContent, '42');
|
||||
}
|
||||
});
|
@ -0,0 +1,26 @@
|
||||
<script>
|
||||
class Box {
|
||||
#value = $state(0);
|
||||
|
||||
get value(){
|
||||
return this.#value;
|
||||
}
|
||||
|
||||
constructor(num){
|
||||
this.#value = num;
|
||||
}
|
||||
|
||||
swap(other) {
|
||||
const value = this.#value;
|
||||
this.#value = other.value;
|
||||
other.#value = value;
|
||||
}
|
||||
}
|
||||
|
||||
const a = new Box(42);
|
||||
const b = new Box(1337);
|
||||
</script>
|
||||
|
||||
<p>{a.value}</p>
|
||||
<p>{b.value}</p>
|
||||
<button onclick={()=>{a.swap(b)}}></button>
|
Loading…
Reference in new issue