Erik Desjardins bca170ad79 Avoid duplicating impure expressions in object rest destructuring (#5151)
* avoid duplicating impure initializers in object rest destructuring

* reuse existing VariableDeclarations in object rest destructuring, to fix two issues:

1. inserting an additional VariableDeclaration after the current one may change order of operations, which is unsafe if a future VariableDeclarator refers to a destructured variable.

2. The entire VariableDeclaration is removed when all properties are rest properties, indiscriminately removing other variables
2017-01-18 21:32:44 -05:00

16 lines
415 B
JavaScript

const _foo = foo(),
{ s } = _foo,
t = babelHelpers.objectWithoutProperties(_foo, ["s"]);
const _bar = bar(),
{ s: { q1 } } = _bar,
q2 = babelHelpers.objectWithoutProperties(_bar.s, ["q1"]),
q3 = babelHelpers.objectWithoutProperties(_bar, ["s"]);
const { a } = foo((_ref) => {
let { b } = _ref,
c = babelHelpers.objectWithoutProperties(_ref, ["b"]);
console.log(b, c);
});