Skip to content

Commit

Permalink
Fix syntax error for getter and setter with ts and estree plugin (#12333
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sosukesuzuki committed Nov 9, 2020
1 parent 3227914 commit ad8a4d6
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -2791,7 +2791,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
method: N.ObjectMethod | N.ClassMethod,
): number {
const baseCount = super.getGetterSetterExpectedParamCount(method);
const firstParam = method.params[0];
const params = this.getObjectOrClassMethodParams(method);
const firstParam = params[0];
const hasContextParam =
firstParam &&
firstParam.type === "Identifier" &&
Expand Down
@@ -0,0 +1,4 @@
({ set x(foo) {} });
({ get x() { return 1 } });
({ set x() {} });
({ get x(x) {} });
@@ -0,0 +1,203 @@
{
"type": "File",
"start":0,"end":85,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":18}},
"errors": [
"SyntaxError: setter must have exactly one formal parameter (3:3)",
"SyntaxError: getter must not have any formal parameters (4:3)"
],
"program": {
"type": "Program",
"start":0,"end":85,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":18}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
"expression": {
"type": "ObjectExpression",
"start":1,"end":18,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":18}},
"extra": {
"parenthesized": true,
"parenStart": 0
},
"properties": [
{
"type": "Property",
"start":3,"end":16,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":16}},
"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",
"value": {
"type": "FunctionExpression",
"start":8,"end":16,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":16}},
"id": null,
"generator": false,
"async": false,
"expression": false,
"params": [
{
"type": "Identifier",
"start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"},
"name": "foo"
}
],
"body": {
"type": "BlockStatement",
"start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16}},
"body": []
}
},
"shorthand": false
}
]
}
},
{
"type": "ExpressionStatement",
"start":21,"end":48,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}},
"expression": {
"type": "ObjectExpression",
"start":22,"end":46,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":25}},
"extra": {
"parenthesized": true,
"parenStart": 21
},
"properties": [
{
"type": "Property",
"start":24,"end":44,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":23}},
"method": false,
"key": {
"type": "Identifier",
"start":28,"end":29,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8},"identifierName":"x"},
"name": "x"
},
"computed": false,
"kind": "get",
"value": {
"type": "FunctionExpression",
"start":29,"end":44,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":23}},
"id": null,
"generator": false,
"async": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":32,"end":44,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":23}},
"body": [
{
"type": "ReturnStatement",
"start":34,"end":42,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":21}},
"argument": {
"type": "Literal",
"start":41,"end":42,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":21}},
"value": 1,
"raw": "1"
}
}
]
}
},
"shorthand": false
}
]
}
},
{
"type": "ExpressionStatement",
"start":49,"end":66,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":17}},
"expression": {
"type": "ObjectExpression",
"start":50,"end":64,"loc":{"start":{"line":3,"column":1},"end":{"line":3,"column":15}},
"extra": {
"parenthesized": true,
"parenStart": 49
},
"properties": [
{
"type": "Property",
"start":52,"end":62,"loc":{"start":{"line":3,"column":3},"end":{"line":3,"column":13}},
"method": false,
"key": {
"type": "Identifier",
"start":56,"end":57,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":8},"identifierName":"x"},
"name": "x"
},
"computed": false,
"kind": "set",
"value": {
"type": "FunctionExpression",
"start":57,"end":62,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":13}},
"id": null,
"generator": false,
"async": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":60,"end":62,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":13}},
"body": []
}
},
"shorthand": false
}
]
}
},
{
"type": "ExpressionStatement",
"start":67,"end":85,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":18}},
"expression": {
"type": "ObjectExpression",
"start":68,"end":83,"loc":{"start":{"line":4,"column":1},"end":{"line":4,"column":16}},
"extra": {
"parenthesized": true,
"parenStart": 67
},
"properties": [
{
"type": "Property",
"start":70,"end":81,"loc":{"start":{"line":4,"column":3},"end":{"line":4,"column":14}},
"method": false,
"key": {
"type": "Identifier",
"start":74,"end":75,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":8},"identifierName":"x"},
"name": "x"
},
"computed": false,
"kind": "get",
"value": {
"type": "FunctionExpression",
"start":75,"end":81,"loc":{"start":{"line":4,"column":8},"end":{"line":4,"column":14}},
"id": null,
"generator": false,
"async": false,
"expression": false,
"params": [
{
"type": "Identifier",
"start":76,"end":77,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":10},"identifierName":"x"},
"name": "x"
}
],
"body": {
"type": "BlockStatement",
"start":79,"end":81,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":14}},
"body": []
}
},
"shorthand": false
}
]
}
}
]
}
}

0 comments on commit ad8a4d6

Please sign in to comment.