windwp / nvim-ts-autotag

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

Unexpected behavior when modifing empty JSX tag #14

Closed wirekang closed 3 years ago

wirekang commented 3 years ago

Problem 1: No reaction when empty tag is root element

Before

function test() {
  return (
    <> 
      <Comp1>
        <Comp2></Comp2>
      </Comp1>
    </>
  );
}

After

function test() {
  return (
    <Wrapper> // <-- Modified
      <Comp1>
        <Comp2></Comp2>
      </Comp1>
    </> // <-- Not changed
  );
}

Problem 2: Changes wrong tag when empty tag is not root element

Before

function text() {
  return (
    <Wrapper>
      <>
        <Comp1></Comp1>
        <Comp2></Comp2>
        <Comp3></Comp3>
      </>
    </Wrapper>
  );
}

After

function text() {
  return (
    <Wrapper>
      <Inner> // <-- Modified
        <Comp1></Comp1>
        <Comp2></Comp2>
        <Comp3></Comp3>
      </> // <-- Excepted tag
    </Inner> // <-- ??
  );
}

I love this plugin. This plugin is awesome. I hope this problem will be fixed soon.

windwp commented 3 years ago

hi i just update it to fix that issue above It still has an incorrect name when you change from a name tag to empty tag but I can't handle it. treesitter determine 2 error node and I don't know how to deal with it so you need to change it by hand.