Skip to content

Commit

Permalink
ES6: spread element for function argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Jun 24, 2015
1 parent 8fea844 commit 2199b84
Show file tree
Hide file tree
Showing 33 changed files with 1,433 additions and 2 deletions.
11 changes: 9 additions & 2 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -3190,13 +3190,20 @@
// 11.2 Left-Hand-Side Expressions

function parseArguments() {
var args = [];
var args = [], expr;

expect('(');

if (!match(')')) {
while (startIndex < length) {
args.push(isolateCoverGrammar(parseAssignmentExpression));
if (match('...')) {
expr = new Node();
lex();
expr.finishSpreadElement(isolateCoverGrammar(parseAssignmentExpression));
} else {
expr = isolateCoverGrammar(parseAssignmentExpression);
}
args.push(expr);
if (match(')')) {
break;
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ES6/spread-element/call-multi-spread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f(...x, ...y, ...z);
178 changes: 178 additions & 0 deletions test/fixtures/ES6/spread-element/call-multi-spread.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"range": [
0,
20
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"type": "Program",
"body": [
{
"range": [
0,
20
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"type": "ExpressionStatement",
"expression": {
"range": [
0,
19
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"type": "CallExpression",
"callee": {
"range": [
0,
1
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
},
"type": "Identifier",
"name": "f"
},
"arguments": [
{
"range": [
2,
6
],
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 6
}
},
"type": "SpreadElement",
"argument": {
"range": [
5,
6
],
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
}
},
"type": "Identifier",
"name": "x"
}
},
{
"range": [
8,
12
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
}
},
"type": "SpreadElement",
"argument": {
"range": [
11,
12
],
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
},
"type": "Identifier",
"name": "y"
}
},
{
"range": [
14,
18
],
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 18
}
},
"type": "SpreadElement",
"argument": {
"range": [
17,
18
],
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 18
}
},
"type": "Identifier",
"name": "z"
}
}
]
}
}
]
}
1 change: 1 addition & 0 deletions test/fixtures/ES6/spread-element/call-spread-default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f(g, ...h = i);
162 changes: 162 additions & 0 deletions test/fixtures/ES6/spread-element/call-spread-default.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"range": [
0,
15
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"type": "Program",
"body": [
{
"range": [
0,
15
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"type": "ExpressionStatement",
"expression": {
"range": [
0,
14
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"type": "CallExpression",
"callee": {
"range": [
0,
1
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
},
"type": "Identifier",
"name": "f"
},
"arguments": [
{
"range": [
2,
3
],
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
}
},
"type": "Identifier",
"name": "g"
},
{
"range": [
5,
13
],
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 13
}
},
"type": "SpreadElement",
"argument": {
"range": [
8,
13
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 13
}
},
"type": "AssignmentExpression",
"operator": "=",
"left": {
"range": [
8,
9
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
},
"type": "Identifier",
"name": "h"
},
"right": {
"range": [
12,
13
],
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 13
}
},
"type": "Identifier",
"name": "i"
}
}
}
]
}
}
]
}
1 change: 1 addition & 0 deletions test/fixtures/ES6/spread-element/call-spread-first.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f(...x, y, z);
Loading

0 comments on commit 2199b84

Please sign in to comment.