ES5 destructuring transform drops array hole and shifts default value assignment
Yeaseen opened this issue · comments
Describe the bug
When transpiling array destructuring with holes and default values inside async functions, SWC’s ES5 output fails to preserve the hole. As a result, the default value is skipped and the wrong element is bound. Node.js and Babel output the expected result, but SWC assigns the next array element instead.
Input code
const timeoutPromise = (timeout) => new Promise(resolve => setTimeout(resolve, timeout));
const processArray = async (array) => {
const [first, , third = 'default', ...rest] = array;
if (!first || !third) {
return;
}
await timeoutPromise(10);
return {first, third, rest};
}
const func1 = async () => {
return await processArray(['value1', 'value2', , 'value4', 'value5', 'value6', 'value7']);
}
const main = async () => {
const res = await func1();
console.log(res);
}
main();
Config
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
SWC's ES5 output should print this:
{ first: 'value1', third: 'default', rest: [ 'value4', 'value5', 'value6', 'value7' ] }
Actual behavior
But, it prints: { first: 'value1', third: 'value4', rest: [ 'value5', 'value6', 'value7' ] }
Version
1.13.5
Additional context
No response