use isConsequenceExpressionStatement to correctly evaluate expressions - fixes #502

This commit is contained in:
Sebastian McKenzie
2015-01-24 00:19:48 +11:00
parent 3167d66154
commit 75389b04a6
7 changed files with 16 additions and 12 deletions

View File

@@ -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);
};

View File

@@ -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 = [];

View File

@@ -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");

View File

@@ -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) {

View File

@@ -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 = [];

View File

@@ -1 +1,2 @@
num **= 2;
;

View File

@@ -1,3 +1,4 @@
"use strict";
num = Math.pow(num, 2);
;