Skip to content

Commit

Permalink
Allow whitespace (or nothing) in the initial-value of @property w…
Browse files Browse the repository at this point in the history
…ith universal syntax (#657)
  • Loading branch information
RobinMalfait committed Jan 13, 2024
1 parent b543fe7 commit 74b6e89
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
56 changes: 56 additions & 0 deletions src/lib.rs
Expand Up @@ -25863,6 +25863,62 @@ mod tests {
"@property --property-name{syntax:\"<color>\";inherits:false;initial-value:#ff0}",
);

test(
r#"
@property --property-name {
syntax: '*';
inherits: false;
initial-value: ;
}
"#,
indoc! {r#"
@property --property-name {
syntax: "*";
inherits: false;
initial-value: ;
}
"#},
);

minify_test(
r#"
@property --property-name {
syntax: '*';
inherits: false;
initial-value: ;
}
"#,
"@property --property-name{syntax:\"*\";inherits:false;initial-value: }",
);

test(
r#"
@property --property-name {
syntax: '*';
inherits: false;
initial-value:;
}
"#,
indoc! {r#"
@property --property-name {
syntax: "*";
inherits: false;
initial-value: ;
}
"#},
);

minify_test(
r#"
@property --property-name {
syntax: '*';
inherits: false;
initial-value:;
}
"#,
"@property --property-name{syntax:\"*\";inherits:false;initial-value: }",
);

minify_test(
r#"
@property --property-name {
Expand Down
19 changes: 16 additions & 3 deletions src/rules/property.rs
Expand Up @@ -80,7 +80,14 @@ impl<'i> PropertyRule<'i> {
Some(val) => {
let mut input = ParserInput::new(val);
let mut parser = Parser::new(&mut input);
Some(syntax.parse_value(&mut parser)?)

if parser.is_exhausted() {
Some(ParsedComponent::Token(crate::properties::custom::Token::WhiteSpace(
" ".into(),
)))
} else {
Some(syntax.parse_value(&mut parser)?)
}
}
},
_ => {
Expand Down Expand Up @@ -135,8 +142,14 @@ impl<'i> ToCss for PropertyRule<'i> {
dest.newline()?;

dest.write_str("initial-value:")?;
dest.whitespace()?;
initial_value.to_css(dest)?;
match initial_value {
ParsedComponent::Token(crate::properties::custom::Token::WhiteSpace(value)) => dest.write_str(value)?,
_ => {
dest.whitespace()?;
initial_value.to_css(dest)?;
}
}

if !dest.minify {
dest.write_char(';')?;
}
Expand Down

0 comments on commit 74b6e89

Please sign in to comment.