1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use swc_core::ecma::ast::JSXFragment;

use crate::{shared::Transform, vnode::VNode};

#[derive(Debug)]
pub struct Fragment<'a> {
    pub children: Vec<VNode<'a>>,

    pub is_static: bool,
}

impl<'a> Fragment<'a> {
    pub fn static_content(&self) -> String {
        self.children.iter().map(VNode::static_content).collect()
    }
}

impl<'a> Transform<'a, Fragment<'a>> for JSXFragment {
    fn transform(&'a self) -> Fragment<'a> {
        let children: Vec<VNode> = self.children.transform();

        let is_static = children.iter().all(VNode::is_static);

        Fragment {
            children,

            is_static,
        }
    }
}