more robustly parse @else if
This commit is contained in:
parent
b4c346f51f
commit
26ec16a802
@ -69,13 +69,16 @@ impl<'a> Parser<'a> {
|
||||
self.whitespace_or_comment();
|
||||
if let Some(tok) = self.toks.peek() {
|
||||
match tok.kind {
|
||||
'i' if matches!(
|
||||
self.toks.peek_forward(1),
|
||||
Some(Token { kind: 'f', .. }) | Some(Token { kind: 'F', .. })
|
||||
) =>
|
||||
{
|
||||
self.toks.next();
|
||||
self.toks.next();
|
||||
'i' | 'I' | '\\' => {
|
||||
self.span_before = tok.pos;
|
||||
let mut ident = self.parse_identifier_no_interpolation(false)?;
|
||||
|
||||
ident.node.make_ascii_lowercase();
|
||||
|
||||
if ident.node != "if" {
|
||||
return Err(("expected \"{\".", ident.span).into());
|
||||
}
|
||||
|
||||
let cond = if found_true {
|
||||
self.throw_away_until_open_curly_brace()?;
|
||||
false
|
||||
@ -84,6 +87,7 @@ impl<'a> Parser<'a> {
|
||||
self.expect_char('{')?;
|
||||
v
|
||||
};
|
||||
|
||||
if cond {
|
||||
found_true = true;
|
||||
self.scopes.enter_new_scope();
|
||||
|
@ -18,11 +18,9 @@ test!(
|
||||
);
|
||||
error!(
|
||||
invalid_charset_value,
|
||||
"@charset 1;",
|
||||
"Error: Expected string."
|
||||
"@charset 1;", "Error: Expected string."
|
||||
);
|
||||
error!(
|
||||
invalid_charset_value_unquoted_string,
|
||||
"@charset a;",
|
||||
"Error: Expected string."
|
||||
"@charset a;", "Error: Expected string."
|
||||
);
|
||||
|
24
tests/if.rs
24
tests/if.rs
@ -236,3 +236,27 @@ error!(
|
||||
denies_interpolated_at_rule,
|
||||
"@#{if} true { a { color: red; } }", "Error: expected \"(\"."
|
||||
);
|
||||
test!(
|
||||
else_if_escaped_lower_i,
|
||||
r"@if false {
|
||||
} @else \69 f true {
|
||||
/**/
|
||||
}",
|
||||
"/**/\n"
|
||||
);
|
||||
test!(
|
||||
else_if_escaped_lower_both,
|
||||
r"@if false {
|
||||
} @else \69 \66 true {
|
||||
/**/
|
||||
}",
|
||||
"/**/\n"
|
||||
);
|
||||
test!(
|
||||
else_if_uppercase,
|
||||
r"@if false {
|
||||
} @else IF true {
|
||||
/**/
|
||||
}",
|
||||
"/**/\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user