From 3961b720be665909cd412dc281141949e3b52427 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 7 Aug 2015 17:47:09 +0100 Subject: [PATCH] check if a node is static before using it as the reference for an object spread --- .../src/transformation/transformers/es6/destructuring.js | 4 ++-- .../es6.destructuring/object-advanced/actual.js | 1 + .../es6.destructuring/object-advanced/expected.js | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/babel/src/transformation/transformers/es6/destructuring.js b/packages/babel/src/transformation/transformers/es6/destructuring.js index ba63140af9..874c34bcd1 100644 --- a/packages/babel/src/transformation/transformers/es6/destructuring.js +++ b/packages/babel/src/transformation/transformers/es6/destructuring.js @@ -460,8 +460,8 @@ class DestructuringTransformer { // member expression then we need to assign it to a temporary variable so it's // only evaluated once - if (pattern.properties.length > 1 && t.isMemberExpression(objRef)) { - var temp = this.scope.generateUidIdentifierBasedOnNode(objRef, this.file); + if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) { + var temp = this.scope.generateUidIdentifierBasedOnNode(objRef); this.nodes.push(this.buildVariableDeclaration(temp, objRef)); objRef = temp; } diff --git a/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/actual.js b/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/actual.js index 27a221c473..f9b39d97af 100644 --- a/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/actual.js +++ b/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/actual.js @@ -1,2 +1,3 @@ var rect = {}; var {topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}} = rect; +var { 3: foo, 5: bar } = [0, 1, 2, 3, 4, 5, 6]; diff --git a/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/expected.js b/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/expected.js index 9d8636356f..34f7843a0a 100644 --- a/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.destructuring/object-advanced/expected.js @@ -7,3 +7,6 @@ var y1 = _rect$topLeft.y; var _rect$bottomRight = rect.bottomRight; var x2 = _rect$bottomRight.x; var y2 = _rect$bottomRight.y; +var _ref = [0, 1, 2, 3, 4, 5, 6]; +var foo = _ref[3]; +var bar = _ref[5];