fix(es/react): Don't panic on key without a value (#6945)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6939.
This commit is contained in:
Donny/강동윤 2023-02-15 13:31:02 +09:00 committed by GitHub
parent 4c6775646b
commit 14454c9dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 4 deletions

View File

@ -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;
}

View File

@ -0,0 +1 @@
const test = <div key></div>

View File

@ -0,0 +1 @@
{ "runtime": "automatic" }

View File

@ -0,0 +1,2 @@
import { jsx as _jsx } from "react/jsx-runtime";
const test = /*#__PURE__*/ _jsx("div", {});

View File

@ -0,0 +1,6 @@
x The value of property 'key' should not be empty
,-[input.js:1:1]
1 | const test = <div key></div>
: ^^^
`----