-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Describe the bug
When using array destructuring with skipped elements and default values inside an async function, SWC’s ES5 output shifts elements instead of applying the default. This causes wrong bindings for subsequent variables. Node.js and Babel handle this correctly.
Input code
async function fetchResource() {
let data = ["John", , 25, "Developer", "California"];
await new Promise(resolve => setTimeout(resolve, 500));
return data;
}
function func1() {
return new Promise(async (resolve, reject) => {
let resource = await fetchResource();
const [firstName, middleName = "N/A", age, ...rest] = resource;
const result = (function() {
if(firstName) {
return {firstName, middleName, age, occupation: rest[0], location: rest[1]};
} else {
return {error: "Failed to fetch resource"};
}
})();
resolve(result);
});
}
async function main() {
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:
{
firstName: 'John',
middleName: 'N/A',
age: 25,
occupation: 'Developer',
location: 'California'
}
Actual behavior
But, it actually prints:
{
firstName: 'John',
middleName: 25,
age: 'Developer',
occupation: 'California',
location: undefined
}
Version
1.13.5
Additional context
No response