fix object rest/spread in arrow function params - fixes #2631

This commit is contained in:
Sebastian McKenzie 2015-11-03 11:14:12 +00:00
parent 8ffc7012cc
commit 72b6e42b34
4 changed files with 237 additions and 6 deletions

View File

@ -21,22 +21,26 @@ pp.toAssignable = function (node, isBinding) {
case "ObjectExpression":
node.type = "ObjectPattern";
for (let prop of (node.properties: Array<Object>)) {
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);

View File

@ -0,0 +1,3 @@
var foo = ( { title, ...other } ) => {
};

View File

@ -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": []
}
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["objectRestSpread"]
}