Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid setter parse #12076

Merged
merged 2 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/babel-parser/src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,7 @@ export default class ExpressionParser extends LValParser {

if (
method.kind === "set" &&
method.params.length !== 0 &&
method.params[method.params.length - 1].type === "RestElement"
) {
this.raise(start, Errors.BadSetterRestParameter);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ set x(){} })
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"type": "File",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"errors": [
"SyntaxError: setter must have exactly one formal parameter (1:3)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but I think we can improve this error message:

A setter must have exactly one parameter.

Or Typescript's:

A 'set' accessor must have exactly one parameter.

],
"program": {
"type": "Program",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"expression": {
"type": "ObjectExpression",
"start":1,"end":14,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":14}},
"properties": [
{
"type": "ObjectMethod",
"start":3,"end":12,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":12}},
"method": false,
"key": {
"type": "Identifier",
"start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"x"},
"name": "x"
},
"computed": false,
"kind": "set",
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":10,"end":12,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":12}},
"body": [],
"directives": []
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}