Skip to content

Commit 16cae8a

Browse files
authored
fix key validation logic (#3936)
1 parent 5e9a505 commit 16cae8a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/rsx/src/template_body.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,13 @@ impl TemplateBody {
236236

237237
// Assign paths to all nodes in the template
238238
body.assign_paths_inner(&nodes);
239-
body.validate_key();
240239

241240
// And then save the roots
242241
body.roots = nodes;
243242

243+
// Finally, validate the key
244+
body.validate_key();
245+
244246
body
245247
}
246248

packages/rsx/tests/parsing.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,29 @@ fn complex_kitchen_sink() {
141141

142142
let _cb: CallBody = syn::parse2(item).unwrap();
143143
}
144+
145+
#[test]
146+
fn key_must_be_formatted() {
147+
let item = quote::quote! {
148+
div {
149+
key: value
150+
}
151+
};
152+
153+
let parsed = syn::parse2::<CallBody>(item).unwrap();
154+
println!("{:?}", parsed.body.diagnostics);
155+
assert!(!parsed.body.diagnostics.is_empty());
156+
}
157+
158+
#[test]
159+
fn key_cannot_be_static() {
160+
let item = quote::quote! {
161+
div {
162+
key: "hello world"
163+
}
164+
};
165+
166+
let parsed = syn::parse2::<CallBody>(item).unwrap();
167+
println!("{:?}", parsed.body.diagnostics);
168+
assert!(!parsed.body.diagnostics.is_empty());
169+
}

0 commit comments

Comments
 (0)