Skip to content

Commit

Permalink
Fix error message on unclosed JSX tag after closed tag
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 18, 2024
1 parent 3f65ea5 commit 33379fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/to_mdast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,12 +1743,13 @@ fn on_mismatch_error(
right: &Event,
) -> Result<(), String> {
if right.name == Name::MdxJsxFlowTag || right.name == Name::MdxJsxTextTag {
let stack = &context.jsx_tag_stack;
let tag = stack.last().unwrap();
let point = if let Some(left) = left {
&left.point
} else {
&context.events[context.events.len() - 1].point
};
let tag = context.jsx_tag.as_ref().unwrap();

return Err(format!(
"{}:{}: Expected a closing tag for `{}` ({}:{}){} (mdx-jsx:end-tag-mismatch)",
Expand Down
6 changes: 6 additions & 0 deletions tests/mdx_jsx_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ fn mdx_jsx_text_core() -> Result<(), String> {
"should crash when building the ast on mismatched interleaving (4)"
);

assert_eq!(
to_mdast("<a><b></b>", &mdx.parse).err().unwrap(),
"1:11: Expected a closing tag for `<a>` (1:1) (mdx-jsx:end-tag-mismatch)",
"should crash on unclosed jsx after closed jsx"
);

Ok(())
}

Expand Down

0 comments on commit 33379fc

Please sign in to comment.