only evaluate object destructuring pattern once

This commit is contained in:
Sebastian McKenzie 2015-02-08 20:22:46 +11:00
parent 4ea0175ca7
commit bcc9e016b1
3 changed files with 18 additions and 8 deletions

View File

@ -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++) { for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i]; var prop = pattern.properties[i];
if (t.isSpreadProperty(prop)) { if (t.isSpreadProperty(prop)) {

View File

@ -1,6 +1,8 @@
"use strict"; "use strict";
var x1 = rect.topLeft.x; var _rect$topLeft = rect.topLeft;
var y1 = rect.topLeft.y; var x1 = _rect$topLeft.x;
var x2 = rect.bottomRight.x; var y1 = _rect$topLeft.y;
var y2 = rect.bottomRight.y; var _rect$bottomRight = rect.bottomRight;
var x2 = _rect$bottomRight.x;
var y2 = _rect$bottomRight.y;

View File

@ -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; } }; 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) { function somethingAdvanced(_ref) {
var x1 = _ref.topLeft.x; var _ref$topLeft = _ref.topLeft;
var y1 = _ref.topLeft.y; var x1 = _ref$topLeft.x;
var x2 = _ref.bottomRight.x; var y1 = _ref$topLeft.y;
var y2 = _ref.bottomRight.y; var _ref$bottomRight = _ref.bottomRight;
var x2 = _ref$bottomRight.x;
var y2 = _ref$bottomRight.y;
} }
function unpackObject(_ref) { function unpackObject(_ref) {