Skip to content

Commit

Permalink
Parse a TokenList instead of only a single Token in @Property rules
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Feb 15, 2024
1 parent 2f18ed9 commit 949eb13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
14 changes: 12 additions & 2 deletions src/lib.rs
Expand Up @@ -25904,7 +25904,7 @@ mod tests {
initial-value: ;
}
"#,
"@property --property-name{syntax:\"*\";inherits:false;initial-value: }",
"@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
);

test(
Expand Down Expand Up @@ -25932,7 +25932,17 @@ mod tests {
initial-value:;
}
"#,
"@property --property-name{syntax:\"*\";inherits:false;initial-value: }",
"@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
);
minify_test(
r#"
@property --property-name {
syntax: '*';
inherits: false;
initial-value: foo bar;
}
"#,
"@property --property-name{syntax:\"*\";inherits:false;initial-value:foo bar}",
);

minify_test(
Expand Down
20 changes: 5 additions & 15 deletions src/rules/property.rs
Expand Up @@ -4,13 +4,10 @@ use super::Location;
#[cfg(feature = "visitor")]
use crate::visitor::Visit;
use crate::{
error::{ParserError, PrinterError},
printer::Printer,
traits::{Parse, ToCss},
values::{
error::{ParserError, PrinterError}, printer::Printer, properties::custom::TokenList, traits::{Parse, ToCss}, values::{
ident::DashedIdent,
syntax::{ParsedComponent, SyntaxString},
},
}
};
use cssparser::*;

Expand Down Expand Up @@ -82,9 +79,7 @@ impl<'i> PropertyRule<'i> {
let mut parser = Parser::new(&mut input);

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

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

if !dest.minify {
dest.write_char(';')?;
Expand Down
12 changes: 6 additions & 6 deletions src/values/syntax.rs
Expand Up @@ -4,6 +4,8 @@ use super::ident::Ident;
use super::number::{CSSInteger, CSSNumber};
use crate::error::{ParserError, PrinterError};
use crate::printer::Printer;
use crate::properties::custom::TokenList;
use crate::stylesheet::ParserOptions;
use crate::traits::{Parse, ToCss};
use crate::values;
#[cfg(feature = "visitor")]
Expand Down Expand Up @@ -155,8 +157,8 @@ pub enum ParsedComponent<'i> {
/// A multiplier describing how the components repeat.
multiplier: Multiplier,
},
/// A raw token.
Token(crate::properties::custom::Token<'i>),
/// A raw token stream.
TokenList(crate::properties::custom::TokenList<'i>),
}

impl<'i> SyntaxString {
Expand Down Expand Up @@ -199,9 +201,7 @@ impl<'i> SyntaxString {
input: &mut Parser<'i, 't>,
) -> Result<ParsedComponent<'i>, ParseError<'i, ParserError<'i>>> {
match self {
SyntaxString::Universal => Ok(ParsedComponent::Token(crate::properties::custom::Token::from(
input.next()?,
))),
SyntaxString::Universal => Ok(ParsedComponent::TokenList(TokenList::parse(input, &ParserOptions::default(), 0)?)),
SyntaxString::Components(components) => {
// Loop through each component, and return the first one that parses successfully.
for component in components {
Expand Down Expand Up @@ -491,7 +491,7 @@ impl<'i> ToCss for ParsedComponent<'i> {
}
Ok(())
}
Token(t) => t.to_css(dest),
TokenList(t) => t.to_css(dest, false),
}
}
}
Expand Down

0 comments on commit 949eb13

Please sign in to comment.