rjsx-mode
rjsx-mode copied to clipboard
More intelligently try to match tags
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.
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>
I would also like a functionality to auto closer missing tag, I believe this is related
Yeah parsing when there are missing tags is very challenging