-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support destructurings containing await (#9962)
Adds a traversion mechanism to found out if destructured expressions contain await Fixes #9686 Fixes #9312 Fixes #9982
- Loading branch information
Showing
5 changed files
with
305 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: support async/await in destructuring assignments |
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
75 changes: 75 additions & 0 deletions
75
packages/svelte/tests/runtime-runes/samples/destructure-async-assignments/_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,75 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: ` | ||
<button>Update me!</button> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
<p>0</p> | ||
`, | ||
|
||
async test({ assert, target, window }) { | ||
const btn = target.querySelector('button'); | ||
const clickEvent = new window.Event('click', { bubbles: true }); | ||
await btn?.dispatchEvent(clickEvent); | ||
for (let i = 1; i <= 42; i += 1) { | ||
await Promise.resolve(); | ||
} | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>Update me!</button> | ||
<p>1</p> | ||
<p>2</p> | ||
<p>3</p> | ||
<p>4</p> | ||
<p>5</p> | ||
<p>6</p> | ||
<p>7</p> | ||
<p>8</p> | ||
<p>9</p> | ||
<p>10</p> | ||
<p>11</p> | ||
<p>12</p> | ||
<p>13</p> | ||
<p>14</p> | ||
<p>15</p> | ||
<p>16</p> | ||
<p>17</p> | ||
<p>18</p> | ||
<p>19</p> | ||
<p>20</p> | ||
<p>21</p> | ||
<p>22</p> | ||
<p>23</p> | ||
<p>24</p> | ||
<p>25</p> | ||
<p>26</p> | ||
` | ||
); | ||
} | ||
}); |
89 changes: 89 additions & 0 deletions
89
packages/svelte/tests/runtime-runes/samples/destructure-async-assignments/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,89 @@ | ||
<script> | ||
let a = $state(0); | ||
let b = $state(0); | ||
let c = $state(0); | ||
let d = $state(0); | ||
let e = $state(0); | ||
let f = $state(0); | ||
let g = $state(0); | ||
let h = $state(0); | ||
let i = $state(0); | ||
let j = $state(0); | ||
let k = $state(0); | ||
let l = $state(0); | ||
let m = $state(0); | ||
let n = $state(0); | ||
let o = $state(0); | ||
let p = $state(0); | ||
let q = $state(0); | ||
let r = $state(0); | ||
let s = $state(0); | ||
let t = $state(0); | ||
let u = $state(0); | ||
let v = $state(0); | ||
let w = $state(0); | ||
let x = $state(0); | ||
let y = $state(0); | ||
let z = $state(0); | ||
const get_vwx = () => { | ||
return Promise.resolve({ v: 22, rest: [23, 24] }); | ||
} | ||
const get_y = () => { | ||
return Promise.resolve([24, 25]); | ||
} | ||
const update = async () => { | ||
[a, b] = [1, await Promise.resolve(2)]; | ||
({ c = await Promise.resolve(3), d } = { d: 4 }); | ||
[e] = [await Promise.resolve(2) + await Promise.resolve(3)]; | ||
({ f = false || await Promise.resolve(6) } = {}); | ||
let func = Promise.resolve(() => 7); | ||
[g = (await func)()] = []; | ||
let mult = (a, b) => (a * b); | ||
({ h } = { h: mult(2, await Promise.resolve(4))}); | ||
[i] = [new Date(await Promise.resolve(9)).getTime()]; | ||
[j = "19" ? 10 : await Promise.resolve(11)] = []; | ||
let obj = ({ [await Promise.resolve("prop")]: k } = { prop: 11 }); | ||
[l = obj[await Promise.resolve("prop")] + 1] = []; | ||
[m] = [`${1}${await Promise.resolve("3")}`]; | ||
[n] = [-(await Promise.resolve(-14))]; | ||
[o] = [(console.log(15), await Promise.resolve(15))]; | ||
({ anotherprop: p = await Promise.resolve(16) } = obj); | ||
let val1, val2; | ||
({ val1 = (async function (x) { return await x; })(Promise.resolve(18)), r = await val1 } | ||
= ({ val2 = (async (x) => await x)(Promise.resolve(17)), q = await val2 } = [])); | ||
({ u = 21 } = ({ t = await Promise.resolve(20) } = ([s] = [await Promise.resolve(19)]))); | ||
({ v, rest: [w] } = await get_vwx()); | ||
[x, y, ...{ z = 26 }] = await get_y(); | ||
} | ||
</script> | ||
|
||
<button on:click={update}>Update me!</button> | ||
<p>{a}</p> | ||
<p>{b}</p> | ||
<p>{c}</p> | ||
<p>{d}</p> | ||
<p>{e}</p> | ||
<p>{f}</p> | ||
<p>{g}</p> | ||
<p>{h}</p> | ||
<p>{i}</p> | ||
<p>{j}</p> | ||
<p>{k}</p> | ||
<p>{l}</p> | ||
<p>{m}</p> | ||
<p>{n}</p> | ||
<p>{o}</p> | ||
<p>{p}</p> | ||
<p>{q}</p> | ||
<p>{r}</p> | ||
<p>{s}</p> | ||
<p>{t}</p> | ||
<p>{u}</p> | ||
<p>{v}</p> | ||
<p>{w}</p> | ||
<p>{x}</p> | ||
<p>{y}</p> | ||
<p>{z}</p> |