rjsx-mode icon indicating copy to clipboard operation
rjsx-mode copied to clipboard

More intelligently try to match tags

Open felipeochoa opened this issue 7 years ago • 3 comments

When a child JSX tag is missing a closing tag, the current code uses its parent tag as a mismatched tag, so its parent ends up missing a tag and the rest of the buffer is screwed. By deferring matching of opening and closing tags to rjsx-parse-xml we could be smarter about this matching process.

image

felipeochoa avatar Oct 24 '16 07:10 felipeochoa

Thinking through this more, this would require parsing the body of the top-level tag in big chunks without trying to assign children to parents. After every tag-closer, we would run some matching heuristic and decide whether we were done parsing XML, but that's a difficult question. Only then would we be able to walk the tree and assign children to parents. An example of how this would get confusing:

<div className="top">
  <section className="middle">
    <div className="bottom">{/* missing closing tag */}
    Middle-text
  </section>
</div>

In order to correctly attach "Middle-text" to the section, we'd have to first hit the </section> tag, realize that .bottom is unmatched, and then add all the other children to .middle.

How do we deal with situations like:

<div>
  <div>
    <div>{/* missing closing tag */}
  </div>
</div>

felipeochoa avatar Oct 26 '16 11:10 felipeochoa

I would also like a functionality to auto closer missing tag, I believe this is related

larebsyed avatar Oct 22 '18 04:10 larebsyed

Yeah parsing when there are missing tags is very challenging

felipeochoa avatar Oct 22 '18 16:10 felipeochoa