Skip to content

Commit 44be96c

Browse files
committed
feat: +feature debug to disable DebugGroup
1 parent 7f0bd79 commit 44be96c

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

float-pigment-css/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ name = "parse"
3535
harness = false
3636

3737
[features]
38-
default = ["std", "deserialize", "serialize", "ffi"]
38+
default = ["std", "deserialize", "serialize", "ffi", "debug"]
3939
std = ["serde/std", "serde_json/std", "bit-set/std", "num-traits/std", "half/std", "float-pigment-consistent-bincode/std"]
4040
no-std-lock = []
4141
wasm-entrance = ["wasm-bindgen", "console_log", "console_error_panic_hook", "js-sys"]
@@ -50,6 +50,7 @@ compatibility_test = []
5050
compile_cache = ["toml", "colorful"]
5151
skip_compare_cache = ["float-pigment-css-macro/skip_compare_cache"]
5252
ffi = []
53+
debug = []
5354

5455
[dependencies]
5556
wasm-bindgen = { version = "0.2", optional = true }

float-pigment-css/src/parser/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,19 @@ fn parse_property_item<'a, 't: 'a, 'i: 't>(
18011801
Ok(())
18021802
}
18031803

1804+
#[cfg(not(feature = "debug"))]
1805+
#[inline(always)]
1806+
fn parse_property_item_debug<'a, 't: 'a, 'i: 't>(
1807+
parser: &'a mut Parser<'i, 't>,
1808+
properties: &'a mut Vec<PropertyMeta>,
1809+
st: &mut ParseState,
1810+
disabled: bool,
1811+
rule_end_position: Option<SourcePosition>,
1812+
) -> Result<(), ParseError<'i, CustomError>> {
1813+
Err(parser.new_custom_error(CustomError::Unsupported))
1814+
}
1815+
1816+
#[cfg(feature = "debug")]
18041817
#[inline(always)]
18051818
fn parse_property_item_debug<'a, 't: 'a, 'i: 't>(
18061819
parser: &'a mut Parser<'i, 't>,
@@ -1908,6 +1921,7 @@ fn parse_property_value_with_important<'a, 't: 'a, 'i: 't>(
19081921
*pm = match pm2 {
19091922
PropertyMeta::Normal { property } => PropertyMeta::Important { property },
19101923
PropertyMeta::Important { .. } => unreachable!(),
1924+
#[cfg(feature = "debug")]
19111925
PropertyMeta::DebugGroup { .. } => unreachable!(),
19121926
};
19131927
}
@@ -1923,6 +1937,7 @@ fn parse_property_value_with_important<'a, 't: 'a, 'i: 't>(
19231937
if let Some(p) = match &mut pm {
19241938
PropertyMeta::Normal { property } => Some(property),
19251939
PropertyMeta::Important { property } => Some(property),
1940+
#[cfg(feature = "debug")]
19261941
PropertyMeta::DebugGroup { .. } => None,
19271942
} {
19281943
let ctx = &mut hooks::ParserHooksContext {
@@ -1983,7 +1998,6 @@ fn parse_custom_property_value_with_important<'a, 't: 'a, 'i: 't>(
19831998

19841999
#[cfg(test)]
19852000
mod test {
1986-
19872001
use super::{is_url, parse_color_to_rgba, resolve_relative_path};
19882002

19892003
#[test]

float-pigment-css/src/query.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ impl MatchedRuleList {
370370
}
371371
}
372372
}
373+
#[cfg(feature = "debug")]
373374
PropertyMeta::DebugGroup {
374375
properties,
375376
important,
@@ -442,6 +443,7 @@ impl MatchedRuleList {
442443
node_properties.merge_property(p, parent_node_properties, current_font_size)
443444
}
444445
}
446+
#[cfg(feature = "debug")]
445447
PropertyMeta::DebugGroup {
446448
properties,
447449
important,

float-pigment-css/src/sheet/rule.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ pub enum PropertyMeta {
2121
///
2222
/// It is designed for debugging only.
2323
/// In production environment, properties are well-normalized -
24-
/// shorthand properties (e.g. `font` `background`) are splitted in advance.
24+
/// shorthand properties (e.g. `font` `background`) are split in advance.
2525
/// However, we may add new shorthand properties in debugger -
2626
/// we can keep the shorthand properties as-is with `DebugGroup`s.
27+
#[cfg(feature = "debug")]
2728
DebugGroup {
2829
/// The original name-value string pair.
2930
original_name_value: Box<(String, String)>,
@@ -51,6 +52,7 @@ impl PropertyMeta {
5152
/// Note that the new property is in *debug* mode so that:
5253
/// * it cannot be serialized even if it has been inserted to a rule;
5354
/// * it has a little performance penalty.
55+
#[cfg(feature = "debug")]
5456
pub fn to_debug_state(&self, disabled: bool) -> Self {
5557
match self {
5658
Self::Normal { property } => Self::DebugGroup {
@@ -90,6 +92,7 @@ impl PropertyMeta {
9092
match self {
9193
Self::Normal { .. } => false,
9294
Self::Important { .. } => true,
95+
#[cfg(feature = "debug")]
9396
Self::DebugGroup { important, .. } => *important,
9497
}
9598
}
@@ -99,6 +102,7 @@ impl PropertyMeta {
99102
match self {
100103
Self::Normal { property } => property.get_property_name().into(),
101104
Self::Important { property } => property.get_property_name().into(),
105+
#[cfg(feature = "debug")]
102106
Self::DebugGroup {
103107
original_name_value,
104108
..
@@ -117,6 +121,7 @@ impl PropertyMeta {
117121
v.push_str(" !important");
118122
v
119123
}
124+
#[cfg(feature = "debug")]
120125
Self::DebugGroup {
121126
original_name_value,
122127
..
@@ -129,6 +134,7 @@ impl PropertyMeta {
129134
match self {
130135
Self::Normal { .. } => false,
131136
Self::Important { .. } => false,
137+
#[cfg(feature = "debug")]
132138
Self::DebugGroup { disabled, .. } => *disabled,
133139
}
134140
}
@@ -138,6 +144,7 @@ impl PropertyMeta {
138144
match self {
139145
Self::Normal { .. } => false,
140146
Self::Important { .. } => false,
147+
#[cfg(feature = "debug")]
141148
Self::DebugGroup { properties, .. } => properties.len() == 0,
142149
}
143150
}
@@ -148,6 +155,7 @@ impl PropertyMeta {
148155
Self::Normal { property, .. } | Self::Important { property, .. } => {
149156
property.is_deprecated()
150157
}
158+
#[cfg(feature = "debug")]
151159
Self::DebugGroup { .. } => false,
152160
}
153161
}
@@ -166,6 +174,7 @@ impl PropertyMeta {
166174
PropertyMeta::Important { property: p } => {
167175
node_properties.merge_property(p, parent_node_properties, current_font_size)
168176
}
177+
#[cfg(feature = "debug")]
169178
PropertyMeta::DebugGroup {
170179
properties,
171180
disabled,
@@ -189,6 +198,7 @@ impl PropertyMeta {
189198
pub fn property(&self) -> Option<Property> {
190199
match self {
191200
Self::Normal { property } | Self::Important { property } => Some(property.clone()),
201+
#[cfg(feature = "debug")]
192202
Self::DebugGroup { .. } => None,
193203
}
194204
}
@@ -233,6 +243,7 @@ impl<'a> Iterator for PropertyMetaIter<'a> {
233243
None
234244
}
235245
}
246+
#[cfg(feature = "debug")]
236247
PropertyMeta::DebugGroup { properties, .. } => {
237248
if self.cur < properties.len() {
238249
let ret = &properties[self.cur];
@@ -317,6 +328,7 @@ impl Rule {
317328
_ => {}
318329
}
319330
}
331+
#[cfg(feature = "debug")]
320332
PropertyMeta::DebugGroup { properties, .. } => {
321333
for property in properties.iter() {
322334
match property {
@@ -377,6 +389,7 @@ impl Rule {
377389
}
378390

379391
/// Enable or disable the rule (and construct a new one as the result if success)
392+
#[cfg(feature = "debug")]
380393
pub fn set_property_disabled(&self, index: usize, disabled: bool) -> Option<Box<Self>> {
381394
let media = self.media.clone();
382395
let selector = self.selector.clone();

0 commit comments

Comments
 (0)