syntax-tree/mdast-util-mdx-jsx

Incorrect error message on unclosed element after properly closed elements

theRealProHacker opened this issue · 1 comments

Initial checklist

Affected packages and versions

latest version

Link to runnable example

No response

Steps to reproduce

This code

<A>
<B></B>

produces this error

1:1: Expected a closing tag for `</B>` (1:1-1:4)

Which seems to come from here:

if (tag.close) {
stack.pop()
} else {
this.enter(
{
type:
token.type === 'mdxJsxTextTag'
? 'mdxJsxTextElement'
: 'mdxJsxFlowElement',
name: tag.name || null,
attributes: tag.attributes,
children: []
},
token,
onErrorRightIsTag
)
}
if (tag.selfClosing || tag.close) {
this.exit(token, onErrorLeftIsTag)
} else {
stack.push(tag)
}
}
/**
* @this {CompileContext}
* @type {OnEnterError}
*/
function onErrorRightIsTag(closing, open) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
const place = closing ? ' before the end of `' + closing.type + '`' : ''
const position = closing
? {start: closing.start, end: closing.end}
: undefined
throw new VFileMessage(
'Expected a closing tag for `' +
serializeAbbreviatedTag(tag) +
'` (' +
stringifyPosition({start: open.start, end: open.end}) +
')' +
place,
position,
'mdast-util-mdx-jsx:end-tag-mismatch'
)
}

Expected behavior

I would have expected an error that asks me to close the <A> tag/element.

Actual behavior

The error asks me to close the </B> tag, which is itself a closing tag

Affected runtime and version

node@20.0

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

No response