Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Convert argument of SpreadElement correctly to assignable #518

Merged
merged 1 commit into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/parser/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export default class LValParser extends NodeUtils {

case "SpreadElement":
node.type = "RestElement";
const arg = node.argument;
this.toAssignable(arg, isBinding, contextDescription);
break;

case "ArrayExpression":
Expand Down Expand Up @@ -94,7 +96,11 @@ export default class LValParser extends NodeUtils {
last.type = "RestElement";
const arg = last.argument;
this.toAssignable(arg, isBinding, contextDescription);
if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") {
if (
arg.type !== "Identifier" &&
arg.type !== "MemberExpression" &&
arg.type !== "ArrayPattern"
) {
this.unexpected(arg.start);
}
--end;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es2015/destructuring/nested/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ x, ...{ y, z } } = o)
300 changes: 300 additions & 0 deletions test/fixtures/es2015/destructuring/nested/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
{
"type": "File",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"program": {
"type": "Program",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"expression": {
"type": "AssignmentExpression",
"start": 1,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 23
}
},
"operator": "=",
"left": {
"type": "ObjectPattern",
"start": 1,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 19
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "x"
},
"name": "x"
},
"shorthand": true,
"value": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "x"
},
"name": "x"
},
"extra": {
"shorthand": true
}
},
{
"type": "RestElement",
"start": 6,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 17
}
},
"argument": {
"type": "ObjectPattern",
"start": 9,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 17
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "y"
},
"name": "y"
},
"shorthand": true,
"value": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "y"
},
"name": "y"
},
"extra": {
"shorthand": true
}
},
{
"type": "ObjectProperty",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "z"
},
"name": "z"
},
"shorthand": true,
"value": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "z"
},
"name": "z"
},
"extra": {
"shorthand": true
}
}
]
}
}
]
},
"right": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 23
},
"identifierName": "o"
},
"name": "o"
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}
3 changes: 3 additions & 0 deletions test/fixtures/es2015/destructuring/nested/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["objectRestSpread"]
}