support spread syntax (#4328)
This commit is contained in:
26
lib/parse.js
26
lib/parse.js
@@ -501,7 +501,16 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
function handle_dot() {
|
||||
next();
|
||||
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||
var ch = peek();
|
||||
if (ch == ".") {
|
||||
var op = ".";
|
||||
do {
|
||||
op += ".";
|
||||
next();
|
||||
} while (peek() == ".");
|
||||
return token("operator", op);
|
||||
}
|
||||
return is_digit(ch.charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||
}
|
||||
|
||||
function read_word() {
|
||||
@@ -1316,6 +1325,12 @@ function parse($TEXT, options) {
|
||||
if (allow_trailing_comma && is("punc", closing)) break;
|
||||
if (is("punc", ",") && allow_empty) {
|
||||
a.push(new AST_Hole({ start: S.token, end: S.token }));
|
||||
} else if (is("operator", "...") && parser === expression) {
|
||||
a.push(new AST_Spread({
|
||||
start: S.token,
|
||||
expression: (next(), parser()),
|
||||
end: prev(),
|
||||
}));
|
||||
} else {
|
||||
a.push(parser());
|
||||
}
|
||||
@@ -1343,6 +1358,15 @@ function parse($TEXT, options) {
|
||||
// allow trailing comma
|
||||
if (!options.strict && is("punc", "}")) break;
|
||||
var start = S.token;
|
||||
if (is("operator", "...")) {
|
||||
next();
|
||||
a.push(new AST_Spread({
|
||||
start: start,
|
||||
expression: expression(false),
|
||||
end: prev(),
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
var key = as_property_key();
|
||||
if (is("punc", "(")) {
|
||||
var func_start = S.token;
|
||||
|
||||
Reference in New Issue
Block a user