windwp / nvim-ts-autotag

Use treesitter to auto close and auto rename html tag
MIT License
1.63k stars 87 forks source link

Not working with react fragments (empty tags) #70

Closed pedro757 closed 1 year ago

pedro757 commented 2 years ago

In react we use fragments, which is basically just an empty tag like this:

function HolaWindwp() {
  return (
    <>
    // Children
    </>
  )
}

If i try to chage that empty tag this plugin does nothing.

<div>

</> // it doesn't autotag here

It works well with non-empty tags.

AlanWarren commented 1 year ago

Came to post something similar. When changing <> into <React.Fragment> nvim-ts-autotag added a closing </React.Fragment>, but it was in the wrong place in the markup, and it also replaced a tag that it shouldn't have.

It's hard to give a specific example, as it happened to me with a very deeply nested code, but here is a contrived example that is at least similar.

<React.Fragemtn>
  <Card>
    <CardBody>
    {status === 'CLOSED' ? (
      <summary>
      {
        summary.filter((s) => s.month_end === date)
          .map((h, i) => {
            if (i === 0) {
              return (
                 <>   //  <----  change this to React.Fragment
                  <div>{h.modified_at} {translateStatus(h.status)}</div>
                  <div>View status history</div>
                 </>
              );
            }
          });
      }
     </summary> 
    ) : (
      <summary>
      {
       // more stuff
      }
     </summary> 
    )}
    </CardBody>
  </Card> // <---- This tag was transformed into a React.Fragment closing tag 
</React.Fragemtn>
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

kutsan commented 1 year ago

I hate stale bot. This needs to re-opened if it's solvable.