Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Missing visitor keys #4724

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

Closed
DMartens opened this issue Mar 24, 2022 · 3 comments · Fixed by #4731
Closed

Missing visitor keys #4724

DMartens opened this issue Mar 24, 2022 · 3 comments · Fixed by #4731
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: visitor-keys Issues related to @typescript-eslint/visitor-keys

Comments

@DMartens
Copy link
Contributor

I'm sorry for not using any template but none apply.
After filing #4705 I investigated and the reason for the missing parent property is that there missing visitor keys (in the issues case implements for TSInterfaceDeclaration).
As such ESLint does not traverse the child nodes and therefore does not add the parent property.

I built the ast spec and compared the "enhanced" and TypeScript-only node types and found more missing keys.
The missing keys are:
MethodDefinition: typeParameters
TSInterfaceDeclaration: implements
TSNamedTupleMember: label
TSEnumDeclaration: modifiers
TSModuleDeclaration: modifiers

Versions

package version
@typescript-eslint/typescript-estree 5.16.0
@DMartens DMartens added package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for team members to take a look labels Mar 24, 2022
@bradzacher bradzacher added bug Something isn't working accepting prs Go ahead, send a pull request that resolves this issue good first issue Good for newcomers package: visitor-keys Issues related to @typescript-eslint/visitor-keys and removed package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for team members to take a look labels Mar 25, 2022
@JoshuaKGoldberg
Copy link
Member

TSInterfaceDeclaration: implements

Is this correct? I see in the typescript-eslint/parser AST that interface A implements B {} seems to be valid, but that shouldn't be valid in TypeScript code.

@DMartens
Copy link
Contributor Author

The original issue originated from my eslint rule failing for this TypeScript compiler test case.
So I thought it is valid TypeScript.

@bradzacher
Copy link
Member

seems to be valid, but that shouldn't be valid in TypeScript code.

TS reuses parsing logic in a few places to deduplicate - for example class declarations and interface declarations are remarkably similar.

Which means that TS can sometimes do weird things. Add to that the no-error "recovery" nature of the parser and you will find that it parses a lot of invalid code successfully and produces an AST.

In this instance here I'd assume this is a legacy thing combined with a shared parser logic thing. The parser allows you to write an interface with implements, and for some reason it also encodes that in the AST.
When our conversion logic was imemented - whoever did it just ensured all valid child props were converted without deciding it it made sense syntactically.

Which leads us into this weird state where we produce an AST for obviously incorrect code.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: visitor-keys Issues related to @typescript-eslint/visitor-keys
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants