Skip to content

Commit 165f59d

Browse files

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

crates/oxc_parser/src/diagnostics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,9 @@ pub fn identifier_expected_jsx_no_hyphen(span: Span) -> OxcDiagnostic {
11311131
.with_label(span)
11321132
.with_help("Remove the hyphen from the identifier")
11331133
}
1134+
1135+
#[cold]
1136+
pub fn jsx_attribute_value_empty_expression(span: Span) -> OxcDiagnostic {
1137+
ts_error("17000", "JSX attributes must only be assigned a non-empty 'expression'.")
1138+
.with_label(span)
1139+
}

crates/oxc_parser/src/jsx/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ impl<'a> ParserImpl<'a> {
289289
self.expect(Kind::RCurly);
290290
}
291291
let span = self.end_span(span_start);
292+
293+
// Empty expression is not allowed in JSX attribute value
294+
// e.g. `<C attr={} />`
295+
if !in_jsx_child {
296+
self.error(diagnostics::jsx_attribute_value_empty_expression(span));
297+
}
298+
292299
// Handle comment between curly braces (ex. `{/* comment */}`)
293300
// ^^^^^^^^^^^^^ span
294301
let expr = self.ast.jsx_empty_expression(Span::new(span.start + 1, span.end - 1));

crates/oxc_semantic/src/checker/typescript.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,6 @@ pub fn check_for_statement_left(left: &ForStatementLeft, is_for_in: bool, ctx: &
424424
}
425425
}
426426

427-
fn invalid_jsx_attribute_value(span: Span) -> OxcDiagnostic {
428-
ts_error("17000", "JSX attributes must only be assigned a non-empty 'expression'.")
429-
.with_label(span)
430-
}
431-
432427
fn jsx_expressions_may_not_use_the_comma_operator(span: Span) -> OxcDiagnostic {
433428
ts_error("18007", "JSX expressions may not use the comma operator")
434429
.with_help("Did you mean to write an array?")
@@ -439,12 +434,6 @@ pub fn check_jsx_expression_container(
439434
container: &JSXExpressionContainer,
440435
ctx: &SemanticBuilder<'_>,
441436
) {
442-
if matches!(container.expression, JSXExpression::EmptyExpression(_))
443-
&& matches!(ctx.nodes.parent_kind(ctx.current_node_id), AstKind::JSXAttribute(_))
444-
{
445-
ctx.error(invalid_jsx_attribute_value(container.span()));
446-
}
447-
448437
if matches!(container.expression, JSXExpression::SequenceExpression(_)) {
449438
ctx.error(jsx_expressions_may_not_use_the_comma_operator(container.expression.span()));
450439
}

0 commit comments

Comments
 (0)