Process nested rules and add them to collection rules. The `conditions` parameter contains all conditions that must be true for nested rules to execute. The `parent_span` parameter provides span context for selectorless rules (from parent NodeRule or StyleSheet).
( &mut self, nested_rules: &'a [NestedRule<'a>], conditions: &Vec<'a, &'a WhenCondition<'a>>, parent_span: Span, )
| 187 | /// The `conditions` parameter contains all conditions that must be true for nested rules to execute. |
| 188 | /// The `parent_span` parameter provides span context for selectorless rules (from parent NodeRule or StyleSheet). |
| 189 | fn process_nested_rules( |
| 190 | &mut self, |
| 191 | nested_rules: &'a [NestedRule<'a>], |
| 192 | conditions: &Vec<'a, &'a WhenCondition<'a>>, |
| 193 | parent_span: Span, |
| 194 | ) { |
| 195 | for nested_rule in nested_rules { |
| 196 | match nested_rule { |
| 197 | NestedRule::NodeRule(node_rule) => { |
| 198 | let rule_data = self.extract_rule_data(&node_rule.block.declarations); |
| 199 | let node_span = node_rule.to_span(); |
| 200 | |
| 201 | self.collection_rules.push(CollectionRule { |
| 202 | selector: Some(&node_rule.selector), |
| 203 | collectors: rule_data.collectors, |
| 204 | diagnostic: rule_data.diagnostic, |
| 205 | diagnostic_stats: rule_data.diagnostic_stats, |
| 206 | conditions: conditions.clone(), |
| 207 | parent_span: node_span, |
| 208 | matches: vec![in self.allocator], |
| 209 | }); |
| 210 | |
| 211 | self.process_nested_rules(&node_rule.block.rules, conditions, node_span); |
| 212 | } |
| 213 | NestedRule::WhenRule(when_rule) => { |
| 214 | if !when_rule.condition.is_valid(self.source) { |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | let mut combined_conditions = conditions.clone(); |
| 219 | combined_conditions.push(&when_rule.condition); |
| 220 | |
| 221 | let rule_data = self.extract_rule_data(&when_rule.block.declarations); |
| 222 | if !rule_data.collectors.is_empty() || rule_data.diagnostic.is_some() { |
| 223 | self.collection_rules.push(CollectionRule { |
| 224 | selector: None, |
| 225 | collectors: rule_data.collectors, |
| 226 | diagnostic: rule_data.diagnostic, |
| 227 | diagnostic_stats: rule_data.diagnostic_stats, |
| 228 | conditions: combined_conditions.clone(), |
| 229 | parent_span, |
| 230 | matches: vec![in self.allocator], |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | self.process_nested_rules(&when_rule.block.rules, &combined_conditions, parent_span); |
| 235 | } |
| 236 | NestedRule::Unknown(_) => {} |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /// Create a new Collector from a parsed Sheet. |
| 242 | pub fn new(sheet: &'a Sheet<'a>, source: &'a str, allocator: &'a Bump) -> Self { |