This commit is contained in:
ConnorSkees 2020-03-30 17:06:23 -04:00
parent e4843180c7
commit beff60ad31
11 changed files with 22 additions and 27 deletions

View File

@ -69,19 +69,18 @@ impl Function {
match stmt {
Stmt::AtRule(AtRule::Return(toks)) => {
return Value::from_tokens(
&mut toks.clone().into_iter().peekable(),
&mut toks.into_iter().peekable(),
&self.scope,
super_selector,
)
}
Stmt::AtRule(AtRule::For(..)) => todo!("@for in function"),
Stmt::AtRule(AtRule::If(i)) => {
match self.call(
if let Ok(v) = self.call(
super_selector,
i.eval(&mut self.scope.clone(), super_selector)?,
) {
Ok(v) => return Ok(v),
Err(..) => {}
return Ok(v);
}
}
_ => return Err("This at-rule is not allowed here.".into()),

View File

@ -132,7 +132,7 @@ impl AtRule {
'h' => {
let r = toks.next().unwrap();
these_toks.push(r);
if &r.kind != &'r' {
if r.kind != 'r' {
from_toks.extend(these_toks);
continue;
}

View File

@ -15,7 +15,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
Value::List(v, ..) if v.is_empty() => SassMap::new(),
v => return Err(format!("$map: {} is not a map.", v).into()),
};
Ok(map.get(key)?.unwrap_or(Value::Null).clone())
Ok(map.get(&key)?.unwrap_or(Value::Null))
}),
);
f.insert(
@ -28,7 +28,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
Value::List(v, ..) if v.is_empty() => SassMap::new(),
v => return Err(format!("$map: {} is not a map.", v).into()),
};
Ok(Value::bool(map.get(key)?.is_some()))
Ok(Value::bool(map.get(&key)?.is_some()))
}),
);
f.insert(

View File

@ -201,7 +201,7 @@ impl<'a> SelectorParser<'a> {
let s = format!(
"{}{}",
v,
eat_ident(tokens, &self.scope, &self.super_selector)?
eat_ident(tokens, self.scope, self.super_selector)?
);
if let Some(Token { kind: '(', .. }) = tokens.peek() {
tokens.next();
@ -225,7 +225,7 @@ impl<'a> SelectorParser<'a> {
}
}
':' => {
let s = eat_ident(tokens, &self.scope, &self.super_selector)?;
let s = eat_ident(tokens, self.scope, self.super_selector)?;
self.selectors.push(SelectorKind::PseudoElement(s))
}
_ => return Err("Expected identifier.".into()),

View File

@ -192,7 +192,7 @@ impl<'a> StyleParser<'a> {
mut super_property: String,
) -> SassResult<String> {
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_or_comment(toks)?;
if toks.peek().is_some() && toks.peek().unwrap().kind == ':' {
toks.next();

View File

@ -515,7 +515,7 @@ pub(crate) fn eat_number<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) -> S
///
/// The newline is consumed
pub(crate) fn read_until_newline<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) {
while let Some(tok) = toks.next() {
for tok in toks {
if tok.kind == '\n' {
break;
}
@ -534,11 +534,9 @@ pub(crate) fn eat_comment<I: Iterator<Item = Token>>(
) -> SassResult<String> {
let mut comment = String::new();
while let Some(tok) = toks.next() {
if tok.kind == '*' {
if toks.peek().unwrap().kind == '/' {
toks.next();
break;
}
if tok.kind == '*' && toks.peek().unwrap().kind == '/' {
toks.next();
break;
}
comment.push(tok.kind);
}

View File

@ -8,11 +8,11 @@ use crate::error::SassResult;
pub(crate) struct SassMap(Vec<(Value, Value)>);
impl SassMap {
pub fn new() -> SassMap {
pub const fn new() -> SassMap {
SassMap(Vec::new())
}
pub fn get(self, key: Value) -> SassResult<Option<Value>> {
pub fn get(self, key: &Value) -> SassResult<Option<Value>> {
for (k, v) in self.0 {
if k.equals(key.clone())? {
return Ok(Some(v));
@ -31,7 +31,7 @@ impl SassMap {
}
pub fn merge(&mut self, other: SassMap) {
for (key, value) in other.into_iter() {
for (key, value) in other {
self.insert(key, value);
}
}

View File

@ -228,7 +228,7 @@ impl Value {
Ok(match self {
Self::Dimension(num, ref unit) => match other {
Self::Dimension(num2, unit2) => {
if !unit.comparable(&unit2) {
if !unit.comparable(unit2) {
return Err(format!("Incompatible units {} and {}.", unit2, unit).into());
}
if unit == unit2 {

View File

@ -170,7 +170,7 @@ impl Sub for Value {
format!("{}-{}{}{}", self, q.normalize(), s, q.normalize()),
QuoteKind::None,
),
Self::Paren(..) => (self + other.eval()?)?,
Self::Paren(..) => (self - other.eval()?)?,
_ => Value::Ident(format!("{}-{}", self, other), QuoteKind::None),
},
_ => match other {

View File

@ -186,7 +186,7 @@ impl Value {
let right = Self::from_tokens(toks, scope, super_selector)?;
Ok(Value::BinaryOp(Box::new(left), Op::Equal, Box::new(right)))
} else {
return Err("expected \"=\".".into());
Err("expected \"=\".".into())
}
}
q @ '>' | q @ '<' => {
@ -231,7 +231,7 @@ impl Value {
Brackets::None,
))
} else {
return Err("Expected \"important\".".into());
Err("Expected \"important\".".into())
}
}
'-' => {

View File

@ -113,11 +113,9 @@ test!(
);
error!(
map_get_one_arg,
"a {\n color: map-get(1);\n}\n",
"Error: Missing argument $key."
"a {\n color: map-get(1);\n}\n", "Error: Missing argument $key."
);
error!(
map_has_key_one_arg,
"a {\n color: map-has-key(1);\n}\n",
"Error: Missing argument $key."
"a {\n color: map-has-key(1);\n}\n", "Error: Missing argument $key."
);