support BigInt literals (#4583)
This commit is contained in:
22
lib/parse.js
22
lib/parse.js
@@ -280,9 +280,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
}
|
||||
|
||||
function read_while(pred) {
|
||||
var ret = "", ch, i = 0;
|
||||
while ((ch = peek()) && pred(ch, i++))
|
||||
ret += next();
|
||||
var ret = "", ch;
|
||||
while ((ch = peek()) && pred(ch)) ret += next();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -292,16 +291,14 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
function read_num(prefix) {
|
||||
var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".";
|
||||
var num = read_while(function(ch, i) {
|
||||
var num = read_while(function(ch) {
|
||||
var code = ch.charCodeAt(0);
|
||||
switch (code) {
|
||||
case 120: case 88: // xX
|
||||
return has_x ? false : (has_x = true);
|
||||
case 101: case 69: // eE
|
||||
return has_x ? true : has_e ? false : (has_e = after_e = true);
|
||||
case 45: // -
|
||||
return after_e || (i == 0 && !prefix);
|
||||
case 43: // +
|
||||
case 43: case 45: // +-
|
||||
return after_e;
|
||||
case (after_e = false, 46): // .
|
||||
return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
|
||||
@@ -315,8 +312,9 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
num = num.replace(has_x ? /([1-9a-f]|.0)_(?=[0-9a-f])/gi : /([1-9]|.0)_(?=[0-9])/gi, "$1");
|
||||
}
|
||||
var valid = parse_js_number(num);
|
||||
if (!isNaN(valid)) return token("num", valid);
|
||||
parse_error("Invalid syntax: " + num);
|
||||
if (isNaN(valid)) parse_error("Invalid syntax: " + num);
|
||||
if (has_dot || has_e || peek() != "n") return token("num", valid);
|
||||
return token("bigint", num.toLowerCase() + next());
|
||||
}
|
||||
|
||||
function read_escaped_char(in_string) {
|
||||
@@ -635,7 +633,7 @@ var PRECEDENCE = function(a, ret) {
|
||||
["*", "/", "%"]
|
||||
], {});
|
||||
|
||||
var ATOMIC_START_TOKEN = makePredicate("atom num regexp string");
|
||||
var ATOMIC_START_TOKEN = makePredicate("atom bigint num regexp string");
|
||||
|
||||
/* -----[ Parser ]----- */
|
||||
|
||||
@@ -783,6 +781,7 @@ function parse($TEXT, options) {
|
||||
semicolon();
|
||||
return dir ? new AST_Directive(body) : new AST_SimpleStatement({ body: body });
|
||||
case "num":
|
||||
case "bigint":
|
||||
case "regexp":
|
||||
case "operator":
|
||||
case "atom":
|
||||
@@ -1361,6 +1360,9 @@ function parse($TEXT, options) {
|
||||
case "num":
|
||||
ret = new AST_Number({ start: tok, end: tok, value: tok.value });
|
||||
break;
|
||||
case "bigint":
|
||||
ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });
|
||||
break;
|
||||
case "string":
|
||||
ret = new AST_String({
|
||||
start : tok,
|
||||
|
||||
Reference in New Issue
Block a user