Skip to content

Commit

Permalink
fix missing parentheses around NaN/Infinity shorthands (#1726)
Browse files Browse the repository at this point in the history
fixes #1724
fixes #1725
  • Loading branch information
alexlamsl authored Mar 29, 2017
1 parent 09f77c7 commit 2e41cd6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,9 @@ function OutputStream(options) {
var p = output.parent();
return p instanceof AST_PropAccess && p.expression === this
|| p instanceof AST_Call && p.expression === this
|| p instanceof AST_Unary && p.operator != "+" && p.operator != "-";
|| p instanceof AST_Unary && p.operator != "+" && p.operator != "-"
|| p instanceof AST_Binary && p.right === this
&& (p.operator == "/" || p.operator == "%");
});

PARENS(AST_Seq, function(output){
Expand Down
24 changes: 24 additions & 0 deletions test/compress/issue-597.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,27 @@ beautify_on_2: {
}
expect_exact: "console.log(null.toString(), (void 0).toString());"
}

issue_1724: {
input: {
var a = 0;
++a % Infinity | Infinity ? a++ : 0;
console.log(a);
}
expect: {
var a = 0;
++a % (1/0) | 1/0 ? a++ : 0;
console.log(a);
}
expect_stdout: "2"
}

issue_1725: {
input: {
([].length === 0) % Infinity ? console.log("PASS") : console.log("FAIL");
}
expect: {
(0 === [].length) % (1/0) ? console.log("PASS") : console.log("FAIL");
}
expect_stdout: "PASS"
}

0 comments on commit 2e41cd6

Please sign in to comment.