From 0603f54a2794912577e28f2fa62f20c0b473baa4 Mon Sep 17 00:00:00 2001 From: Abdul Wahab Date: Mon, 14 Sep 2026 16:09:40 +0500 Subject: [PATCH] bake: the universal selector adds nothing to the anchor `:scope > *` and `:scope > *.card` describe the accepted element like any other child compound, but `*` was carried into the merged selector and produced `div.pricing-grid*`, which no browser matches. The universal type is dropped on merge, so those rules land on the anchor itself. Pinned in the rewrite tests. Written with AI assistance (Claude). Co-Authored-By: Claude Fable 5 --- crates/live/src/bake.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/live/src/bake.rs b/crates/live/src/bake.rs index b136ab0e9..954940b55 100644 --- a/crates/live/src/bake.rs +++ b/crates/live/src/bake.rs @@ -147,9 +147,15 @@ fn compound_parts(compound: &str) -> (Option, Vec) { let chars: Vec = compound.chars().collect(); let mut i = 0; let mut tag = String::new(); - while i < chars.len() && (chars[i].is_ascii_alphanumeric() || chars[i] == '-' || chars[i] == '_') { - tag.push(chars[i]); - i += 1; + // The universal selector is a type that matches anything, so it adds + // nothing to an anchor and is dropped here (`*`, `*.card`). + if chars.first() == Some(&'*') { + i = 1; + } else { + while i < chars.len() && (chars[i].is_ascii_alphanumeric() || chars[i] == '-' || chars[i] == '_') { + tag.push(chars[i]); + i += 1; + } } let mut tokens: Vec = Vec::new(); let mut cur = String::new(); @@ -556,6 +562,10 @@ mod tests { assert!(rewrite_selector(":scope > section.pricing-grid", a).is_err()); assert_eq!(rewrite_selector(":scope > section.pricing", "#pricing").unwrap(), "#pricing.pricing"); assert_eq!(rewrite_selector(":scope > .card:not([hidden])", a).unwrap(), "div.pricing-grid.card:not([hidden])"); + // The universal selector adds nothing to the anchor. + assert_eq!(rewrite_selector(":scope > *", a).unwrap(), "div.pricing-grid"); + assert_eq!(rewrite_selector(":scope > *.card", a).unwrap(), "div.pricing-grid.card"); + assert_eq!(rewrite_selector(":scope:hover > * .x", a).unwrap(), "div.pricing-grid:hover .x"); assert!(rewrite_selector(":scope + .x", a).is_err()); assert!(rewrite_selector(".a :scope", a).is_err()); }