fix(45802): keep children of mismatched jsx element (#45839)

* fix(45802): keep children of mismatched jsx element

* Apply suggestions from code review

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Hiroshi Ogawa
2021-09-20 23:19:55 +09:00
committed by GitHub
parent 78472ec14c
commit 5ef043987a
5 changed files with 47 additions and 19 deletions

View File

@@ -5042,12 +5042,12 @@ namespace ts {
&& !tagNamesAreEquivalent(lastChild.openingElement.tagName, lastChild.closingElement.tagName)
&& tagNamesAreEquivalent(opening.tagName, lastChild.closingElement.tagName)) {
// when an unclosed JsxOpeningElement incorrectly parses its parent's JsxClosingElement,
// restructure (<div>(...<span></div>)) --> (<div>(...<span></span>)</div>)
// restructure (<div>(...<span>...</div>)) --> (<div>(...<span>...</>)</div>)
// (no need to error; the parent will error)
const end = lastChild.openingElement.end; // newly-created children and closing are both zero-width end/end
const end = lastChild.children.end;
const newLast = finishNode(factory.createJsxElement(
lastChild.openingElement,
createNodeArray([], end, end),
lastChild.children,
finishNode(factory.createJsxClosingElement(finishNode(factory.createIdentifier(""), end, end)), end, end)),
lastChild.openingElement.pos,
end);