support spread syntax (#4328)

This commit is contained in:
Alex Lam S.L
2020-12-05 21:19:31 +00:00
committed by GitHub
parent d2d56e301e
commit 1e4985ed9e
8 changed files with 635 additions and 56 deletions

View File

@@ -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;