procss/transformers/flat_self.rs
1// ┌───────────────────────────────────────────────────────────────────────────┐
2// │ │
3// │ ██████╗ ██████╗ ██████╗ Copyright (C) 2022, The Prospective Company │
4// │ ██╔══██╗██╔══██╗██╔═══██╗ │
5// │ ██████╔╝██████╔╝██║ ██║ This file is part of the Procss library, │
6// │ ██╔═══╝ ██╔══██╗██║ ██║ distributed under the terms of the │
7// │ ██║ ██║ ██║╚██████╔╝ Apache License 2.0. The full license can │
8// │ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ be found in the LICENSE file. │
9// │ │
10// └───────────────────────────────────────────────────────────────────────────┘
11
12use crate::ast::{Css, SelectorPath};
13use crate::transform::*;
14
15/// Remove `&` references from a flattened `Css`.
16pub(crate) fn flat_self(css: &mut Css) {
17 css.transform_each(&mut |x: &mut SelectorPath| {
18 let res = match x {
19 SelectorPath::Cons(..) => None,
20 SelectorPath::PartialCons(_, tail) if !tail.is_empty() => {
21 Some(SelectorPath::Cons(tail.remove(0).1, tail.clone()))
22 }
23 _ => None,
24 };
25
26 if let Some(y) = res {
27 *x = y;
28 }
29 });
30}