mirror of https://github.com/sveltejs/svelte
feat: make fallback prop values readonly (#9789)
* WIP * update tests * only make readonly in runes mode * remove this for now * changeset * ugh * add reassignment test * tweak message --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/9771/head
parent
bd8f7db754
commit
62c9292947
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
feat: make fallback prop values readonly
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
/** @type {{ object?: { count: number }}} */
|
||||
let { object = { count: 0 } } = $props();
|
||||
</script>
|
||||
|
||||
<button onclick={() => object = { count: object.count + 1 } }>
|
||||
clicks: {object.count}
|
||||
</button>
|
@ -0,0 +1,19 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>clicks: 0</button>`,
|
||||
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const btn = target.querySelector('button');
|
||||
|
||||
await btn?.click();
|
||||
assert.htmlEqual(target.innerHTML, `<button>clicks: 1</button>`);
|
||||
|
||||
await btn?.click();
|
||||
assert.htmlEqual(target.innerHTML, `<button>clicks: 2</button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
import Counter from './Counter.svelte';
|
||||
</script>
|
||||
|
||||
<Counter />
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
/** @type {{ object?: { count: number }}} */
|
||||
let { object = { count: 0 } } = $props();
|
||||
</script>
|
||||
|
||||
<button onclick={() => object.count += 1}>
|
||||
clicks: {object.count}
|
||||
</button>
|
@ -0,0 +1,18 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>clicks: 0</button>`,
|
||||
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const btn = target.querySelector('button');
|
||||
await btn?.click();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>clicks: 0</button>`);
|
||||
},
|
||||
|
||||
runtime_error: 'Props cannot be mutated, unless used with `bind:`'
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
import Counter from './Counter.svelte';
|
||||
</script>
|
||||
|
||||
<Counter />
|
Loading…
Reference in new issue