diff --git a/__test__/index.spec.mjs.md b/__test__/index.spec.mjs.md index 32a9588..9deceae 100644 --- a/__test__/index.spec.mjs.md +++ b/__test__/index.spec.mjs.md @@ -31,7 +31,7 @@ Generated by [AVA](https://avajs.dev). getDom() {␊ return
␊ ␊ - 成员123: 4000+␊ + 成员123: 4000+␊ ␊
␊ ␊ @@ -65,15 +65,15 @@ Generated by [AVA](https://avajs.dev). padding-bottom: "29px"␊ }}>␊ ␊ -
␊ +
␊ ␊ <>␊ ␊ - ␊ + ␊ ␊ <>␊ ␊ - 超能芭比 5分钟前查看团购␊ + 超能芭比 5分钟前查看团购␊ ␊ ␊ ␊ @@ -81,41 +81,41 @@ Generated by [AVA](https://avajs.dev). ␊
␊ ␊ -
␊ +
␊ ␊ - ␊ + ␊ ␊ -
␊ +
␊ ␊ - 巴拉巴拉小魔仙␊ + 巴拉巴拉小魔仙␊ ␊ - 成员: 4000+␊ + 成员: 4000+␊ ␊
␊ ␊ -
␊ +
␊ ␊ {this.getDom()}␊ ␊ - ␊ + ␊ ␊ - slslsl-jsj␊ + slslsl-jsj␊ ␊ - 复制␊ + 复制␊ ␊
␊ ␊
␊ ␊ -
␊ +
␊ ␊ - ␊ + ␊ ␊ 团长介绍:售前售后进群售前售后进群售前售后进群售前售后进群VXklsidohh...␊ ␊ ␊ ␊ - ␊ + ␊ ␊
␊ ␊ diff --git a/__test__/index.spec.mjs.snap b/__test__/index.spec.mjs.snap index b1892d4..95a70d6 100644 Binary files a/__test__/index.spec.mjs.snap and b/__test__/index.spec.mjs.snap differ diff --git a/src/style_parser.rs b/src/style_parser.rs index 3160229..7075a6c 100644 --- a/src/style_parser.rs +++ b/src/style_parser.rs @@ -163,19 +163,16 @@ impl<'i> StyleParser<'i> { let has_property_index = final_properties .iter() .position(|property| property.property_id() == parent_declaration.property_id()); + let is_style_inheritable = is_style_inheritable(parent_declaration.property_id()); if let Some(index) = has_property_index { - let is_style_inheritable = is_style_inheritable(final_properties[index].property_id()); - if is_style_inheritable { - final_properties[index] = parent_declaration.clone(); - } else { - let value = final_properties[index].value_to_css_string(PrinterOptions::default()); + let value = final_properties[index].value_to_css_string(PrinterOptions::default()); if let Ok(value) = value { + // Todo "initial" "unset" if value.as_str() == "inherit" { final_properties[index] = parent_declaration.clone(); } } - } - } else { + } else if is_style_inheritable { final_properties.push(parent_declaration.clone()); } } diff --git a/src/utils.rs b/src/utils.rs index ba408a2..a78e1e2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -5,7 +5,7 @@ use lightningcss::properties::PropertyId; use once_cell::sync::Lazy; use swc_ecma_ast::{JSXMemberExpr, JSXObject}; -static _INHERITABLE_STYLES: Lazy>> = Lazy::new(|| { +static INHERITABLE_STYLES: Lazy>> = Lazy::new(|| { let mut styles = HashSet::new(); styles.insert(PropertyId::from("color")); styles.insert(PropertyId::from("font-size")); @@ -90,9 +90,8 @@ pub fn create_qualname(str: &str) -> QualName { QualName::new(None, ns!(), LocalName::from(str)) } -pub fn is_style_inheritable(_style: PropertyId<'_>) -> bool { - // INHERITABLE_STYLES.contains(&style) - false +pub fn is_style_inheritable(style: PropertyId<'_>) -> bool { + INHERITABLE_STYLES.contains(&style) } pub fn is_starts_with_uppercase(str: &str) -> bool {