From f979d55b718c036075bfb23635afc34fa0d76332 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 30 May 2015 19:07:31 -0400 Subject: [PATCH] remove special ExpressionStatement handling in destructuring transformer --- .../transformers/es6/destructuring.js | 17 +---------------- .../array-unpack-optimisation/expected.js | 8 ++++---- .../expected.js | 8 ++++---- .../assignment-expression/expected.js | 4 ++-- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index 4a592171ce..d46e4c2576 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -107,25 +107,10 @@ export function CatchClause(node, parent, scope, file) { node.body.body = nodes.concat(node.body.body); } -export function ExpressionStatement(node, parent, scope, file) { - var expr = node.expression; - if (expr.type !== "AssignmentExpression") return; - if (!t.isPattern(expr.left)) return; - if (this.isCompletionRecord()) return; - - var destructuring = new DestructuringTransformer({ - operator: expr.operator, - scope: scope, - file: file, - }); - - return destructuring.init(expr.left, expr.right); -} - export function AssignmentExpression(node, parent, scope, file) { if (!t.isPattern(node.left)) return; - var ref = scope.generateUidIdentifier("temp"); + var ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref"); var nodes = []; nodes.push(t.variableDeclaration("var", [ diff --git a/test/core/fixtures/transformation/es6.destructuring/array-unpack-optimisation/expected.js b/test/core/fixtures/transformation/es6.destructuring/array-unpack-optimisation/expected.js index 7179137806..42e1f86c03 100644 --- a/test/core/fixtures/transformation/es6.destructuring/array-unpack-optimisation/expected.js +++ b/test/core/fixtures/transformation/es6.destructuring/array-unpack-optimisation/expected.js @@ -22,7 +22,7 @@ var b = _ref2[1]; var _ref3 = [a, b]; var a = _ref3[0]; var b = _ref3[1]; -var _temp = [a[1], a[0]]; -a[0] = _temp[0]; -a[1] = _temp[1]; -_temp; +var _ref4 = [a[1], a[0]]; +a[0] = _ref4[0]; +a[1] = _ref4[1]; +_ref4; diff --git a/test/core/fixtures/transformation/es6.destructuring/assignment-expression-completion-record/expected.js b/test/core/fixtures/transformation/es6.destructuring/assignment-expression-completion-record/expected.js index 8f31c828a4..0693a629b6 100644 --- a/test/core/fixtures/transformation/es6.destructuring/assignment-expression-completion-record/expected.js +++ b/test/core/fixtures/transformation/es6.destructuring/assignment-expression-completion-record/expected.js @@ -1,7 +1,7 @@ "use strict"; var x, y; -var _temp = [1, 2]; -x = _temp[0]; -y = _temp[1]; -_temp; +var _ref = [1, 2]; +x = _ref[0]; +y = _ref[1]; +_ref; diff --git a/test/core/fixtures/transformation/es6.destructuring/assignment-expression/expected.js b/test/core/fixtures/transformation/es6.destructuring/assignment-expression/expected.js index 72bddcac55..5be82d8a2e 100644 --- a/test/core/fixtures/transformation/es6.destructuring/assignment-expression/expected.js +++ b/test/core/fixtures/transformation/es6.destructuring/assignment-expression/expected.js @@ -1,5 +1,5 @@ "use strict"; -var _temp; +var _ref; -console.log((_temp = [123], x = _temp[0], _temp)); +console.log((_ref = [123], x = _ref[0], _ref));