Skip to content

Commit

Permalink
[[FEAT]] Implement support for ES8 trailing commas
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Jan 25, 2019
1 parent dc29e78 commit 29cab1f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 210 deletions.
24 changes: 18 additions & 6 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,12 +1062,11 @@ var JSHINT = (function() {
case "}":
case "]":
case ",":
case ")":
if (opts.allowTrailing) {
return true;
}

/* falls through */
case ")":
error("E024", state.tokens.next, state.tokens.next.value);
return false;
}
Expand Down Expand Up @@ -2952,7 +2951,15 @@ var JSHINT = (function() {
if (state.tokens.next.id !== ",") {
break;
}
parseComma();
parseComma({ allowTrailing: true });

if (state.tokens.next.id === ")") {
if (!state.inES8()) {
warning("W119", state.tokens.curr, "Trailing comma in arguments lists", "8");
}

break;
}
}
}

Expand Down Expand Up @@ -3429,13 +3436,18 @@ var JSHINT = (function() {

// now we have evaluated the default expression, add the variable to the param scope
currentParams.forEach(addParam);

if (state.tokens.next.id === ",") {
if (pastRest) {
warning("W131", state.tokens.next);
}
parseComma();
} else {
parseComma({ allowTrailing: true });
}

if (state.tokens.next.id === ")") {
if (state.tokens.curr.id === "," && !state.inES8()) {
warning("W119", state.tokens.curr, "Trailing comma in function parameters", "8");
}

advance(")", next);
return {
arity: arity,
Expand Down
9 changes: 9 additions & 0 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ var state = {
return this.option.moz;
},

/**
* Determine if constructs introduced in ECMAScript 8 should be accepted.
*
* @returns {boolean}
*/
inES8: function() {
return this.esVersion >= 8;
},

/**
* Determine if constructs introduced in ECMAScript 7 should be accepted.
*
Expand Down

0 comments on commit 29cab1f

Please sign in to comment.