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

JSX Implicit fragment not being created in some JSX situations #1691

Open
nicholaides opened this issue Jan 26, 2025 · 5 comments
Open

JSX Implicit fragment not being created in some JSX situations #1691

nicholaides opened this issue Jan 26, 2025 · 5 comments

Comments

@nicholaides
Copy link

Input:

<node>
> if cond
  <sibling>

Actual Output:

<node />
> (cond?
  <sibling />:void 0)

Expected Output:

<>
  <node />
  { (cond?
    <sibling />:void 0)}
</>

Workaround: Wrap it in a fragment manually

<>
  <node>
  > if cond
    <sibling>

This doesn't just happen in a top-level context, either. This will also trigger the same behavior:

<parent>
  > if parentCond
    <node>
    > if cond
      <sibling>
@nicholaides
Copy link
Author

Also, I just noticed that this fails with a parse error:

<node>
>if cond
  <sibling>

Seems likely to be related to this bug.

@edemaine
Copy link
Collaborator

This looks like expected behavior to me. JSX children are supposed to be strictly indented, and none of your examples are indented (the > is at the same level as the JSX before it).

Are you proposing that > foo be treated as indented farther than the >? That would seem a bit weird to me...

@edemaine
Copy link
Collaborator

edemaine commented Jan 26, 2025

Ohh, now I see - you wanted the second element to be a sibling. Right, we should probably create an implicit fragment in that case, though it's a bit ambiguous. Comparing a JSX node with > seems unlikely to be that useful, though it could be, depending on the JSX implementation. But probably reasonable to require that the tag be wrapped in parentheses for it to be compared.

Related, these also don't get an automatic fragment, but it's less clear whether they should:

<div>
some text
<div>
{value}

Given the last in particular, I'm a little unclear whether > should work...

@nicholaides
Copy link
Author

Comparing a JSX node with > seems unlikely to be that useful

Yeah, in my opinion, "code children" syntax should take precedence over comparing JSX nodes with > if implicit fragments is going to be a feature.

@nicholaides
Copy link
Author

nicholaides commented Jan 26, 2025

In those examples (<div>;some text and <div>;{value}), not wrapping in an implicit fragment only makes sense if <div /> has a side effect.

It seems like Civet's "code children" feature (if not all of it's JSX support) assumes that JSX tags don't have side effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants