Skip to content

Commit

Permalink
[[FIX]] Allow array literal form to follow spread operator in functio…
Browse files Browse the repository at this point in the history
…n call args.

Fixes jshintgh-2060

Squashed commit of the following:

commit cb9d868bc084bc1c4a25b105ce13e044f1cdec39
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Wed Dec 31 11:06:30 2014 -0500

    String condition, Additional tests

commit 6c1bb47ac9539b521083409079e8a0dbbf10944d
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Tue Dec 30 18:20:56 2014 -0500

    Removes unnecessary conditions

commit c02239ebcb7f9986a725c5d375fa448fd1ec3824
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Tue Dec 30 18:19:00 2014 -0500

    Cleanup "spread & rest operator support" tests

commit 80728050087907e21739325273915df0ab26b14e
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Tue Dec 30 17:37:00 2014 -0500

    Allow array literal form to follow spread operator in function call args. Fixes jshintgh-2060
  • Loading branch information
rwaldron committed Jan 4, 2015
1 parent 08c70e6 commit 1e8f171
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 24 deletions.
8 changes: 7 additions & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,13 @@ var JSHINT = (function () {
if (!state.option.esnext) {
warning("W119", this, "spread/rest operator");
}
if (!state.tokens.next.identifier) {

// TODO: Allow all AssignmentExpression
// once parsing permits.
if (!state.tokens.next.identifier &&
state.tokens.next.type !== "(string)" &&
!checkPunctuators(state.tokens.next, ["[", "("])) {

error("E030", state.tokens.next, state.tokens.next.value);
}
expression(150);
Expand Down
79 changes: 56 additions & 23 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3925,48 +3925,81 @@ exports["object ComputedPropertyName"] = function (test) {

exports["spread & rest operator support"] = function (test) {
var code = [
// spread operator
"function foo(a, b, c) {",
" console.log(a, b, c); ",
"}",
"var args = [ 0, 1, 2 ];",
// 1
// Spread Identifier
"foo(...args);",

// spread operator
// 2
// Spread Array Literal
"foo(...[]);",

// 3, 4
// Spread String Literal
"foo(...'');",
'foo(..."");',

// 5
// Spread Group
"foo(...([]));",

// 6, 7, 8
// Spread Operator
"let initial = [ 1, 2, 3, 4, 5 ];",
"let extended = [ ...initial, 6, 7, 8, 9 ];",
"let nest = [ ...[], 6, 7, 8, 9 ];",

// 9
// Rest Operator
"function foo(...args) {}",

// 10
// Rest Operator (Fat Arrow Params)
"let bar = (...args) => args;",

// rest operator
"(function foo(i, j, ...args) {",
" return args;",
"}());",
// 11
"foo(...[].entries());",

// rest operator on a fat arrow function
"let bar = (...args) => args;"
// 12
"foo(...(new Map()).set('a', 1).values());"
];

var run = TestRun(test);
run.test(code, {esnext: true});
TestRun(test)
.test(code, {esnext: true});

run = TestRun(test)
.addError(11, "'arrow function syntax (=>)' is only available in ES6 (use esnext option).")
TestRun(test)
.addError(1, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(2, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(3, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(4, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(5, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(7, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(8, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(11, "'spread/rest operator' is only available in ES6 (use esnext option).");

run.test(code, {moz: true});
.addError(9, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(10, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(10, "'arrow function syntax (=>)' is only available in ES6 (use esnext option).")
.addError(11, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(12, "'spread/rest operator' is only available in ES6 (use esnext option).")
.test(code, {moz: true});

run = TestRun(test)
TestRun(test)
.addError(1, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(2, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(3, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(4, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(5, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(6, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(7, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")

.addError(7, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(8, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(8, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(11, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(9, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(10, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(10, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(10, "'arrow function syntax (=>)' is only available in ES6 (use esnext option).")
.addError(11, "'spread/rest operator' is only available in ES6 (use esnext option).")
.addError(11, "'arrow function syntax (=>)' is only available in ES6 (use esnext option).");
run.test(code);
.addError(12, "'spread/rest operator' is only available in ES6 (use esnext option).")
.test(code);

test.done();
};
Expand Down

0 comments on commit 1e8f171

Please sign in to comment.