Prior to this change, we'd conduct an open-ended traversal on the 'id' of any VariableDeclarator to find a RestElement. The 'id' of a VariableDeclarator can contain an AssignmentPattern (to supply a default value), and if the right-hand side of the AssignmentPattern contained a RestElement, we'd transform it. The problem here is that the right-hand side of an AssignmentPattern can be *any* Expression. If the right-hand side is a function body, we'd traverse the entire function body, and if a RestElement occurred anywhere in that function body, we'd transform it and emit the transformations wherever we began the traversal (at least one scope outside its usage). The fix is to stop the inner traversal if we encounter an AssignmentPattern. The outer traversal will still visit the AssignmentPattern, so RestElements within the right-hand side of an AssignmentPattern will be properly transformed at that time.
13 lines
215 B
JavaScript
13 lines
215 B
JavaScript
function fn0(obj0) {
|
|
const {
|
|
fn1 = (obj1 = {}) => {
|
|
const {
|
|
fn2 = (obj2 = {}) => {
|
|
const {a, ...rest} = obj2;
|
|
console.log(rest);
|
|
}
|
|
} = obj1;
|
|
}
|
|
} = obj0;
|
|
}
|