-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Services debug failure in presence of unclosed JSX fragment #44154
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
Moving this off the backlog - some version of this hits over 20k machines a day. |
I think conceptually, what's happening "makes sense". As a recovery tactic for JSX fragments (
we always parse out a tag name, but we don't store it in the tree. Then later, we try to populate each child node with its trivia. That said, I don't know what the right fix is. Storing the name in the tree? |
I'm currently investigating this bug by accident, because the fuzzer detected this crash and it's getting in the way of me reproing another crash. |
Yeah, I was working on this one too. Not sure what the "good" fix would be here. Having followed the code, I don't think the recovery is all that perfect. Basically all it does is eat the next token, see if that was an identifier, then issue an error, then try and close with the I almost wonder what this debug assertion gets us. |
Just to clarify this, it seems like the services code is trying to be clever to detect parser bugs, but effectively ends up re-encoding parser rules that may or may not be right without context (which this part of the code does not have). In this case, I don't think that the assertion is really correct; it's only failing because it happens to be an identifier, but what if I stuck in |
@gabritto says @andrewbranch says (phew) that there are some actual reasons to have it, so I'll see if I can get the parser to do better here instead of ragging on our debug asserts any more. 😄 |
Let’s just say you’re not the first to propose removing the assertion in the first few months of being on the team 😅 |
After speaking to @CyrusNajmabadi outside GitHub about this, I am kind of convinced that the assertion is not really guaranteeing anything useful (though it would be worth looking into when the assertion was added). Ultimately, "skipped" tokens are something our trees should be able to hold onto. There are only 2 cases I think this assertion was meant to catch:
I think that's exactly the concern in the latter point above.
I think all of us have come to the same conclusion. I think the fix is to remove the assertion. |
Though now I've re-read - if there are good reasons to keep it, let's discuss them here. |
I sort of agree in theory, but I suspect removing the assertion would just move the crash to a dozen different places where LS operations naturally assume that an identifier is going to be predictably parented into the parse tree. It’s usually not hard to change the parser recovery so it doesn’t drop identifiers. |
My point about I'm interested in how this would be fixed to not drop the node though; it seems like the only thing that can be done is to actually stick a tag name into this fragment, which seems odd. The opening fragment just doesn't have anything fancy; it just only lets you type |
Recovery of this sort is usually done by making up tokens that don’t exist instead of dropping tokens that do exist. I’m not sure what the best route for this one would be without looking at the parser code, but my first instinct would be |
Thanks, that's helpful. |
so we're not getting rid of the assertion then? |
Seems like no; I'm going to see if I can do what Andrew suggested by inventing things to recover instead and we'll see, I guess. |
Maybe related to #38317.
In a
.tsx
file:Hover over
Foo
, or click onFoo
to get document highlightsThe text was updated successfully, but these errors were encountered: