Skip to content

Commit 1adc171

Browse files
authored
fix: self closing tag should not be combined - close #158 (#196)
* fix: self closing tag should not be combined - close #158 * fix: open tag index could be -1
1 parent a91b9df commit 1adc171

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/eslint-mdx/src/traverse.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ export class Traverse {
7676
}
7777

7878
if (!offset) {
79-
acc.push(this.combineLeftJsxNodes(jsxNodes))
79+
// fix #158
80+
const firstOpenTagIndex = jsxNodes.findIndex(node =>
81+
isOpenTag(node.value as string),
82+
)
83+
if (firstOpenTagIndex === -1) {
84+
acc.push(...jsxNodes)
85+
} else {
86+
acc.push(...jsxNodes.slice(0, firstOpenTagIndex))
87+
acc.push(
88+
this.combineLeftJsxNodes(jsxNodes.slice(firstOpenTagIndex)),
89+
)
90+
}
8091
jsxNodes.length = 0
8192
}
8293
}

test/no-unescaped-entities.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ ruleTester.run('no-unescaped-entities', noUnescapedEntities, {
1919
parserOptions,
2020
filename,
2121
},
22+
{
23+
// #158
24+
code: `<YouTube youTubeId="dQw4w9WgXcQ" />
25+
<Aside>I chose this video to test my theme. I did this to myself</Aside>
26+
`,
27+
parser,
28+
parserOptions,
29+
filename,
30+
},
2231
],
2332
invalid: [
2433
{

0 commit comments

Comments
 (0)