[ES7] Trailing comma in function parameter list

Currenly a stage 1 proposal.
See https://github.com/jeffmo/es-trailing-function-commas.
This commit is contained in:
Aluísio Augusto Silva Gonçalves 2015-04-06 09:10:44 -03:00
parent 320a39f4c4
commit 584532cc2c
9 changed files with 33 additions and 2 deletions

View File

@ -224,7 +224,7 @@ pp.parseSubscripts = function(base, start, noCalls) {
} else if (!noCalls && this.eat(tt.parenL)) {
let node = this.startNodeAt(start)
node.callee = base
node.arguments = this.parseExprList(tt.parenR, false)
node.arguments = this.parseExprList(tt.parenR, this.options.features["es7.trailingFunctionCommas"])
return this.parseSubscripts(this.finishNode(node, "CallExpression"), start, noCalls)
} else if (this.type === tt.backQuote) {
let node = this.startNodeAt(start)

View File

@ -458,7 +458,7 @@ pp.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
pp.parseFunctionParams = function(node) {
this.expect(tt.parenL)
node.params = this.parseBindingList(tt.parenR, false, false)
node.params = this.parseBindingList(tt.parenR, false, this.options.features["es7.trailingFunctionCommas"])
}
// Parse a class declaration or literal (depending on the

View File

@ -0,0 +1,7 @@
export var metadata = {
stage: 1
};
export function check() {
return false;
}

View File

@ -1,5 +1,6 @@
export default {
"es7.classProperties": require("./es7/class-properties"),
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
"es7.asyncFunctions": require("./es7/async-functions"),
"es7.decorators": require("./es7/decorators"),

View File

@ -0,0 +1,4 @@
Math.max(1,
2,
3,
);

View File

@ -0,0 +1,3 @@
"use strict";
Math.max(1, 2, 3);

View File

@ -0,0 +1,8 @@
function thisIsAFunctionWithAVeryLongNameAndWayTooManyParameters(
thisIsTheFirstParameter, andThisOneIsRelatedToIt,
butNotThisOne,
andNeitherThis,
inFactThereArentThatManyParameters,
) {
throw null;
}

View File

@ -0,0 +1,5 @@
"use strict";
function thisIsAFunctionWithAVeryLongNameAndWayTooManyParameters(thisIsTheFirstParameter, andThisOneIsRelatedToIt, butNotThisOne, andNeitherThis, inFactThereArentThatManyParameters) {
throw null;
}

View File

@ -0,0 +1,3 @@
{
"optional": ["es7.trailingFunctionCommas"]
}