From 84c773a7ca53f0d0a0c7ec8734c8e916e85843fd Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 26 Jun 2015 00:37:33 +0100 Subject: [PATCH] add support for trailing commas in arrow function parameter lists - fixes #1841 --- src/expression.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/expression.js b/src/expression.js index dccf9962a8..ba94cd5249 100755 --- a/src/expression.js +++ b/src/expression.js @@ -432,9 +432,18 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) { } let innerStart = this.markPosition(), exprList = [], first = true - let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart + let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart, optionalCommaStart while (this.type !== tt.parenR) { - first ? first = false : this.expect(tt.comma) + if (first) { + first = false; + } else { + this.expect(tt.comma) + if (this.type === tt.parenR && this.options.features["es7.trailingFunctionCommas"]) { + optionalCommaStart = this.start + break + } + } + if (this.type === tt.ellipsis) { let spreadNodeStart = this.markPosition() spreadStart = this.start @@ -462,6 +471,7 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) { this.unexpected(this.lastTokStart) } } + if (optionalCommaStart) this.unexpected(optionalCommaStart) if (spreadStart) this.unexpected(spreadStart) if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start)