diff --git a/src/parser/lval.js b/src/parser/lval.js index da712e3298..853765bee2 100644 --- a/src/parser/lval.js +++ b/src/parser/lval.js @@ -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": @@ -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; diff --git a/test/fixtures/es2015/destructuring/nested/actual.js b/test/fixtures/es2015/destructuring/nested/actual.js new file mode 100644 index 0000000000..aa9fada3b4 --- /dev/null +++ b/test/fixtures/es2015/destructuring/nested/actual.js @@ -0,0 +1 @@ +({ x, ...{ y, z } } = o) diff --git a/test/fixtures/es2015/destructuring/nested/expected.json b/test/fixtures/es2015/destructuring/nested/expected.json new file mode 100644 index 0000000000..31bae95b7e --- /dev/null +++ b/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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/destructuring/nested/options.json b/test/fixtures/es2015/destructuring/nested/options.json new file mode 100644 index 0000000000..527f225b5b --- /dev/null +++ b/test/fixtures/es2015/destructuring/nested/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["objectRestSpread"] +}