-
-
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.
fix: resolve computed_prop_# collision (#8418)
Fixes #8417 The issue is that unpack_destructuring in each blocks, await blocks, and @const tags were making computed_props independently. This causes computed_props_# to conflict when each blocks were used with @const tags, or await blocks and @const tags, or consecutive @const tags together. Therefore, one solution is to use component.get_unique_name to, well, make unique names and never get conflicts.
- Loading branch information
Showing
5 changed files
with
115 additions
and
21 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
20 changes: 20 additions & 0 deletions
20
test/runtime/samples/const-tag-await-then-destructuring-computed-in-computed/_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,20 @@ | ||
export default { | ||
html: ` | ||
<p>4, 12, 60</p> | ||
`, | ||
|
||
async test({ component, target, assert }) { | ||
component.permutation = [2, 3, 1]; | ||
await (component.promise1 = Promise.resolve({length: 1, width: 2, height: 3})); | ||
try { | ||
await (component.promise2 = Promise.reject({length: 97, width: 98, height: 99})); | ||
} catch (e) { | ||
// nothing | ||
} | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<p>2, 11, 2</p> | ||
<p>9506, 28811, 98</p> | ||
`); | ||
} | ||
}; |
27 changes: 27 additions & 0 deletions
27
test/runtime/samples/const-tag-await-then-destructuring-computed-in-computed/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,27 @@ | ||
<script> | ||
export let promise1 = {length: 5, width: 3, height: 4}; | ||
export let promise2 = {length: 12, width: 5, height: 13}; | ||
export let permutation = [1, 2, 3]; | ||
function calculate(length, width, height) { | ||
return { | ||
'1-Dimensions': [length, width, height], | ||
'2-Dimensions': [length * width, width * height, length * height], | ||
'3-Dimensions': [length * width * height, length + width + height, length * width + width * height + length * height] | ||
}; | ||
} | ||
const th = 'th'; | ||
</script> | ||
|
||
{#await promise1 then { length, width, height }} | ||
{@const { [0]: a, [1]: b, [2]: c } = permutation} | ||
{@const { [`${a}-Dimensions`]: { [c - 1]: first }, [`${b}-Dimensions`]: { [b - 1]: second }, [`${c}-Dimensions`]: { [a - 1]: third } } = calculate(length, width, height) } | ||
<p>{first}, {second}, {third}</p> | ||
{/await} | ||
|
||
{#await promise2 catch { [`leng${th}`]: l, [`wid${th}`]: w, height: h }} | ||
{@const [a, b, c] = permutation} | ||
{@const { [`${a}-Dimensions`]: { [c - 1]: first }, [`${b}-Dimensions`]: { [b - 1]: second }, [`${c}-Dimensions`]: { [a - 1]: third } } = calculate(l, w, h) } | ||
<p>{first}, {second}, {third}</p> | ||
{/await} |
15 changes: 15 additions & 0 deletions
15
test/runtime/samples/const-tag-each-destructure-computed-in-computed/_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,15 @@ | ||
export default { | ||
html: ` | ||
<button>6, 12, 8, 24</button> | ||
<button>45, 35, 63, 315</button> | ||
<button>60, 48, 80, 480</button> | ||
`, | ||
|
||
async test({ component, target, assert }) { | ||
component.boxes = [{ length: 10, width: 20, height: 30 }]; | ||
|
||
assert.htmlEqual(target.innerHTML, | ||
'<button>200, 600, 300, 6000</button>' | ||
); | ||
} | ||
}; |
44 changes: 44 additions & 0 deletions
44
test/runtime/samples/const-tag-each-destructure-computed-in-computed/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,44 @@ | ||
<script> | ||
export let boxes = [ | ||
{length: 2, width: 3, height: 4}, | ||
{length: 9, width: 5, height: 7}, | ||
{length: 10, width: 6, height: 8} | ||
]; | ||
function calculate(length, width, height) { | ||
return { | ||
twoDimensions: { | ||
bottomArea: length * width, | ||
sideArea1: width * height, | ||
sideArea2: length * height | ||
}, | ||
threeDimensions: { | ||
volume: length * width * height | ||
} | ||
}; | ||
} | ||
export let dimension = 'Dimensions'; | ||
function changeDimension() { | ||
dimension = 'DIMENSIONS'; | ||
} | ||
let area = 'Area'; | ||
let th = 'th'; | ||
</script> | ||
|
||
{#each boxes as { [`leng${th}`]: length, [`wid${th}`]: width, height }} | ||
{@const { | ||
[`two${dimension}`]: areas, | ||
[`three${dimension}`]: { | ||
volume | ||
} | ||
} = calculate(length, width, height)} | ||
{@const { | ||
i = 1, | ||
[`bottom${area}`]: bottom, | ||
[`side${area}${i++}`]: sideone, | ||
[`side${area}${i++}`]: sidetwo | ||
} = areas} | ||
<button on:click={changeDimension}>{bottom}, {sideone}, {sidetwo}, {volume}</button> | ||
{/each} |