-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Unify type assertion nodes #6099
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
Comments
Worth noting that now we have |
|
It's worth noting that the AST is there to represent the syntax, not the semantics of the code. The original issue suggested aligning the nodes based on the semantics (as assertion being the same as an angle bracket assertion), but was suggested to try and make it easier for lint rule authors. From a pure ast perspective - satisfies and as should really be the same node with At this point I think almost everyone has moved away from angle bracket assertions, so it's becoming less relevant to merge things. |
Yeah I don't think this is really necessary anymore. I can't recall anybody external to us asking for it, and it's not completely cut-and-dry which one to go for. I'll just close this issue for now. Someone should yell & make noise if there's a compelling reason to make this change! |
Discussed in #6021
Originally posted by bradzacher May 31, 2020
There are two styles for type-assertions:
as
assertions (x as type
)<type>x
)Currently they produce two different, but almost identical ASTs:
and
I don't think that there's a reason why these should be separate AST nodes. I think that they're separate nodes because they have different code representations, but I don't know if that's something that matters from the POV of the AST. Similar to the discussion that's going on around the ESTree representation of optional chaining - there is a difference between the AST and the CST.
From the perspective of ESLint, having two nodes causes pains when writing lint rules, as authors have to remember to add both nodes to selectors or
if
checks. Often they don't, which means rules don't have proper support for TS syntax.I propose that we unify the two nodes with the following AST:
The text was updated successfully, but these errors were encountered: