Skip to content
Closed
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
6 changes: 4 additions & 2 deletions crates/oxc_transformer/src/jsx/jsx_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,10 @@ impl<'a> JsxImpl<'a, '_> {
// SAFETY: `ast.copy` is unsound! We need to fix.
unsafe { ctx.ast.copy(e.to_expression()) }
}
JSXExpression::EmptyExpression(e) => {
ctx.ast.expression_boolean_literal(e.span, true)
JSXExpression::EmptyExpression(_) => {
// `<div attr={}></div>`
// ^^ Invalid empty expression here
unreachable!()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not make this unreachable in situations where the semantic checker is not run or missed the check, do not emit anything instead.

Copy link
Member Author

@Dunqing Dunqing Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. To achieve "do not emit anything" here we must return a None, which will cause more changes, I will do this later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From reading the JSX spec, it doesn't look like an EmptyExpression is ever valid in this position. If I've understood that right, could we make JSXExpressionContainer just contain an Expression, rather than a JSXExpression?

I assume the reason is recoverability. To achieve that, could we instead raise an error in the parser, and skip adding the JSXAttribute, so that parsing can continue?

It's going to cause a problem serializing to ESTree, because what does it serialize to? The "EmptyExpression" option doesn't exist.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
},
None => ctx.ast.expression_boolean_literal(SPAN, true),
Expand Down