diff --git a/lib/6to5/transformation/transformers/es6/destructuring.js b/lib/6to5/transformation/transformers/es6/destructuring.js index ba3cd553df..48bb576f2f 100644 --- a/lib/6to5/transformation/transformers/es6/destructuring.js +++ b/lib/6to5/transformation/transformers/es6/destructuring.js @@ -112,6 +112,12 @@ Destructuring.prototype.pushObjectPattern = function (pattern, parentId) { )); } + if (pattern.properties.length > 1 && t.isMemberExpression(parentId)) { + var temp = this.scope.generateUidBasedOnNode(parentId, this.file); + this.nodes.push(this.buildVariableDeclaration(temp, parentId)); + parentId = temp; + } + for (var i = 0; i < pattern.properties.length; i++) { var prop = pattern.properties[i]; if (t.isSpreadProperty(prop)) { diff --git a/test/fixtures/transformation/es6-destructuring/object-advanced/expected.js b/test/fixtures/transformation/es6-destructuring/object-advanced/expected.js index d3ee04ea05..1048f7d0d4 100644 --- a/test/fixtures/transformation/es6-destructuring/object-advanced/expected.js +++ b/test/fixtures/transformation/es6-destructuring/object-advanced/expected.js @@ -1,6 +1,8 @@ "use strict"; -var x1 = rect.topLeft.x; -var y1 = rect.topLeft.y; -var x2 = rect.bottomRight.x; -var y2 = rect.bottomRight.y; +var _rect$topLeft = rect.topLeft; +var x1 = _rect$topLeft.x; +var y1 = _rect$topLeft.y; +var _rect$bottomRight = rect.bottomRight; +var x2 = _rect$bottomRight.x; +var y2 = _rect$bottomRight.y; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring/parameters/expected.js b/test/fixtures/transformation/es6-destructuring/parameters/expected.js index 2b21e4bedf..e6fbfa2e0a 100644 --- a/test/fixtures/transformation/es6-destructuring/parameters/expected.js +++ b/test/fixtures/transformation/es6-destructuring/parameters/expected.js @@ -3,10 +3,12 @@ var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; function somethingAdvanced(_ref) { - var x1 = _ref.topLeft.x; - var y1 = _ref.topLeft.y; - var x2 = _ref.bottomRight.x; - var y2 = _ref.bottomRight.y; + var _ref$topLeft = _ref.topLeft; + var x1 = _ref$topLeft.x; + var y1 = _ref$topLeft.y; + var _ref$bottomRight = _ref.bottomRight; + var x2 = _ref$bottomRight.x; + var y2 = _ref$bottomRight.y; } function unpackObject(_ref) {