diff --git a/src/lexers/jsx-lexer.js b/src/lexers/jsx-lexer.js
index 147a8bbe..ffdf91f1 100644
--- a/src/lexers/jsx-lexer.js
+++ b/src/lexers/jsx-lexer.js
@@ -165,10 +165,12 @@ export default class JsxLexer extends JavascriptLexer {
const useTagName =
child.isBasic &&
this.transSupportBasicHtmlNodes &&
- this.transKeepBasicHtmlNodesFor.includes(child.name)
+ this.transKeepBasicHtmlNodesFor.includes(child.name) &&
+ child.children.length <= 1 &&
+ child.children.every((v) => v.type === 'text')
const elementName = useTagName ? child.name : index
const childrenString = elemsToString(child.children)
- return childrenString || !(useTagName && child.selfClosing)
+ return childrenString || !useTagName
? `<${elementName}>${childrenString}${elementName}>`
: `<${elementName}/>`
default:
@@ -202,7 +204,6 @@ export default class JsxLexer extends JavascriptLexer {
children: this.parseChildren(child.children, sourceText),
name,
isBasic,
- selfClosing: child.kind === ts.SyntaxKind.JsxSelfClosingElement,
}
} else if (child.kind === ts.SyntaxKind.JsxExpression) {
// strip empty expressions
diff --git a/test/lexers/jsx-lexer.test.js b/test/lexers/jsx-lexer.test.js
index 8519684f..8059c464 100644
--- a/test/lexers/jsx-lexer.test.js
+++ b/test/lexers/jsx-lexer.test.js
@@ -370,12 +370,19 @@ describe('JsxLexer', () => {
done()
})
- it('keeps empty tag untouched when transSupportBasicHtmlNodes is true', (done) => {
+ it('converts empty tags to self-closing tags when transSupportBasicHtmlNodes is true', (done) => {
const Lexer = new JsxLexer({ transSupportBasicHtmlNodes: true })
const content = ' ab c
d
ab
<1>c