Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: treat jsx expr tag names as components #258

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
25 changes: 25 additions & 0 deletions src/transpiling/jsx_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ impl JsxPrecompile {
///
/// Case: <div {...props} />
/// Case: <Foo bar="1" />
/// Case: <Foo.Bar bar="1" />
fn serialize_jsx_to_call_expr(&mut self, el: &JSXElement) -> CallExpr {
let mut is_component = false;
let name_expr = match &el.opening.name {
Expand All @@ -792,6 +793,9 @@ impl JsxPrecompile {
}
// Case: <ctx.Provider />
JSXElementName::JSXMemberExpr(jsx_member_expr) => {
// Expressions are always treated as component since we can't
// reliably detect if the variable holds a component or a string.
is_component = true;
Expr::Member(jsx_member_expr_to_normal(jsx_member_expr))
}
JSXElementName::JSXNamespacedName(namespace_name) => {
Expand Down Expand Up @@ -2486,6 +2490,27 @@ const a = _jsx(a.b.c.d, {
);
}

#[test]
fn component_prop_casing_test() {
test_transform(
JsxPrecompile::default(),
r#"const a = <Foo someCasing={2} />;"#,
r#"import { jsx as _jsx } from "react/jsx-runtime";
const a = _jsx(Foo, {
someCasing: 2
});"#,
);

test_transform(
JsxPrecompile::default(),
r#"const a = <MyIsland.Foo someCasing={2} />;"#,
r#"import { jsx as _jsx } from "react/jsx-runtime";
const a = _jsx(MyIsland.Foo, {
someCasing: 2
});"#,
);
}

#[test]
fn import_source_option_test() {
test_transform(
Expand Down