ES5 target: object assignment with rest evaluates rest before listed properties
Yeaseen opened this issue · comments
Describe the bug
When targeting ES5, SWC lowers object rest destructuring incorrectly for assignment patterns.
It constructs the ...rest object before evaluating the listed properties (here aa), but per spec the listed properties must be resolved first (including getter side effects) before the rest is built. This causes observable divergences with getters or proxies.
Input code
let aa, rest;
const src = {
get aa() {
console.log('getter aa (deleting zz)');
delete this.zz;
return 1;
},
yy: 2,
zz: 3
};
({ aa, ...rest } = src);
console.log('rest keys:', Object.keys(rest));
Config
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
It should output:
$ node test.js
getter aa (deleting zz)
rest keys: [ 'yy' ]
Actual behavior
SWC playground produced JS code gives the following:
$ node out.js
getter aa (deleting zz)
rest keys: [ 'yy', 'zz' ]
Version
1.13.5
Additional context
No response