Skip to content

Commit

Permalink
Convert argument of SpreadElement correctly to assignable (babel#518) (
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 11, 2017
1 parent 28985e7 commit 54399ab
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/parser/lval.js
Expand Up @@ -36,6 +36,8 @@ pp.toAssignable = function (node, isBinding, contextDescription) {

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

case "ArrayExpression":
Expand Down Expand Up @@ -77,7 +79,11 @@ pp.toAssignableList = function (exprList, isBinding, contextDescription) {
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
@@ -0,0 +1 @@
({ x, ...{ y, z } } = o)
300 changes: 300 additions & 0 deletions test/fixtures/es2015/destructuring/nested/expected.json
@@ -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,
"shorthand": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "x"
},
"name": "x"
},
"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": "RestProperty",
"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,
"shorthand": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "y"
},
"name": "y"
},
"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,
"shorthand": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "z"
},
"name": "z"
},
"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
@@ -0,0 +1,3 @@
{
"plugins": ["objectRestSpread"]
}

0 comments on commit 54399ab

Please sign in to comment.