properly handle silent comments in styles

This commit is contained in:
ConnorSkees 2020-03-30 02:21:41 -04:00
parent ae0ce9894c
commit 57a704172f
5 changed files with 43 additions and 9 deletions

View File

@ -96,8 +96,8 @@ use crate::selector::Selector;
use crate::style::Style;
pub(crate) use crate::token::Token;
use crate::utils::{
devour_whitespace, eat_comment, eat_ident, eat_variable_value, parse_quoted_string,
read_until_newline, VariableDecl, eat_ident_no_interpolation
devour_whitespace, eat_comment, eat_ident, eat_ident_no_interpolation, eat_variable_value,
parse_quoted_string, read_until_newline, VariableDecl,
};
use crate::value::Value;

View File

@ -5,7 +5,8 @@ use crate::error::SassResult;
use crate::scope::Scope;
use crate::selector::Selector;
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::{Expr, Token};
@ -192,10 +193,10 @@ impl<'a> StyleParser<'a> {
) -> SassResult<String> {
devour_whitespace(toks);
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 == ':' {
toks.next();
devour_whitespace(toks);
devour_whitespace_or_comment(toks)?;
}
if super_property.is_empty() {

View File

@ -129,11 +129,20 @@ pub(crate) fn read_until_open_curly_brace<I: Iterator<Item = Token>>(
match tok.kind {
'{' => 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 {
break;
}
val.push(toks.next().unwrap());
}
val
@ -162,6 +171,14 @@ pub(crate) fn read_until_closing_curly_brace<I: Iterator<Item = Token>>(
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()),
}
}
@ -245,6 +262,14 @@ pub(crate) fn read_until_semicolon_or_closing_curly_brace<I: Iterator<Item = Tok
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()),
}
}
@ -296,6 +321,14 @@ pub(crate) fn read_until_semicolon_or_open_or_closing_curly_brace<I: Iterator<It
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()),
}
}

View File

@ -14,8 +14,8 @@ use crate::scope::Scope;
use crate::selector::Selector;
use crate::unit::Unit;
use crate::utils::{
devour_whitespace, eat_comment, eat_ident, eat_number, parse_interpolation,
parse_quoted_string, read_until_newline, eat_ident_no_interpolation
devour_whitespace, eat_comment, eat_ident, eat_ident_no_interpolation, eat_number,
parse_interpolation, parse_quoted_string, read_until_newline,
};
use crate::value::Value;
use crate::Token;

View File

@ -50,6 +50,6 @@ test!(
);
test!(
converts_cr_in_comment,
"a {\n /* \r*/ color: red;\n}\n",
"a {\n /* \n*/\n color: red;\n}\n"
"a {\n color: 1 + // flang }\n blang }",
"a {\n color: 1blang;\n}\n"
);