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

Remove properties that are used by invalid code #4759

Closed
bradzacher opened this issue Mar 29, 2022 · 9 comments · Fixed by #4863
Closed

Remove properties that are used by invalid code #4759

bradzacher opened this issue Mar 29, 2022 · 9 comments · Fixed by #4863
Labels
accepting prs Go ahead, send a pull request that resolves this issue AST PRs and Issues about the AST structure breaking change This change will require a new major version to be released package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Milestone

Comments

@bradzacher
Copy link
Member

bradzacher commented Mar 29, 2022

Currently we have the following AST properties declared:

These all represent bad code that would cause errors if one attempted to build in TS:

public enum Foo {}
// 'public' modifier cannot appear on a module or namespace element.(1044)

abstract namespace Bar {}
// 'abstract' modifier can only appear on a class, method, or property declaration.(1242)

interface Baz implements Bam {}
// Interface declaration cannot have 'implements' clause.(1176)

abstract interface Bam {}
// 'abstract' modifier can only appear on a class, method, or property declaration.

TS parses these fine and emits a semantic error, not a syntactic error.
Our parser currently does not error on syntactically bad code, thus we also don't error on it (#1852).

We should remove these properties from the AST as it is non-sensical to include them - nobody should ever be inspecting the code that is produced on them.

@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree breaking change This change will require a new major version to be released AST PRs and Issues about the AST structure accepting prs Go ahead, send a pull request that resolves this issue labels Mar 29, 2022
@bradzacher bradzacher added this to the 6.0.0 milestone Mar 29, 2022
@Josh-Cena

This comment was marked as resolved.

@DMartens
Copy link
Contributor

I intented to create an PR for this, but each of the properties seem to be intended as they are handled explicitly:

@bradzacher bradzacher changed the title Remove properties that Remove properties that are used by invalid code Mar 29, 2022
@bradzacher
Copy link
Member Author

Yes it's implemented. But that doesn't mean it should be there!

Some of this code was written by non-TS folks back in the day - who worked to just convert the AST 1-for-1 without know what was right or wrong.

We should remove properties and the code that populates them!

@juank1809
Copy link
Contributor

juank1809 commented Apr 13, 2022

I was about to submit a PR to this issue, but I stumbled upon a realization: there are still valid modifiers, more specifically const and declare, to handle.

I think the best approach to this problem is to modify the code in order to restrict and forbid invalid modifiers within these nodes instead of removing it.

@bradzacher
Copy link
Member Author

more specifically const and declare

These are handled via boolean flags.

const?: boolean;
declare?: boolean;

@bradzacher
Copy link
Member Author

Another set of cases to be removed:




Syntactically the TS parser allows the export modifier, but semantically it disallows it.

@bradzacher
Copy link
Member Author

Another case to be removed:

Syntactically the TS parser allows an initialiser (likely due to it reusing parsing logic for class properties), but semantically it is disallowed.

@bradzacher
Copy link
Member Author

Another case to be removed:

typeParameters?: TSTypeParameterDeclaration;

typeParameters is placed on the .value node, not the MethodDefinition

@JoshuaKGoldberg
Copy link
Member

Fixed by #4863 and will be available in v6! 🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2023
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 AST PRs and Issues about the AST structure breaking change This change will require a new major version to be released package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
5 participants