From 16cae8abaf2e889b533ed7d3a7b741b4f5d00bd8 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 7 Apr 2025 19:29:53 -0500 Subject: [PATCH] fix key validation logic (#3936) --- packages/rsx/src/template_body.rs | 4 +++- packages/rsx/tests/parsing.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/rsx/src/template_body.rs b/packages/rsx/src/template_body.rs index ca44d5e1f..95379ddc0 100644 --- a/packages/rsx/src/template_body.rs +++ b/packages/rsx/src/template_body.rs @@ -236,11 +236,13 @@ impl TemplateBody { // Assign paths to all nodes in the template body.assign_paths_inner(&nodes); - body.validate_key(); // And then save the roots body.roots = nodes; + // Finally, validate the key + body.validate_key(); + body } diff --git a/packages/rsx/tests/parsing.rs b/packages/rsx/tests/parsing.rs index 6e03ef8f9..aae64d7a3 100644 --- a/packages/rsx/tests/parsing.rs +++ b/packages/rsx/tests/parsing.rs @@ -141,3 +141,29 @@ fn complex_kitchen_sink() { let _cb: CallBody = syn::parse2(item).unwrap(); } + +#[test] +fn key_must_be_formatted() { + let item = quote::quote! { + div { + key: value + } + }; + + let parsed = syn::parse2::(item).unwrap(); + println!("{:?}", parsed.body.diagnostics); + assert!(!parsed.body.diagnostics.is_empty()); +} + +#[test] +fn key_cannot_be_static() { + let item = quote::quote! { + div { + key: "hello world" + } + }; + + let parsed = syn::parse2::(item).unwrap(); + println!("{:?}", parsed.body.diagnostics); + assert!(!parsed.body.diagnostics.is_empty()); +}