tailwind_ast/ast/
methods.rs1use super::*;
2
3impl<'a> AstStyle<'a> {
4 #[inline]
6 pub fn is_self_reference(&self) -> bool {
7 matches!(self.elements.as_slice(), ["&"])
8 }
9}
10
11impl<'a> AstGroup<'a> {
12 #[inline]
14 pub fn expand(self, styles: &mut Vec<AstStyle<'a>>) {
15 let head = &self.head;
16 for item in self.children {
17 item.expand_with_head(styles, head)
18 }
19 }
20}
21
22impl<'a> Add<AstGroup<'a>> for AstStyle<'a> {
23 type Output = AstGroup<'a>;
24 #[inline]
25 fn add(self, rhs: AstGroup<'a>) -> Self::Output {
26 let mut head = self;
27 head.add_assign(&rhs.head);
28 AstGroup { important: false, head, children: rhs.children }
29 }
30}
31
32impl<'a> AstGroupItem<'a> {
33 #[inline]
35 pub fn expand(self, styles: &mut Vec<AstStyle<'a>>) {
36 match self {
37 Self::Grouped(g) => g.expand(styles),
38 Self::Styled(rhs) => styles.push(rhs),
39 }
40 }
41
42 #[inline]
44 pub fn expand_with_head(self, styles: &mut Vec<AstStyle<'a>>, head: &AstStyle<'a>) {
45 match self {
46 Self::Grouped(g) => {
47 let new = head.clone().add(g);
48 new.expand(styles)
49 }
50 Self::Styled(rhs) => {
51 let mut new = head.clone();
52 new.add_assign(&rhs);
53 styles.push(new)
54 }
55 }
56 }
57}
58
59impl<'a> AddAssign<&AstStyle<'a>> for AstStyle<'a> {
60 #[inline]
61 fn add_assign(&mut self, rhs: &AstStyle<'a>) {
62 self.negative = merge_negative(self.negative, rhs.negative);
63 self.variants.extend(rhs.variants.iter().cloned());
64 self.arbitrary = self.arbitrary.or(self.arbitrary);
65 match rhs.is_self_reference() {
66 true => {}
67 false => self.elements.extend(rhs.elements.iter().cloned()),
68 };
69 }
70}
71
72#[inline]
73fn merge_negative(lhs: bool, rhs: bool) -> bool {
74 match (lhs, rhs) {
75 (true, true) => true,
76 (true, false) | (false, true) => true,
77 (false, false) => false,
78 }
79}