Skip to content

Commit

Permalink
parse out-of-range numerals correctly (#4781)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Mar 15, 2021
1 parent 176581d commit aa6e33e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/parse.js
Expand Up @@ -1763,40 +1763,45 @@ function parse($TEXT, options) {
};

function as_atom_node() {
var tok = S.token, ret;
var ret, tok = S.token, value = tok.value;
switch (tok.type) {
case "num":
ret = new AST_Number({ start: tok, end: tok, value: tok.value });
if (isFinite(value)) {
ret = new AST_Number({ value: value });
} else {
ret = new AST_Infinity();
if (value < 0) ret = new AST_UnaryPrefix({ operator: "-", expression: ret });
}
break;
case "bigint":
ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });
ret = new AST_BigInt({ value: value });
break;
case "string":
ret = new AST_String({
start : tok,
end : tok,
value : tok.value,
quote : tok.quote
});
ret = new AST_String({ value : value, quote : tok.quote });
break;
case "regexp":
ret = new AST_RegExp({ start: tok, end: tok, value: tok.value });
ret = new AST_RegExp({ value: value });
break;
case "atom":
switch (tok.value) {
switch (value) {
case "false":
ret = new AST_False({ start: tok, end: tok });
ret = new AST_False();
break;
case "true":
ret = new AST_True({ start: tok, end: tok });
ret = new AST_True();
break;
case "null":
ret = new AST_Null({ start: tok, end: tok });
ret = new AST_Null();
break;
default:
unexpected();
}
break;
default:
unexpected();
}
next();
ret.start = ret.end = tok;
return ret;
}

Expand Down
7 changes: 7 additions & 0 deletions test/compress/numbers.js
@@ -1,3 +1,10 @@
literal_infinity: {
input: {
console.log(2e308, -1e2345);
}
expect_exact: "console.log(1/0,-(1/0));"
}

parentheses_for_prototype_functions: {
beautify = {
beautify: true,
Expand Down

0 comments on commit aa6e33e

Please sign in to comment.