fix object rest/spread in arrow function params - fixes #2631
This commit is contained in:
parent
8ffc7012cc
commit
72b6e42b34
@ -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);
|
||||
|
||||
3
packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/actual.js
vendored
Normal file
3
packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
var foo = ( { title, ...other } ) => {
|
||||
|
||||
};
|
||||
221
packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/expected.json
vendored
Normal file
221
packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/expected.json
vendored
Normal 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": []
|
||||
}
|
||||
}
|
||||
3
packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/options.json
vendored
Normal file
3
packages/babylon/test/fixtures/harmony/arrow-functions/object-rest-spread/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["objectRestSpread"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user