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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::css_rules::Location;
use crate::properties::custom::TokenList;
use crate::{PrintErr, Printer};
/// An unknown at-rule, stored as raw tokens.
pub struct UnknownAtRule {
/// The name of the at-rule (without the @).
// TODO(port): arena lifetime — Zig `[]const u8` backed by parser arena.
pub name: &'static [u8],
/// The prelude of the rule.
pub prelude: TokenList,
/// The contents of the block, if any.
pub block: Option<TokenList>,
/// The location of the rule in the source file.
pub loc: Location,
}
impl UnknownAtRule {
pub fn to_css(&self, dest: &mut Printer) -> Result<(), PrintErr> {
// #[cfg(feature = "sourcemap")]
// dest.add_mapping(self.loc);
dest.write_char(b'@')?;
dest.write_str(self.name)?;
if !self.prelude.v.is_empty() {
dest.write_char(b' ')?;
self.prelude.to_css(dest, false)?;
}
if let Some(block) = &self.block {
dest.block(|d| {
d.newline()?;
block.to_css(d, false)
})
} else {
dest.write_char(b';')
}
}
pub fn deep_clone(&self, bump: &bun_alloc::Arena) -> Self {
use crate::generics::DeepClone as _;
// PORT NOTE: `css.implementDeepClone` field-walk. `name: &'static [u8]`
// is an arena-owned slice → identity copy (generics.zig "const strings"
// rule); `TokenList` carries `#[derive(DeepClone)]`.
Self {
name: self.name,
prelude: self.prelude.deep_clone(bump),
block: self.block.as_ref().map(|b| b.deep_clone(bump)),
loc: self.loc,
}
}
}
// ported from: src/css/rules/unknown.zig