expand parameters

Conflicts:
	test/compress/harmony.js
This commit is contained in:
Fábio Santos
2015-04-13 01:26:26 +01:00
committed by Richard van Velzen
parent e8664e63ef
commit 9863f0efa3
5 changed files with 89 additions and 7 deletions

View File

@@ -526,9 +526,16 @@ function tokenizer($TEXT, filename, html5_comments) {
function handle_dot() {
next();
return is_digit(peek().charCodeAt(0))
? read_num(".")
: token("punc", ".");
if (is_digit(peek().charCodeAt(0))) {
return read_num(".");
}
if (peek() === ".") {
next(); // Consume second dot
next(); // Consume third dot
return token("expand", "...");
}
return token("punc", ".");
};
function read_word() {
@@ -1034,7 +1041,16 @@ function parse($TEXT, options) {
S.in_parameters = true;
while (!is("punc", ")")) {
if (first) first = false; else expect(",");
a.push(expression(false));
if (is("expand", "...")) {
next();
a.push(new AST_Expansion({
start: prev(),
symbol: as_symbol(AST_SymbolFunarg),
end: S.token,
}));
} else {
a.push(expression(false));
}
}
S.in_parameters = false;
var end = S.token
@@ -1475,13 +1491,32 @@ function parse($TEXT, options) {
return subscripts(new AST_Call({
start : start,
expression : expr,
args : expr_list(")"),
args : call_args(),
end : prev()
}), true);
}
return expr;
};
var call_args = embed_tokens(function call_args() {
var first = true;
var args = [];
while (!is("punc", ")")) {
if (first) first = false; else expect(",");
if (is("expand", "...")) {
next();
args.push(new AST_Expansion({
start: prev(),
symbol: as_symbol(AST_SymbolFunarg)
}));
} else {
args.push(expression(false));
}
}
next();
return args;
});
var maybe_unary = function(allow_calls) {
var start = S.token;
if (is("operator") && UNARY_PREFIX(start.value)) {