correctly parse quoted media queries
This commit is contained in:
parent
a813cab0d7
commit
0639a6ba2b
@ -1,6 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
error::SassResult,
|
error::SassResult,
|
||||||
utils::{is_name_start, peek_ident_no_interpolation, read_until_closing_paren},
|
utils::{
|
||||||
|
is_name_start, peek_ident_no_interpolation, read_until_closing_paren,
|
||||||
|
read_until_closing_quote,
|
||||||
|
},
|
||||||
{Cow, Token},
|
{Cow, Token},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,13 +64,18 @@ impl<'a> Parser<'a> {
|
|||||||
'>' | '<' | ':' | ')' => {
|
'>' | '<' | ':' | ')' => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
'\'' | '"' => {
|
||||||
|
toks.push(tok);
|
||||||
|
self.toks.next();
|
||||||
|
toks.append(&mut read_until_closing_quote(self.toks, tok.kind)?);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
toks.push(tok);
|
toks.push(tok);
|
||||||
self.toks.next();
|
self.toks.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.parse_value_as_string_from_vec(toks)
|
self.parse_value_as_string_from_vec(toks, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn parse_media_query_list(&mut self) -> SassResult<String> {
|
pub(super) fn parse_media_query_list(&mut self) -> SassResult<String> {
|
||||||
@ -112,7 +120,7 @@ impl<'a> Parser<'a> {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.push_str(&self.parse_value_as_string_from_vec(toks)?);
|
buf.push_str(&self.parse_value_as_string_from_vec(toks, true)?);
|
||||||
|
|
||||||
self.whitespace();
|
self.whitespace();
|
||||||
buf.push(')');
|
buf.push(')');
|
||||||
|
@ -435,9 +435,14 @@ impl<'a> Parser<'a> {
|
|||||||
pub fn parse_value_as_string_from_vec(
|
pub fn parse_value_as_string_from_vec(
|
||||||
&mut self,
|
&mut self,
|
||||||
toks: Vec<Token>,
|
toks: Vec<Token>,
|
||||||
|
quoted: bool,
|
||||||
) -> SassResult<Cow<'static, str>> {
|
) -> SassResult<Cow<'static, str>> {
|
||||||
let value = self.parse_value_from_vec(toks)?;
|
let value = self.parse_value_from_vec(toks)?;
|
||||||
|
if quoted {
|
||||||
value.node.to_css_string(value.span)
|
value.node.to_css_string(value.span)
|
||||||
|
} else {
|
||||||
|
value.node.unquote().to_css_string(value.span)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn whitespace(&mut self) -> bool {
|
pub fn whitespace(&mut self) -> bool {
|
||||||
|
@ -54,3 +54,12 @@ test!(
|
|||||||
"@media (color) {a {color: red;}}",
|
"@media (color) {a {color: red;}}",
|
||||||
"@media (color) {\n a {\n color: red;\n }\n}\n"
|
"@media (color) {\n a {\n color: red;\n }\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
quoted_colon_in_parens,
|
||||||
|
"@media screen and (\":\") {
|
||||||
|
a {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
}",
|
||||||
|
"@media screen and (:) {\n a {\n color: red;\n }\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user