From 4711b1f0720eb54e458ca5a16cb655013693b628 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 9 Sep 2022 15:42:07 +0200 Subject: Add support for mdx attribute (value) expressions --- src/construct/partial_mdx_expression.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/construct/partial_mdx_expression.rs') diff --git a/src/construct/partial_mdx_expression.rs b/src/construct/partial_mdx_expression.rs index a949347..aeea52e 100644 --- a/src/construct/partial_mdx_expression.rs +++ b/src/construct/partial_mdx_expression.rs @@ -36,13 +36,22 @@ pub fn before(tokenizer: &mut Tokenizer) -> State { State::Next(StateName::MdxExpressionEolAfter) }, Some(b'}') if tokenizer.tokenize_state.size == 0 => { - tokenizer.enter(Name::MdxExpressionMarker); - tokenizer.consume(); - tokenizer.exit(Name::MdxExpressionMarker); - tokenizer.exit(tokenizer.tokenize_state.token_1.clone()); - State::Ok + if tokenizer.tokenize_state.token_1 == Name::MdxJsxTagAttributeValueExpression && !tokenizer.tokenize_state.seen { + State::Error(format!( + "{}:{}: Unexpected empty in expression, expected a value between braces", + tokenizer.point.line, tokenizer.point.column + )) + } else { + tokenizer.tokenize_state.seen = false; + tokenizer.enter(Name::MdxExpressionMarker); + tokenizer.consume(); + tokenizer.exit(Name::MdxExpressionMarker); + tokenizer.exit(tokenizer.tokenize_state.token_1.clone()); + State::Ok + } }, Some(_) => { + tokenizer.tokenize_state.seen = true; tokenizer.enter(Name::MdxExpressionData); State::Retry(StateName::MdxExpressionInside) } @@ -56,9 +65,11 @@ pub fn inside(tokenizer: &mut Tokenizer) -> State { tokenizer.exit(Name::MdxExpressionData); State::Retry(StateName::MdxExpressionBefore) } else { - // To do: only count if agnostic. + // To do: don’t count if gnostic. if tokenizer.current == Some(b'{') { tokenizer.tokenize_state.size += 1; + } else if tokenizer.current == Some(b'}') { + tokenizer.tokenize_state.size -= 1; } tokenizer.consume(); @@ -67,8 +78,11 @@ pub fn inside(tokenizer: &mut Tokenizer) -> State { } pub fn eol_after(tokenizer: &mut Tokenizer) -> State { - // Lazy continuation in a flow expression is a syntax error. - if tokenizer.tokenize_state.token_1 == Name::MdxFlowExpression && tokenizer.lazy { + // Lazy continuation in a flow expression (or in a flow tag) is a syntax error. + if (tokenizer.tokenize_state.token_1 == Name::MdxFlowExpression + || tokenizer.tokenize_state.token_2 == Name::MdxJsxFlowTag) + && tokenizer.lazy + { State::Error(format!( "{}:{}: Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc", tokenizer.point.line, tokenizer.point.column -- cgit