-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Describe the bug
When using nested array destructuring with holes inside an async function, SWC’s ES5 output mishandles the destructuring. The transform drops the hole and shifts values, causing one of the awaited results to be replaced with a raw, unresolved Promise. Node.js and Babel transpilation both yield the correct values.
Input code
class MyClass {
constructor(data) {
if (!(data instanceof Array))
throw new Error('Invalid instance');
this.data = data;
}
}
function fetchPromise(idx) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(idx), 10)
})
}
async function func1() {
const arr = [1, [2, 3], , 4];
let [a, [ , b], ,d] = arr;
const instance = new MyClass([a, b, d])
a = await fetchPromise(instance.data[0]) || fetchPromise(0);
b = await fetchPromise(instance.data[1]) || fetchPromise(0);
d = await fetchPromise(instance.data[2]) || fetchPromise(0);
return [a, b, d];
}
function main() {
const res = func1();
res.then(value => console.log(value));
}
main();
Config
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
SWC's ES5 output should print: [ 1, 3, 4 ]
Actual behavior
But, it prints: [ 1, 3, Promise { <pending> } ]
Version
1.13.5
Additional context
No response