diff --git a/lib/6to5/transformation/helpers/build-binary-assignment-operator-transformer.js b/lib/6to5/transformation/helpers/build-binary-assignment-operator-transformer.js index 5822026ec6..7a4011a79e 100644 --- a/lib/6to5/transformation/helpers/build-binary-assignment-operator-transformer.js +++ b/lib/6to5/transformation/helpers/build-binary-assignment-operator-transformer.js @@ -13,6 +13,9 @@ module.exports = function (exports, opts) { }; exports.ExpressionStatement = function (node, parent, scope, context, file) { + // hit the `AssignmentExpression` one below + if (file.isConsequenceExpressionStatement(node)) return; + var expr = node.expression; if (!isAssignment(expr)) return; @@ -27,13 +30,11 @@ module.exports = function (exports, opts) { }; exports.AssignmentExpression = function (node, parent, scope, context, file) { - if (t.isExpressionStatement(parent)) return; if (!isAssignment(node)) return; var nodes = []; var exploded = explode(node.left, nodes, file, scope); - nodes.push(opts.build(exploded.uid, node.right)); - nodes.push(exploded.ref); + nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right))); return t.toSequenceExpression(nodes, scope); }; diff --git a/lib/6to5/transformation/helpers/build-conditional-assignment-operator-transformer.js b/lib/6to5/transformation/helpers/build-conditional-assignment-operator-transformer.js index 9137b31b23..f72126415f 100644 --- a/lib/6to5/transformation/helpers/build-conditional-assignment-operator-transformer.js +++ b/lib/6to5/transformation/helpers/build-conditional-assignment-operator-transformer.js @@ -9,6 +9,9 @@ module.exports = function (exports, opts) { }; exports.ExpressionStatement = function (node, parent, scope, context, file) { + // hit the `AssignmentExpression` one below + if (file.isConsequenceExpressionStatement(node)) return; + var expr = node.expression; if (!opts.is(expr, file)) return; @@ -25,7 +28,6 @@ module.exports = function (exports, opts) { }; exports.AssignmentExpression = function (node, parent, scope, context, file) { - if (t.isExpressionStatement(parent)) return; if (!opts.is(node, file)) return; var nodes = []; diff --git a/lib/6to5/transformation/transformers/es6/destructuring.js b/lib/6to5/transformation/transformers/es6/destructuring.js index 6bcd0fa90d..5e3f97ca17 100644 --- a/lib/6to5/transformation/transformers/es6/destructuring.js +++ b/lib/6to5/transformation/transformers/es6/destructuring.js @@ -236,6 +236,7 @@ exports.CatchClause = function (node, parent, scope, context, file) { exports.ExpressionStatement = function (node, parent, scope, context, file) { var expr = node.expression; if (expr.type !== "AssignmentExpression") return; + if (file.isConsequenceExpressionStatement(node)) return; if (!t.isPattern(expr.left)) return; @@ -256,7 +257,6 @@ exports.ExpressionStatement = function (node, parent, scope, context, file) { }; exports.AssignmentExpression = function (node, parent, scope, context, file) { - if (parent.type === "ExpressionStatement") return; if (!t.isPattern(node.left)) return; var ref = scope.generateUidIdentifier("temp"); diff --git a/lib/6to5/transformation/transformers/es7/abstract-references.js b/lib/6to5/transformation/transformers/es7/abstract-references.js index 3de864c58e..fa1ed60dfa 100644 --- a/lib/6to5/transformation/transformers/es7/abstract-references.js +++ b/lib/6to5/transformation/transformers/es7/abstract-references.js @@ -7,8 +7,8 @@ var t = require("../../../types"); exports.experimental = true; -var container = function (parent, call, ret) { - if (t.isExpressionStatement(parent)) { +var container = function (parent, call, ret, file) { + if (t.isExpressionStatement(parent) && !file.isConsequenceExpressionStatement(parent)) { // we don't need to worry about return values return call; } else { @@ -23,7 +23,7 @@ var container = function (parent, call, ret) { } }; -exports.AssignmentExpression = function (node, parent, scope) { +exports.AssignmentExpression = function (node, parent, scope, context, file) { var left = node.left; if (!t.isVirtualPropertyExpression(left)) return; @@ -60,10 +60,10 @@ exports.AssignmentExpression = function (node, parent, scope) { ]); } - return container(parent, call, value); + return container(parent, call, value, file); }; -exports.UnaryExpression = function (node, parent) { +exports.UnaryExpression = function (node, parent, scope, context, file) { var arg = node.argument; if (!t.isVirtualPropertyExpression(arg)) return; if (node.operator !== "delete") return; @@ -73,7 +73,7 @@ exports.UnaryExpression = function (node, parent) { OBJECT: arg.object }); - return container(parent, call, t.literal(true)); + return container(parent, call, t.literal(true), file); }; exports.CallExpression = function (node, parent, scope) { diff --git a/lib/6to5/transformation/transformers/spec/proto-to-assign.js b/lib/6to5/transformation/transformers/spec/proto-to-assign.js index ecf6b4d113..3e0b35f877 100644 --- a/lib/6to5/transformation/transformers/spec/proto-to-assign.js +++ b/lib/6to5/transformation/transformers/spec/proto-to-assign.js @@ -20,7 +20,6 @@ exports.optional = true; exports.secondPass = true; exports.AssignmentExpression = function (node, parent, scope, context, file) { - if (t.isExpressionStatement(parent)) return; if (!isProtoAssignmentExpression(node)) return; var nodes = []; diff --git a/test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js b/test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js index 86a33753a9..3119676676 100644 --- a/test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js +++ b/test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js @@ -1 +1,2 @@ num **= 2; +; diff --git a/test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js b/test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js index c1803c3164..cd3678c7fe 100644 --- a/test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js +++ b/test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js @@ -1,3 +1,4 @@ "use strict"; num = Math.pow(num, 2); +;