Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion float-pigment-css/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ name = "parse"
harness = false

[features]
default = ["std", "deserialize", "serialize", "ffi"]
default = ["std", "deserialize", "serialize", "ffi", "debug"]
std = ["serde/std", "serde_json/std", "bit-set/std", "num-traits/std", "half/std", "float-pigment-consistent-bincode/std"]
no-std-lock = []
wasm-entrance = ["wasm-bindgen", "console_log", "console_error_panic_hook", "js-sys"]
Expand All @@ -50,6 +50,7 @@ compatibility_test = []
compile_cache = ["toml", "colorful"]
skip_compare_cache = ["float-pigment-css-macro/skip_compare_cache"]
ffi = []
debug = []

[dependencies]
wasm-bindgen = { version = "0.2", optional = true }
Expand Down
1 change: 1 addition & 0 deletions float-pigment-css/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ pub unsafe extern "C" fn parse_inline_style(
bs_empty = false;
property
}
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup { .. } => Property::Unknown,
})
.collect();
Expand Down
16 changes: 15 additions & 1 deletion float-pigment-css/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,19 @@ fn parse_property_item<'a, 't: 'a, 'i: 't>(
Ok(())
}

#[cfg(not(feature = "debug"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entrance of this is parser::parse_inline_style.

An extra assertion of debug mode is needed there.

#[inline(always)]
fn parse_property_item_debug<'a, 't: 'a, 'i: 't>(
parser: &'a mut Parser<'i, 't>,
properties: &'a mut Vec<PropertyMeta>,
st: &mut ParseState,
disabled: bool,
rule_end_position: Option<SourcePosition>,
) -> Result<(), ParseError<'i, CustomError>> {
Err(parser.new_custom_error(CustomError::Unsupported))
}

#[cfg(feature = "debug")]
#[inline(always)]
fn parse_property_item_debug<'a, 't: 'a, 'i: 't>(
parser: &'a mut Parser<'i, 't>,
Expand Down Expand Up @@ -1908,6 +1921,7 @@ fn parse_property_value_with_important<'a, 't: 'a, 'i: 't>(
*pm = match pm2 {
PropertyMeta::Normal { property } => PropertyMeta::Important { property },
PropertyMeta::Important { .. } => unreachable!(),
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup { .. } => unreachable!(),
};
}
Expand All @@ -1923,6 +1937,7 @@ fn parse_property_value_with_important<'a, 't: 'a, 'i: 't>(
if let Some(p) = match &mut pm {
PropertyMeta::Normal { property } => Some(property),
PropertyMeta::Important { property } => Some(property),
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup { .. } => None,
} {
let ctx = &mut hooks::ParserHooksContext {
Expand Down Expand Up @@ -1983,7 +1998,6 @@ fn parse_custom_property_value_with_important<'a, 't: 'a, 'i: 't>(

#[cfg(test)]
mod test {

use super::{is_url, parse_color_to_rgba, resolve_relative_path};

#[test]
Expand Down
2 changes: 2 additions & 0 deletions float-pigment-css/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ impl MatchedRuleList {
}
}
}
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup {
properties,
important,
Expand Down Expand Up @@ -442,6 +443,7 @@ impl MatchedRuleList {
node_properties.merge_property(p, parent_node_properties, current_font_size)
}
}
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup {
properties,
important,
Expand Down
1 change: 1 addition & 0 deletions float-pigment-css/src/sheet/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ impl Rule {
bs_empty = false;
property
}
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup { .. } => Property::Unknown,
})
.collect();
Expand Down
15 changes: 14 additions & 1 deletion float-pigment-css/src/sheet/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ pub enum PropertyMeta {
///
/// It is designed for debugging only.
/// In production environment, properties are well-normalized -
/// shorthand properties (e.g. `font` `background`) are splitted in advance.
/// shorthand properties (e.g. `font` `background`) are split in advance.
/// However, we may add new shorthand properties in debugger -
/// we can keep the shorthand properties as-is with `DebugGroup`s.
#[cfg(feature = "debug")]
DebugGroup {
/// The original name-value string pair.
original_name_value: Box<(String, String)>,
Expand Down Expand Up @@ -51,6 +52,7 @@ impl PropertyMeta {
/// Note that the new property is in *debug* mode so that:
/// * it cannot be serialized even if it has been inserted to a rule;
/// * it has a little performance penalty.
#[cfg(feature = "debug")]
pub fn to_debug_state(&self, disabled: bool) -> Self {
match self {
Self::Normal { property } => Self::DebugGroup {
Expand Down Expand Up @@ -90,6 +92,7 @@ impl PropertyMeta {
match self {
Self::Normal { .. } => false,
Self::Important { .. } => true,
#[cfg(feature = "debug")]
Self::DebugGroup { important, .. } => *important,
}
}
Expand All @@ -99,6 +102,7 @@ impl PropertyMeta {
match self {
Self::Normal { property } => property.get_property_name().into(),
Self::Important { property } => property.get_property_name().into(),
#[cfg(feature = "debug")]
Self::DebugGroup {
original_name_value,
..
Expand All @@ -117,6 +121,7 @@ impl PropertyMeta {
v.push_str(" !important");
v
}
#[cfg(feature = "debug")]
Self::DebugGroup {
original_name_value,
..
Expand All @@ -129,6 +134,7 @@ impl PropertyMeta {
match self {
Self::Normal { .. } => false,
Self::Important { .. } => false,
#[cfg(feature = "debug")]
Self::DebugGroup { disabled, .. } => *disabled,
}
}
Expand All @@ -138,6 +144,7 @@ impl PropertyMeta {
match self {
Self::Normal { .. } => false,
Self::Important { .. } => false,
#[cfg(feature = "debug")]
Self::DebugGroup { properties, .. } => properties.len() == 0,
}
}
Expand All @@ -148,6 +155,7 @@ impl PropertyMeta {
Self::Normal { property, .. } | Self::Important { property, .. } => {
property.is_deprecated()
}
#[cfg(feature = "debug")]
Self::DebugGroup { .. } => false,
}
}
Expand All @@ -166,6 +174,7 @@ impl PropertyMeta {
PropertyMeta::Important { property: p } => {
node_properties.merge_property(p, parent_node_properties, current_font_size)
}
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup {
properties,
disabled,
Expand All @@ -189,6 +198,7 @@ impl PropertyMeta {
pub fn property(&self) -> Option<Property> {
match self {
Self::Normal { property } | Self::Important { property } => Some(property.clone()),
#[cfg(feature = "debug")]
Self::DebugGroup { .. } => None,
}
}
Expand Down Expand Up @@ -233,6 +243,7 @@ impl<'a> Iterator for PropertyMetaIter<'a> {
None
}
}
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup { properties, .. } => {
if self.cur < properties.len() {
let ret = &properties[self.cur];
Expand Down Expand Up @@ -317,6 +328,7 @@ impl Rule {
_ => {}
}
}
#[cfg(feature = "debug")]
PropertyMeta::DebugGroup { properties, .. } => {
for property in properties.iter() {
match property {
Expand Down Expand Up @@ -377,6 +389,7 @@ impl Rule {
}

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