Skip to content

Commit 949eb13

Browse files
committed
Parse a TokenList instead of only a single Token in @Property rules
1 parent 2f18ed9 commit 949eb13

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -25904,7 +25904,7 @@ mod tests {
2590425904
initial-value: ;
2590525905
}
2590625906
"#,
25907-
"@property --property-name{syntax:\"*\";inherits:false;initial-value: }",
25907+
"@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
2590825908
);
2590925909

2591025910
test(
@@ -25932,7 +25932,17 @@ mod tests {
2593225932
initial-value:;
2593325933
}
2593425934
"#,
25935-
"@property --property-name{syntax:\"*\";inherits:false;initial-value: }",
25935+
"@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
25936+
);
25937+
minify_test(
25938+
r#"
25939+
@property --property-name {
25940+
syntax: '*';
25941+
inherits: false;
25942+
initial-value: foo bar;
25943+
}
25944+
"#,
25945+
"@property --property-name{syntax:\"*\";inherits:false;initial-value:foo bar}",
2593625946
);
2593725947

2593825948
minify_test(

src/rules/property.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ use super::Location;
44
#[cfg(feature = "visitor")]
55
use crate::visitor::Visit;
66
use crate::{
7-
error::{ParserError, PrinterError},
8-
printer::Printer,
9-
traits::{Parse, ToCss},
10-
values::{
7+
error::{ParserError, PrinterError}, printer::Printer, properties::custom::TokenList, traits::{Parse, ToCss}, values::{
118
ident::DashedIdent,
129
syntax::{ParsedComponent, SyntaxString},
13-
},
10+
}
1411
};
1512
use cssparser::*;
1613

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

8481
if parser.is_exhausted() {
85-
Some(ParsedComponent::Token(crate::properties::custom::Token::WhiteSpace(
86-
" ".into(),
87-
)))
82+
Some(ParsedComponent::TokenList(TokenList(vec![])))
8883
} else {
8984
Some(syntax.parse_value(&mut parser)?)
9085
}
@@ -142,13 +137,8 @@ impl<'i> ToCss for PropertyRule<'i> {
142137
dest.newline()?;
143138

144139
dest.write_str("initial-value:")?;
145-
match initial_value {
146-
ParsedComponent::Token(crate::properties::custom::Token::WhiteSpace(value)) => dest.write_str(value)?,
147-
_ => {
148-
dest.whitespace()?;
149-
initial_value.to_css(dest)?;
150-
}
151-
}
140+
dest.whitespace()?;
141+
initial_value.to_css(dest)?;
152142

153143
if !dest.minify {
154144
dest.write_char(';')?;

src/values/syntax.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use super::ident::Ident;
44
use super::number::{CSSInteger, CSSNumber};
55
use crate::error::{ParserError, PrinterError};
66
use crate::printer::Printer;
7+
use crate::properties::custom::TokenList;
8+
use crate::stylesheet::ParserOptions;
79
use crate::traits::{Parse, ToCss};
810
use crate::values;
911
#[cfg(feature = "visitor")]
@@ -155,8 +157,8 @@ pub enum ParsedComponent<'i> {
155157
/// A multiplier describing how the components repeat.
156158
multiplier: Multiplier,
157159
},
158-
/// A raw token.
159-
Token(crate::properties::custom::Token<'i>),
160+
/// A raw token stream.
161+
TokenList(crate::properties::custom::TokenList<'i>),
160162
}
161163

162164
impl<'i> SyntaxString {
@@ -199,9 +201,7 @@ impl<'i> SyntaxString {
199201
input: &mut Parser<'i, 't>,
200202
) -> Result<ParsedComponent<'i>, ParseError<'i, ParserError<'i>>> {
201203
match self {
202-
SyntaxString::Universal => Ok(ParsedComponent::Token(crate::properties::custom::Token::from(
203-
input.next()?,
204-
))),
204+
SyntaxString::Universal => Ok(ParsedComponent::TokenList(TokenList::parse(input, &ParserOptions::default(), 0)?)),
205205
SyntaxString::Components(components) => {
206206
// Loop through each component, and return the first one that parses successfully.
207207
for component in components {
@@ -491,7 +491,7 @@ impl<'i> ToCss for ParsedComponent<'i> {
491491
}
492492
Ok(())
493493
}
494-
Token(t) => t.to_css(dest),
494+
TokenList(t) => t.to_css(dest, false),
495495
}
496496
}
497497
}

0 commit comments

Comments
 (0)