77 * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
88 * @typedef {import('mdast-util-to-markdown').Handle } ToMarkdownHandle
99 * @typedef {import('mdast-util-to-markdown').Map } ToMarkdownMap
10- * @typedef {import('mdast-util-from-markdown').OnError } OnError
10+ * @typedef {import('mdast-util-from-markdown').OnEnterError } OnEnterError
11+ * @typedef {import('mdast-util-from-markdown').OnExitError } OnExitError
1112 * @typedef {import('estree-jsx').Program } Program
1213 * @typedef {import('./complex-types').MdxJsxAttributeValueExpression } MdxJsxAttributeValueExpression
1314 * @typedef {import('./complex-types').MdxJsxAttribute } MdxJsxAttribute
@@ -312,19 +313,19 @@ function exitMdxJsxTag(token) {
312313 children : [ ]
313314 } ,
314315 token ,
315- onError
316+ onErrorRightIsTag
316317 )
317318 }
318319
319320 if ( tag . selfClosing || tag . close ) {
320- this . exit ( token )
321+ this . exit ( token , onErrorLeftIsTag )
321322 } else {
322323 stack . push ( tag )
323324 }
324325}
325326
326- /** @type {OnError } */
327- function onError ( closing , open ) {
327+ /** @type {OnEnterError } */
328+ function onErrorRightIsTag ( closing , open ) {
328329 const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
329330 const place = closing ? ' before the end of `' + closing . type + '`' : ''
330331 const position = closing
@@ -343,6 +344,26 @@ function onError(closing, open) {
343344 )
344345}
345346
347+ /** @type {OnExitError } */
348+ function onErrorLeftIsTag ( a , b ) {
349+ const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
350+ throw new VFileMessage (
351+ 'Expected the closing tag `' +
352+ serializeAbbreviatedTag ( tag ) +
353+ '` either after the end of `' +
354+ b . type +
355+ '` (' +
356+ stringifyPosition ( b . end ) +
357+ ') or another opening tag after the start of `' +
358+ b . type +
359+ '` (' +
360+ stringifyPosition ( b . start ) +
361+ ')' ,
362+ { start : a . start , end : a . end } ,
363+ 'mdast-util-mdx-jsx:end-tag-mismatch'
364+ )
365+ }
366+
346367/**
347368 * Serialize a tag, excluding attributes.
348369 * `self-closing` is not supported, because we don’t need it yet.
0 commit comments