-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Describe the bug
When using object destructuring assignment inside an if condition, SWC’s ES5 output evaluates the property incorrectly. In Node.js the destructuring works and isEven is true, but SWC transforms it in a way that makes the check fail.
Input code
let myObject = {value: 5, isEven: true};
function checkIfEven() {
if (({isEven} = myObject).isEven) {
return "Number is even";
}
else {
return "Number is odd";
}
}
function func1() {
return checkIfEven();
}
function main() {
let res = func1();
console.log(res);
}
main();
Config
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
SWC's ES5 should print: Number is even
Actual behavior
But it prints: Number is odd
Version
1.13.5
Additional context
I think the if condition adds an extra unnecessary check here: if ((isEven = myObject.isEven).isEven)
, making it (isEven = myObject.isEven)
evaluates to a boolean (true), and true.isEven
is undefined --> falsy --> “Number is odd”