-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Parser error type identifier #4878
Conversation
node.parameterName = <Identifier>typeName; | ||
node.type = parseType(); | ||
return finishNode(node); | ||
let pnode = <TypePredicateNode>createNode(SyntaxKind.TypePredicate, typeName.pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
predicateNode
@jbondc I don't think this is the correct approach for the original bug. As @CyrusNajmabadi pointed out, I think we'd be better off parsing the type and erroring afterwards. Additionally, I think we should be reporting the specific errors suggested. |
Used this technique to avoid |
Going to reference #3003 to this, having the ability to improve error messages seems valuable too. |
@DanielRosenwasser is performance the primary concern? Don't mind revisiting the approach. |
Would be nice to have a more generalized solution to parser error recovery, #5173, #4260 Do think the approach I took was a step in the right direction: |
It seems like there should be a much easier fix here. Namely, after parsing out the I've very hesitant about having any sort of parser flags. Esp. around errors. |
@CyrusNajmabadi I'll try something else. Is there any reason a missing node doesn't have a flag? That seems useful. It could be a single check here:
|
Yes. It was very intentional. Such a flag would be redundant with existing information already on the node. Redundant information in a tree is very concerning to me as it now means you have to ensure that they must stay in sync 100% of the time. If you screw that up then you get inconsistencies that make everything difficult. Such a concern is not hypothetical either. Both the original TS parser and the Roslyn parsers suffered from this problem. They had redundant forms of information that weren't always kept in sync properly. And people used different mechanisms to grok out that information later in the pipeline, leading to all sorts of subtle and annoying bugs. I'd far prefer to have one uniform way to encode if a node is missing, and one way to check for it (through a function which everyone calls). |
Add a 'NodeFlags.Missing' to easily check for missing node.
Better error on bad type predicate.
ba90e05
to
1868d43
Compare
@CyrusNajmabadi Refactored using a Let me know what you think |
!!! error TS1005: '}' expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression.
@jbondc I'm not a fan of this approach. As mentioned earlier, I don't believe the flag I appropriate. It's now confusing to users if they should check that flag or use the function to test if a node is missing. Second, this adds a lot of complexity into the parser. A much simpler solution would be to just make parsing more lenient, and then check for invalid precedence later on during our normal syntactic checks. |
As @CyrusNajmabadi explained, this is the correct approach. there has not been much activity here either, so closing. please resubmit with the outlined approach. |
k bye |
This improves parsing an invalid type identifier #4067
Was tricky, added a
ParserContextFlags.NoError
flag to disable errors on parsing, then check for missing node(s) to improve the error(s).