properly handle silent comments in styles
This commit is contained in:
parent
ae0ce9894c
commit
57a704172f
@ -96,8 +96,8 @@ use crate::selector::Selector;
|
|||||||
use crate::style::Style;
|
use crate::style::Style;
|
||||||
pub(crate) use crate::token::Token;
|
pub(crate) use crate::token::Token;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
devour_whitespace, eat_comment, eat_ident, eat_variable_value, parse_quoted_string,
|
devour_whitespace, eat_comment, eat_ident, eat_ident_no_interpolation, eat_variable_value,
|
||||||
read_until_newline, VariableDecl, eat_ident_no_interpolation
|
parse_quoted_string, read_until_newline, VariableDecl,
|
||||||
};
|
};
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@ use crate::error::SassResult;
|
|||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
devour_whitespace, eat_ident, read_until_semicolon_or_open_or_closing_curly_brace,
|
devour_whitespace, devour_whitespace_or_comment, eat_ident,
|
||||||
|
read_until_semicolon_or_open_or_closing_curly_brace,
|
||||||
};
|
};
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::{Expr, Token};
|
use crate::{Expr, Token};
|
||||||
@ -192,10 +193,10 @@ impl<'a> StyleParser<'a> {
|
|||||||
) -> SassResult<String> {
|
) -> SassResult<String> {
|
||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
let property = eat_ident(toks, &self.scope, &self.super_selector)?;
|
let property = eat_ident(toks, &self.scope, &self.super_selector)?;
|
||||||
devour_whitespace(toks);
|
devour_whitespace_or_comment(toks)?;
|
||||||
if toks.peek().is_some() && toks.peek().unwrap().kind == ':' {
|
if toks.peek().is_some() && toks.peek().unwrap().kind == ':' {
|
||||||
toks.next();
|
toks.next();
|
||||||
devour_whitespace(toks);
|
devour_whitespace_or_comment(toks)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if super_property.is_empty() {
|
if super_property.is_empty() {
|
||||||
|
33
src/utils.rs
33
src/utils.rs
@ -129,11 +129,20 @@ pub(crate) fn read_until_open_curly_brace<I: Iterator<Item = Token>>(
|
|||||||
match tok.kind {
|
match tok.kind {
|
||||||
'{' => n += 1,
|
'{' => n += 1,
|
||||||
'}' => n -= 1,
|
'}' => n -= 1,
|
||||||
|
'/' => {
|
||||||
|
let next = toks.next().unwrap();
|
||||||
|
match toks.peek().unwrap().kind {
|
||||||
|
'/' => read_until_newline(toks),
|
||||||
|
_ => val.push(next),
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
val.push(toks.next().unwrap());
|
val.push(toks.next().unwrap());
|
||||||
}
|
}
|
||||||
val
|
val
|
||||||
@ -162,6 +171,14 @@ pub(crate) fn read_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
|||||||
t.push(toks.next().unwrap());
|
t.push(toks.next().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
'/' => {
|
||||||
|
let next = toks.next().unwrap();
|
||||||
|
match toks.peek().unwrap().kind {
|
||||||
|
'/' => read_until_newline(toks),
|
||||||
|
_ => t.push(next),
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ => t.push(toks.next().unwrap()),
|
_ => t.push(toks.next().unwrap()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,6 +262,14 @@ pub(crate) fn read_until_semicolon_or_closing_curly_brace<I: Iterator<Item = Tok
|
|||||||
t.push(toks.next().unwrap());
|
t.push(toks.next().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
'/' => {
|
||||||
|
let next = toks.next().unwrap();
|
||||||
|
match toks.peek().unwrap().kind {
|
||||||
|
'/' => read_until_newline(toks),
|
||||||
|
_ => t.push(next),
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ => t.push(toks.next().unwrap()),
|
_ => t.push(toks.next().unwrap()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,6 +321,14 @@ pub(crate) fn read_until_semicolon_or_open_or_closing_curly_brace<I: Iterator<It
|
|||||||
t.push(toks.next().unwrap());
|
t.push(toks.next().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
'/' => {
|
||||||
|
let next = toks.next().unwrap();
|
||||||
|
match toks.peek().unwrap().kind {
|
||||||
|
'/' => read_until_newline(toks),
|
||||||
|
_ => t.push(next),
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ => t.push(toks.next().unwrap()),
|
_ => t.push(toks.next().unwrap()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ use crate::scope::Scope;
|
|||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
devour_whitespace, eat_comment, eat_ident, eat_number, parse_interpolation,
|
devour_whitespace, eat_comment, eat_ident, eat_ident_no_interpolation, eat_number,
|
||||||
parse_quoted_string, read_until_newline, eat_ident_no_interpolation
|
parse_interpolation, parse_quoted_string, read_until_newline,
|
||||||
};
|
};
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::Token;
|
use crate::Token;
|
||||||
|
@ -50,6 +50,6 @@ test!(
|
|||||||
);
|
);
|
||||||
test!(
|
test!(
|
||||||
converts_cr_in_comment,
|
converts_cr_in_comment,
|
||||||
"a {\n /* \r*/ color: red;\n}\n",
|
"a {\n color: 1 + // flang }\n blang }",
|
||||||
"a {\n /* \n*/\n color: red;\n}\n"
|
"a {\n color: 1blang;\n}\n"
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user