Prefer match
over if let
This commit is contained in:
parent
28050116d3
commit
6da84575dc
32
src/main.rs
32
src/main.rs
@ -379,13 +379,10 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => match self.lexer.next() {
|
||||||
if let Some(Token { pos, .. }) = self.lexer.next() {
|
Some(Token { pos, .. }) => self.error(pos, "unexpected toplevel token"),
|
||||||
self.error(pos, "unexpected toplevel token")
|
_ => unsafe { std::hint::unreachable_unchecked() },
|
||||||
} else {
|
},
|
||||||
unsafe { std::hint::unreachable_unchecked() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Ok((rules, self.global_scope))
|
Ok((rules, self.global_scope))
|
||||||
@ -401,15 +398,6 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
Expr::MixinDecl(name, mixin) => {
|
Expr::MixinDecl(name, mixin) => {
|
||||||
scope.mixins.insert(name, mixin);
|
scope.mixins.insert(name, mixin);
|
||||||
}
|
}
|
||||||
Expr::Include(rules) => {
|
|
||||||
stmts.extend(rules);
|
|
||||||
}
|
|
||||||
Expr::Debug(pos, ref message) => {
|
|
||||||
self.debug(pos, message);
|
|
||||||
}
|
|
||||||
Expr::Warn(pos, ref message) => {
|
|
||||||
self.warn(pos, message);
|
|
||||||
}
|
|
||||||
Expr::Selector(s) => {
|
Expr::Selector(s) => {
|
||||||
self.scope += 1;
|
self.scope += 1;
|
||||||
let rules = self.eat_rules(&super_selector.zip(&s), scope);
|
let rules = self.eat_rules(&super_selector.zip(&s), scope);
|
||||||
@ -431,6 +419,9 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
scope.vars.insert(name, val);
|
scope.vars.insert(name, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Expr::Include(rules) => stmts.extend(rules),
|
||||||
|
Expr::Debug(pos, ref message) => self.debug(pos, message),
|
||||||
|
Expr::Warn(pos, ref message) => self.warn(pos, message),
|
||||||
Expr::MultilineComment(s) => stmts.push(Stmt::MultilineComment(s)),
|
Expr::MultilineComment(s) => stmts.push(Stmt::MultilineComment(s)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -444,9 +435,9 @@ fn eat_at_rule<I: Iterator<Item = Token>>(
|
|||||||
toks: &mut Peekable<I>,
|
toks: &mut Peekable<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
) -> Result<Expr, Printer> {
|
) -> Result<Expr, Printer> {
|
||||||
|
devour_whitespace(toks);
|
||||||
match rule {
|
match rule {
|
||||||
AtRule::Error => {
|
AtRule::Error => {
|
||||||
devour_whitespace(toks);
|
|
||||||
let message = toks
|
let message = toks
|
||||||
.take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon))
|
.take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon))
|
||||||
.map(|x| x.kind.to_string())
|
.map(|x| x.kind.to_string())
|
||||||
@ -454,7 +445,6 @@ fn eat_at_rule<I: Iterator<Item = Token>>(
|
|||||||
Err(Printer::Error(pos, message))
|
Err(Printer::Error(pos, message))
|
||||||
}
|
}
|
||||||
AtRule::Warn => {
|
AtRule::Warn => {
|
||||||
devour_whitespace(toks);
|
|
||||||
let message = toks
|
let message = toks
|
||||||
.take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon))
|
.take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon))
|
||||||
.map(|x| x.kind.to_string())
|
.map(|x| x.kind.to_string())
|
||||||
@ -462,7 +452,6 @@ fn eat_at_rule<I: Iterator<Item = Token>>(
|
|||||||
Err(Printer::Warn(pos, message))
|
Err(Printer::Warn(pos, message))
|
||||||
}
|
}
|
||||||
AtRule::Debug => {
|
AtRule::Debug => {
|
||||||
devour_whitespace(toks);
|
|
||||||
let message = toks
|
let message = toks
|
||||||
.by_ref()
|
.by_ref()
|
||||||
.take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon))
|
.take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon))
|
||||||
@ -1145,6 +1134,11 @@ mod test_mixins {
|
|||||||
"@mixin a($b) {\n color: #{$b};\n}\nd {\n @include a(red);\n}\n",
|
"@mixin a($b) {\n color: #{$b};\n}\nd {\n @include a(red);\n}\n",
|
||||||
"d {\n color: red;\n}\n"
|
"d {\n color: red;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
mixin_default_value,
|
||||||
|
"@mixin a($b: red) {\n color: $b;\n}\nd {\n @include a;\n}\n",
|
||||||
|
"d {\n color: red;\n}\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user