mirror of https://github.com/sveltejs/svelte
allow destructured defaults to refer to variables (#5986)
Co-authored-by: M. Habib Rosyad <habib@volantis.io> Co-authored-by: Conduitry <git@chor.date>pull/6026/head
parent
b764374b62
commit
d17a90cc44
@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
error(assert, err) {
|
||||||
|
assert.ok(err.message === "Cannot access 'c' before initialization" || err.message === 'c is not defined');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
let array = [{a: 1, c: 2}];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each array as { a, b = c, c }}
|
||||||
|
{a}{b}{c}
|
||||||
|
{/each}
|
@ -0,0 +1,23 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<input />
|
||||||
|
<input />
|
||||||
|
`,
|
||||||
|
ssrHtml: `
|
||||||
|
<input />
|
||||||
|
<input value="hello" />
|
||||||
|
`,
|
||||||
|
|
||||||
|
test({ assert, component, target, window }) {
|
||||||
|
const [input1, input2] = target.querySelectorAll('input');
|
||||||
|
assert.equal(input1.value, '');
|
||||||
|
assert.equal(input2.value, 'hello');
|
||||||
|
|
||||||
|
const inputEvent = new window.InputEvent('input');
|
||||||
|
|
||||||
|
input2.value = 'world';
|
||||||
|
input2.dispatchEvent(inputEvent);
|
||||||
|
assert.equal(input2.value, 'world');
|
||||||
|
assert.equal(component.array[1].value, 'world');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
export let array = [{ value: '' }, {}];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each array as { value = "hello" }}
|
||||||
|
<input bind:value />
|
||||||
|
{/each}
|
@ -1,7 +1,8 @@
|
|||||||
<script>
|
<script>
|
||||||
export let animalEntries;
|
export let animalEntries;
|
||||||
|
export const defaultHeight = 30;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each animalEntries as { animal, species = 'unknown', kilogram: weight = 50 , ...props } }
|
{#each animalEntries as { animal, species = 'unknown', kilogram: weight = 50, pound = (weight * 2.2).toFixed(0), height = defaultHeight, bmi = weight / (height * height), ...props } }
|
||||||
<p {...props}>{animal} - {species} - {weight}kg</p>
|
<p {...props}>{animal} - {species} - {weight}kg ({pound} lb) - {height}cm - {bmi}</p>
|
||||||
{/each}
|
{/each}
|
||||||
|
Loading…
Reference in new issue