-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Recover closing fragment with contents differently #47534
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
Conversation
I guess my ideal scenario would be
It seems like that would pass the assertion in services and be a net improvement on parser errors reported today. But I don't know how difficult that is. |
It seems like at the moment, having a random |
Hmm, I have an idea here; I'll give it a try. |
@andrewbranch I made an attempt to implement the setup you suggested; it does seem to work, but it does seem to break auto-fragment closing in one case because now we think the fragment is closed (as opposed to element); the test will fail in the PR if you want to look. The error's a placeholder for now. |
//@Filename: file.tsx | ||
//// let x = <></Fo/*$*/o>; | ||
|
||
verify.quickInfoAt("$", "let Foo: any") |
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 fails right now as it says "any"; I think this test case was wrong originally given I didn't actually declare Foo
.
I'm sort of worried about this approach because it makes the parser start eating closing tags moreso than before, so if you stick a |
~~~~~~~~~~~~~~~~ | ||
!!! error TS2657: JSX expressions must have one parent element. |
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 error seems to get dropped because we're eagerly eating up tags after <>
(whereas this test assumed that it would stop earlier, and therefore wrote two tests on two different lines).
src/compiler/parser.ts
Outdated
if (tokenIsIdentifierOrKeyword(token())) { | ||
parseErrorAtRange(parseJsxElementName(), Diagnostics.Expected_corresponding_closing_tag_for_JSX_fragment); | ||
} |
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 condition is now impossible due to the change above.
@@ -50,7 +50,7 @@ verify.jsxClosingTag({ | |||
1: undefined, | |||
2: undefined, | |||
3: undefined, | |||
4: { newText: "</>" }, | |||
4: undefined, |
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.
The case looks like:
// @Filename: /4.tsx
////const x = <div>
//// <>/*4*/
//// </div>
////</>;
So, we now see the fragment close below and don't offer up a close. Maybe reasonable, maybe not.
#52818 is comically better than this. |
Fixes #44154
I don't know if I like this. This effectively does what was noted in #44154 (comment), but does lead to some extra errors and a different JS output which feels undesirable.