Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/construct/partial_mdx_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ pub fn inside(tokenizer: &mut Tokenizer) -> State {
tokenizer.exit(Name::MdxExpressionData);
State::Retry(StateName::MdxExpressionBefore)
} else {
// Don’t count if gnostic.
if tokenizer.current == Some(b'{')
&& tokenizer.parse_state.options.mdx_expression_parse.is_none()
{
// Count braces even when external parser is present.
// Original check skipped nested braces, breaking `{{ x: 1 }}`.
if tokenizer.current == Some(b'{') {
tokenizer.tokenize_state.size += 1;
} else if tokenizer.current == Some(b'}') {
tokenizer.tokenize_state.size -= 1;
Expand Down
24 changes: 24 additions & 0 deletions tests/mdx_expression_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,29 @@ fn mdx_expression_text_gnostic() -> Result<(), message::Message> {
"should keep the correct number of spaces in a blockquote (text)"
);

assert_eq!(
to_html_with_options("a {{}} b", &swc)?,
"<p>a b</p>",
"should support nested empty object literal"
);

assert_eq!(
to_html_with_options("a {{ x: 1 }} b", &swc)?,
"<p>a b</p>",
"should support nested object literal with property"
);

assert_eq!(
to_html_with_options("a {func({ x: 1 })} b", &swc)?,
"<p>a b</p>",
"should support function call with nested object"
);

assert_eq!(
to_html_with_options("a {f({ x: g({ y: 2 }) })} b", &swc)?,
"<p>a b</p>",
"should support double nested function calls"
);

Ok(())
}