Merge pull request #1511 from amasad/trailing-methods

Trailing commas in methods
This commit is contained in:
Sebastian McKenzie 2015-05-12 21:46:18 +01:00
commit 85cd0465fa
2 changed files with 60 additions and 1 deletions

View File

@ -635,7 +635,7 @@ pp.parseMethod = function(isGenerator, isAsync) {
let node = this.startNode() let node = this.startNode()
this.initFunction(node, isAsync) this.initFunction(node, isAsync)
this.expect(tt.parenL) this.expect(tt.parenL)
node.params = this.parseBindingList(tt.parenR, false, false) node.params = this.parseBindingList(tt.parenR, false, this.options.features["es7.trailingFunctionCommas"])
if (this.options.ecmaVersion >= 6) { if (this.options.ecmaVersion >= 6) {
node.generator = isGenerator node.generator = isGenerator
} }

View File

@ -3255,6 +3255,65 @@ test("function log(n, op, val,) { }", {
features: { "es7.trailingFunctionCommas": true } features: { "es7.trailingFunctionCommas": true }
}); });
test("class Foo { bar(a,) { } }", {
type: "Program",
start: 0,
end: 25,
body: [{
type: "ClassDeclaration",
start: 0,
end: 25,
id: {
type: "Identifier",
name: "Foo",
start: 6,
end: 9
},
superClass: null,
body: {
type: "ClassBody",
start: 10,
end: 25,
body: [{
type: "MethodDefinition",
start: 12,
end: 23,
static: false,
key: {
type: "Identifier",
start: 12,
end: 15,
name: "bar"
},
kind: "method",
value: {
type: "FunctionExpression",
start: 15,
end: 23,
id: null,
params: [{
type: "Identifier",
name: "a",
start: 16,
end: 17
}],
generator: false,
body: {
type: "BlockStatement",
start: 20,
end: 23,
body: []
},
expression: false
}
}]
}
}]
}, {
ecmaVersion: 7,
features: { "es7.trailingFunctionCommas": true }
});
testFail("log(,);", "Unexpected token (1:4)", { testFail("log(,);", "Unexpected token (1:4)", {
ecmaVersion: 7, ecmaVersion: 7,
features: { "es7.trailingFunctionCommas": true } features: { "es7.trailingFunctionCommas": true }