diff --git a/lib/6to5/transformation/transformers/destructuring.js b/lib/6to5/transformation/transformers/destructuring.js index 8522df8b1b..67690661e5 100644 --- a/lib/6to5/transformation/transformers/destructuring.js +++ b/lib/6to5/transformation/transformers/destructuring.js @@ -11,21 +11,7 @@ var buildVariableAssign = function (kind, id, init) { } }; -var normalise = function (node) { - if (t.isParenthesizedExpression(node)) { - return node.expression; - } else { - return node; - } -}; - -var isPattern = function (node) { - return t.isPattern(normalise(node)); -}; - var push = function (kind, nodes, elem, parentId) { - elem = normalise(elem); - if (t.isObjectPattern(elem)) { pushObjectPattern(kind, nodes, elem, parentId); } else if (t.isArrayPattern(elem)) { @@ -42,7 +28,7 @@ var pushObjectPattern = function (kind, nodes, pattern, parentId) { var pattern2 = prop.value; var patternId2 = t.memberExpression(parentId, prop.key); - if (isPattern(pattern2)) { + if (t.isPattern(pattern2)) { push(kind, nodes, pattern2, patternId2); } else { nodes.push(buildVariableAssign(kind, pattern2, patternId2)); @@ -94,7 +80,7 @@ exports.ForOfStatement = function (node, parent, file, scope) { if (!t.isVariableDeclaration(declar)) return; var pattern = declar.declarations[0].id; - if (!isPattern(pattern)) return; + if (!t.isPattern(pattern)) return; var key = t.identifier(file.generateUid("ref", scope)); node.left = t.variableDeclaration(declar.kind, [ @@ -117,7 +103,7 @@ exports.Function = function (node, parent, file, scope) { var hasDestructuring = false; node.params = node.params.map(function (pattern) { - if (!isPattern(pattern)) return pattern; + if (!t.isPattern(pattern)) return pattern; hasDestructuring = true; var parentId = t.identifier(file.generateUid("ref", scope)); @@ -146,7 +132,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) { var expr = node.expression; if (expr.type !== "AssignmentExpression") return; - if (!isPattern(expr.left)) return; + if (!t.isPattern(expr.left)) return; var nodes = []; @@ -167,7 +153,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) { var hasPattern = false; _.each(node.declarations, function (declar) { - if (isPattern(declar.id)) { + if (t.isPattern(declar.id)) { hasPattern = true; return false; } diff --git a/package.json b/package.json index 65030d52d4..45a8f3c221 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "chokidar": "0.10.5", "source-map-support": "0.2.8", "esutils": "1.1.4", - "acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/f5110383517eef0bea78c2da2a1fb01fbed74e4e.tar.gz", + "acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/49e421660af161af0e75c2fa066ea356d6650e69.tar.gz", "estraverse": "^1.7.0" }, "devDependencies": { diff --git a/test/fixtures/transformation/destructuring/assignment/actual.js b/test/fixtures/transformation/destructuring/assignment/actual.js index 653338ee9a..d14ce7e47d 100644 --- a/test/fixtures/transformation/destructuring/assignment/actual.js +++ b/test/fixtures/transformation/destructuring/assignment/actual.js @@ -1,2 +1 @@ [a, b] = f(); -({ x }) = e(); diff --git a/test/fixtures/transformation/destructuring/assignment/expected.js b/test/fixtures/transformation/destructuring/assignment/expected.js index eda9b31d15..792c6693a2 100644 --- a/test/fixtures/transformation/destructuring/assignment/expected.js +++ b/test/fixtures/transformation/destructuring/assignment/expected.js @@ -4,6 +4,3 @@ var _ref = f(); a = _ref[0]; b = _ref[1]; -var _ref2 = e(); - -x = _ref2.x;