Skip to content

Conversation

@rlch
Copy link

@rlch rlch commented Nov 12, 2025

Remove parser check that prevented brace counting when external parser is configured. The original logic skipped counting opening braces in gnostic mode, causing expressions like {{ x: 1 }} to exit prematurely at the first closing brace.

Tokenizer must count all braces to find expression boundaries before the external parser validates syntax.

Fixes:

  • Nested object literals: {{ x: 1 }}
  • Nested function calls: func({ x: g({ y: 2 }) })
  • JSX attribute expressions with nested objects

Tests added for nested object literal scenarios.

Remove parser check that prevented brace counting when external parser
is configured. The original logic skipped counting opening braces in
gnostic mode, causing expressions like `{{ x: 1 }}` to exit prematurely
at the first closing brace.

Tokenizer must count all braces to find expression boundaries before
the external parser validates syntax.

Fixes:
- Nested object literals: `{{ x: 1 }}`
- Nested function calls: `func({ x: g({ y: 2 }) })`
- JSX attribute expressions with nested objects

Tests added for nested object literal scenarios.
@wooorm
Copy link
Owner

wooorm commented Nov 12, 2025

The idea is that if you have mdx_expression_parse, then you want something different than counting, because it doesn’t work, and instead accept/crash from mdx_expression_parse based on what language you expect.
Otherwise, why is mdx_expression_parse there?

So, why is mdx_expression_parse there? Why don’t you use the existing methods, from there, to signal back whether things are as expected or not?

@wooorm
Copy link
Owner

wooorm commented Nov 12, 2025

It also looks like you want JS in there, which is exactly what is supported here? Why not use that?

pub fn parse_expression(value: &str, kind: &MdxExpressionKind) -> MdxSignal {
let result = parse_expression_core(value, kind);
match result {
Err((span, message)) => swc_error_to_signal(span, &message, value.len()),
Ok(_) => MdxSignal::Ok,
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants