-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow destructured defaults to refer to variables (#5986)
Co-authored-by: M. Habib Rosyad <[email protected]> Co-authored-by: Conduitry <[email protected]>
- Loading branch information
1 parent
b764374
commit d17a90c
Showing
14 changed files
with
115 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/runtime/samples/each-block-destructured-default-before-initialised/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
error(assert, err) { | ||
assert.ok(err.message === "Cannot access 'c' before initialization" || err.message === 'c is not defined'); | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/runtime/samples/each-block-destructured-default-before-initialised/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let array = [{a: 1, c: 2}]; | ||
</script> | ||
|
||
{#each array as { a, b = c, c }} | ||
{a}{b}{c} | ||
{/each} |
23 changes: 23 additions & 0 deletions
23
test/runtime/samples/each-block-destructured-default-binding/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/runtime/samples/each-block-destructured-default-binding/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
export let array = [{ value: '' }, {}]; | ||
</script> | ||
|
||
{#each array as { value = "hello" }} | ||
<input bind:value /> | ||
{/each} |
18 changes: 11 additions & 7 deletions
18
test/runtime/samples/each-block-destructured-default/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
export default { | ||
props: { | ||
animalEntries: [ | ||
{ animal: 'raccoon', class: 'mammal', species: 'P. lotor', kilogram: 25 }, | ||
{ animal: 'eagle', class: 'bird', kilogram: 5.4 } | ||
{ animal: 'raccoon', class: 'mammal', species: 'P. lotor', kilogram: 25, bmi: 0.04 }, | ||
{ animal: 'eagle', class: 'bird', kilogram: 5.4 }, | ||
{ animal: 'tiger', class: 'mammal', kilogram: 10, pound: 30 }, | ||
{ animal: 'lion', class: 'mammal', kilogram: 10, height: 50 }, | ||
{ animal: 'leopard', class: 'mammal', kilogram: 30, height: 50, bmi: 10 } | ||
] | ||
}, | ||
|
||
html: ` | ||
<p class="mammal">raccoon - P. lotor - 25kg</p> | ||
<p class="bird">eagle - unknown - 5.4kg</p> | ||
<p class="mammal">raccoon - P. lotor - 25kg (55 lb) - 30cm - 0.04</p> | ||
<p class="bird">eagle - unknown - 5.4kg (12 lb) - 30cm - 0.006</p> | ||
<p class="mammal">tiger - unknown - 10kg (30 lb) - 30cm - 0.011111111111111112</p> | ||
<p class="mammal">lion - unknown - 10kg (22 lb) - 50cm - 0.004</p> | ||
<p class="mammal">leopard - unknown - 30kg (66 lb) - 50cm - 10</p> | ||
`, | ||
|
||
|
||
|
||
test({ assert, component, target }) { | ||
component.animalEntries = [{ animal: 'cow', class: 'mammal', species: 'B. taurus' }]; | ||
assert.htmlEqual(target.innerHTML, ` | ||
<p class="mammal">cow - B. taurus - 50kg</p> | ||
<p class="mammal">cow - B. taurus - 50kg (110 lb) - 30cm - 0.05555555555555555</p> | ||
`); | ||
} | ||
}; |
5 changes: 3 additions & 2 deletions
5
test/runtime/samples/each-block-destructured-default/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
<script> | ||
export let animalEntries; | ||
export const defaultHeight = 30; | ||
</script> | ||
|
||
{#each animalEntries as { animal, species = 'unknown', kilogram: weight = 50 , ...props } } | ||
<p {...props}>{animal} - {species} - {weight}kg</p> | ||
{#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 ({pound} lb) - {height}cm - {bmi}</p> | ||
{/each} |