Skip to content

Commit cdfd0e5

Browse files
committed
Fix error message on unclosed tag after closed tag
Closes GH-12.
1 parent bf60d93 commit cdfd0e5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ export function mdxJsxFromMarkdown() {
451451
* @type {OnEnterError}
452452
*/
453453
function onErrorRightIsTag(closing, open) {
454-
const tag = this.data.mdxJsxTag
454+
const stack = this.data.mdxJsxTagStack
455+
assert(stack, 'expected `mdxJsxTagStack`')
456+
const tag = stack[stack.length - 1]
455457
assert(tag, 'expected `mdxJsxTag`')
456458
const place = closing ? ' before the end of `' + closing.type + '`' : ''
457459
const position = closing

test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ test('mdxJsxFromMarkdown', async function (t) {
246246
}
247247
)
248248

249+
await t.test(
250+
'should crash on unclosed jsx after closed jsx',
251+
async function () {
252+
assert.throws(function () {
253+
fromMarkdown('<a><b></b>', {
254+
extensions: [mdxJsx()],
255+
mdastExtensions: [mdxJsxFromMarkdown()]
256+
})
257+
}, /Expected a closing tag for `<a>` \(1:1-1:4\)/)
258+
}
259+
)
260+
249261
await t.test(
250262
'should support an attribute expression in text jsx (agnostic)',
251263
async function () {

0 commit comments

Comments
 (0)