Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

readonly anddeclare invalid property forMethodDefinition. #2908

Closed
Labels
package: typescript-estreeIssues related to @typescript-eslint/typescript-estreewontfixThis will not be worked on
@sosukesuzuki

Description

@sosukesuzuki
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I haveread the FAQ and my problem is not listed.

Repro

// the code you're trying to parseclassFoo{readonlybar(){}declarebaz(){}}
// the code you're using to do the parse of the aforementioned codeimport{parse}from'@typescript-eslint/typescript-estree';constcode=`class Foo {  readonly bar() {}  declare baz() {}}`;constast=parse(code);

Expected Result

Expect thatMethodDefinition nodes havereadonly anddeclare 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

prettier/prettier#9760

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

packageversion
@typescript-eslint/typescript-estreemaster
TypeScript4.1.2
nodev14.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: typescript-estreeIssues related to @typescript-eslint/typescript-estreewontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp