Closed
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Repro
// the code you're trying to parse
class Foo {
readonly bar() {}
declare baz() {}
}
// the code you're using to do the parse of the aforementioned code
import { parse } from '@typescript-eslint/typescript-estree';
const code = `
class Foo {
readonly bar() {}
declare baz() {}
}
`;
const ast = parse(code);
Expected Result
Expect that MethodDefinition
nodes have readonly
and declare
property.
AST
{
"type": "ClassDeclaration",
"id": {
"type": "Identifier",
"name": "Foo"
},
"body": {
"type": "ClassBody",
"body": [
{
"type": "MethodDefinition",
"key": {
"type": "Identifier",
"name": "bar"
},
"value": {
"type": "FunctionExpression",
"id": null,
"generator": false,
"expression": false,
"async": false,
"body": {
"type": "BlockStatement",
"body": []
},
"params": []
},
"computed": false,
"static": false,
"kind": "method",
+ "readonly": true
},
{
"type": "MethodDefinition",
"key": {
"type": "Identifier",
"name": "baz"
},
"value": {
"type": "FunctionExpression",
"id": null,
"generator": false,
"expression": false,
"async": false,
"body": {
"type": "BlockStatement",
"body": []
},
"params": []
},
"computed": false,
"static": false,
"kind": "method",
+ "declare": true
}
]
},
"superClass": null
}
Actual Result
AST
{
"type": "ClassDeclaration",
"id": {
"type": "Identifier",
"name": "Foo"
},
"body": {
"type": "ClassBody",
"body": [
{
"type": "MethodDefinition",
"key": {
"type": "Identifier",
"name": "bar"
},
"value": {
"type": "FunctionExpression",
"id": null,
"generator": false,
"expression": false,
"async": false,
"body": {
"type": "BlockStatement",
"body": []
},
"params": []
},
"computed": false,
"static": false,
"kind": "method"
},
{
"type": "MethodDefinition",
"key": {
"type": "Identifier",
"name": "baz"
},
"value": {
"type": "FunctionExpression",
"id": null,
"generator": false,
"expression": false,
"async": false,
"body": {
"type": "BlockStatement",
"body": []
},
"params": []
},
"computed": false,
"static": false,
"kind": "method"
}
]
},
"superClass": null
}
Additional Info
I know the above code is invalid as TypeScript program (TS Playground). But I think code formatters should correctly treat those cases. What do you think about?
If the request is accepted, I can work on this.
Versions
package | version |
---|---|
@typescript-eslint/typescript-estree |
master |
TypeScript |
4.1.2 |
node |
v14.8.0 |