diff --git a/packages/babylon/src/parser/lval.js b/packages/babylon/src/parser/lval.js index 4955ff5b5b..c534f90915 100644 --- a/packages/babylon/src/parser/lval.js +++ b/packages/babylon/src/parser/lval.js @@ -21,22 +21,26 @@ pp.toAssignable = function (node, isBinding) { case "ObjectExpression": node.type = "ObjectPattern"; for (let prop of (node.properties: Array)) { - if (prop.type === "SpreadProperty") continue; - if (prop.type === "ObjectMethod") { if (prop.kind === "get" || prop.kind === "set") { this.raise(prop.key.start, "Object pattern can't contain getter or setter"); } else { this.raise(prop.key.start, "Object pattern can't contain methods"); } - } - - if (prop.type === "ObjectProperty") { - this.toAssignable(prop.value, isBinding); + } else { + this.toAssignable(prop, isBinding); } } break; + case "ObjectProperty": + this.toAssignable(node.value, isBinding); + break; + + case "SpreadProperty": + node.type = "RestProperty"; + break; + case "ArrayExpression": node.type = "ArrayPattern"; this.toAssignableList(node.elements, isBinding); diff --git a/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/actual.js b/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/actual.js new file mode 100644 index 0000000000..6beb712759 --- /dev/null +++ b/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/actual.js @@ -0,0 +1,3 @@ +var foo = ( { title, ...other } ) => { + +}; diff --git a/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/expected.json b/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/expected.json new file mode 100644 index 0000000000..00b780b1c4 --- /dev/null +++ b/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/expected.json @@ -0,0 +1,221 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": "foo" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "ObjectPattern", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": "title" + }, + "value": { + "type": "Identifier", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": "title" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "RestProperty", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "argument": { + "type": "Identifier", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "name": "other" + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/options.json b/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/options.json new file mode 100644 index 0000000000..4de042a697 --- /dev/null +++ b/packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["objectRestSpread"] +}