Skip to content

Commit

Permalink
looks like comma-expressions should be explicitly forbidden in expres…
Browse files Browse the repository at this point in the history
…sions of the "conditional" (?) operator.

(cherry picked from commit c7b83e1)
  • Loading branch information
mishoo committed Sep 21, 2010
1 parent ad34b71 commit 315230b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/parse-js.js
Expand Up @@ -1098,15 +1098,13 @@ function parse($TEXT, strict_mode, embed_tokens) {
return expr_op(expr_atom(true), 0);
};

function maybe_conditional(commas) {
if (arguments.length == 0)
commas = true;
function maybe_conditional() {
var expr = expr_ops();
if (is("operator", "?")) {
next();
var yes = expression();
var yes = expression(false);
expect(":");
return as("conditional", expr, yes, expression(commas));
return as("conditional", expr, yes, expression(false));
}
return expr;
};
Expand All @@ -1116,14 +1114,12 @@ function parse($TEXT, strict_mode, embed_tokens) {
return expr == "name" || expr == "dot" || expr == "sub";
};

function maybe_assign(commas) {
if (arguments.length == 0)
commas = true;
var left = maybe_conditional(commas), val = S.token.value;
function maybe_assign() {
var left = maybe_conditional(), val = S.token.value;
if (is("operator") && HOP(ASSIGNMENT, val)) {
if (is_assignable(left)) {
next();
return as("assign", ASSIGNMENT[val], left, maybe_assign(commas));
return as("assign", ASSIGNMENT[val], left, maybe_assign());
}
croak("Invalid assignment");
}
Expand All @@ -1133,7 +1129,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
function expression(commas) {
if (arguments.length == 0)
commas = true;
var expr = maybe_assign(commas);
var expr = maybe_assign();
if (commas && is("punc", ",")) {
next();
return as("seq", expr, expression());
Expand Down

0 comments on commit 315230b

Please sign in to comment.