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

35 lines
1.0 KiB
JavaScript

function a(_ref) {
let a34 = babelHelpers.objectWithoutProperties(_ref, []);
}
function a2(_ref2) {
let { a1 } = _ref2,
b1 = babelHelpers.objectWithoutProperties(_ref2, ["a1"]);
}
function a3(_ref3) {
let { a2, b2 } = _ref3,
c2 = babelHelpers.objectWithoutProperties(_ref3, ["a2", "b2"]);
}
function a4(_ref4, _ref5) {
let { a5 } = _ref5,
c5 = babelHelpers.objectWithoutProperties(_ref5, ["a5"]);
let { a3 } = _ref4,
c3 = babelHelpers.objectWithoutProperties(_ref4, ["a3"]);
}
function a5(_ref6) {
let { a3, b2: { ba1 } } = _ref6,
ba2 = babelHelpers.objectWithoutProperties(_ref6.b2, ["ba1"]),
c3 = babelHelpers.objectWithoutProperties(_ref6, ["a3", "b2"]);
}
function a6(_ref7) {
let { a3, b2: { ba1 } } = _ref7,
ba2 = babelHelpers.objectWithoutProperties(_ref7.b2, ["ba1"]);
}
function a7(_ref8 = {}) {
let { a1 = 1 } = _ref8,
b1 = babelHelpers.objectWithoutProperties(_ref8, ["a1"]);
}
// Unchanged
function b(a) {}
function b2(a, ...b) {}
function b3({ b }) {}