7
7
* @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
8
8
* @typedef {import('mdast-util-to-markdown').Handle } ToMarkdownHandle
9
9
* @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
11
12
* @typedef {import('estree-jsx').Program } Program
12
13
* @typedef {import('./complex-types').MdxJsxAttributeValueExpression } MdxJsxAttributeValueExpression
13
14
* @typedef {import('./complex-types').MdxJsxAttribute } MdxJsxAttribute
@@ -312,19 +313,19 @@ function exitMdxJsxTag(token) {
312
313
children : [ ]
313
314
} ,
314
315
token ,
315
- onError
316
+ onErrorRightIsTag
316
317
)
317
318
}
318
319
319
320
if ( tag . selfClosing || tag . close ) {
320
- this . exit ( token )
321
+ this . exit ( token , onErrorLeftIsTag )
321
322
} else {
322
323
stack . push ( tag )
323
324
}
324
325
}
325
326
326
- /** @type {OnError } */
327
- function onError ( closing , open ) {
327
+ /** @type {OnEnterError } */
328
+ function onErrorRightIsTag ( closing , open ) {
328
329
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
329
330
const place = closing ? ' before the end of `' + closing . type + '`' : ''
330
331
const position = closing
@@ -343,6 +344,26 @@ function onError(closing, open) {
343
344
)
344
345
}
345
346
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
+
346
367
/**
347
368
* Serialize a tag, excluding attributes.
348
369
* `self-closing` is not supported, because we don’t need it yet.
0 commit comments