From 462ff572b3cd2e1e1b1d3336c9fc718db3f68b7f Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Tue, 12 May 2015 13:19:21 -0700 Subject: [PATCH 1/2] Add failing test for trailing commas in methods --- test/acorn/tests-babel.js | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/acorn/tests-babel.js b/test/acorn/tests-babel.js index 71cfa9813b..5b429aba26 100644 --- a/test/acorn/tests-babel.js +++ b/test/acorn/tests-babel.js @@ -3255,6 +3255,65 @@ test("function log(n, op, val,) { }", { 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)", { ecmaVersion: 7, features: { "es7.trailingFunctionCommas": true } From 0452e0fdd216bc8db4cccd21f291ff84a8fb3e0f Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Tue, 12 May 2015 13:20:36 -0700 Subject: [PATCH 2/2] Allow trailing commas in methods --- src/acorn/src/expression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/acorn/src/expression.js b/src/acorn/src/expression.js index 6b8e842e8d..b820a6bf64 100755 --- a/src/acorn/src/expression.js +++ b/src/acorn/src/expression.js @@ -635,7 +635,7 @@ pp.parseMethod = function(isGenerator, isAsync) { let node = this.startNode() this.initFunction(node, isAsync) 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) { node.generator = isGenerator }