diff --git a/crates/swc_ecma_transforms_react/src/jsx/mod.rs b/crates/swc_ecma_transforms_react/src/jsx/mod.rs index 309afb8692c9..f72aa4f0a646 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/mod.rs @@ -533,10 +533,18 @@ where .value .and_then(jsx_attr_value_to_expr) .map(|expr| expr.as_arg()); - assert_ne!( - key, None, - "value of property 'key' should not be empty" - ); + + if key.is_none() { + HANDLER.with(|handler| { + handler + .struct_span_err( + i.span, + "The value of property 'key' should not \ + be empty", + ) + .emit(); + }); + } continue; } diff --git a/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/input.js b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/input.js new file mode 100644 index 000000000000..f7c873f3d936 --- /dev/null +++ b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/input.js @@ -0,0 +1 @@ +const test =
\ No newline at end of file diff --git a/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/options.json b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/options.json new file mode 100644 index 000000000000..8c29c48c6f58 --- /dev/null +++ b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/options.json @@ -0,0 +1 @@ +{ "runtime": "automatic" } diff --git a/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/output.mjs b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/output.mjs new file mode 100644 index 000000000000..d96adbf55b10 --- /dev/null +++ b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/output.mjs @@ -0,0 +1,2 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +const test = /*#__PURE__*/ _jsx("div", {}); diff --git a/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/output.stderr b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/output.stderr new file mode 100644 index 000000000000..541b257a8376 --- /dev/null +++ b/crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-6939/output.stderr @@ -0,0 +1,6 @@ + + x The value of property 'key' should not be empty + ,-[input.js:1:1] + 1 | const test =
+ : ^^^ + `----