simplify interpolated ident parsing by changing if stmt to match
This commit is contained in:
parent
c2384595e8
commit
20fc9e8e6b
@ -240,8 +240,6 @@ fn index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
|||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let list = args.get_err(0, "list")?.as_list();
|
let list = args.get_err(0, "list")?.as_list();
|
||||||
let value = args.get_err(1, "value")?;
|
let value = args.get_err(1, "value")?;
|
||||||
// TODO: find a way to propagate any errors here
|
|
||||||
// Potential input to fuzz: index(1px 1in 1cm, 96px + 1rem)
|
|
||||||
let index = match list.into_iter().position(|v| v == value) {
|
let index = match list.into_iter().position(|v| v == value) {
|
||||||
Some(v) => Number::from(v + 1),
|
Some(v) => Number::from(v + 1),
|
||||||
None => return Ok(Value::Null),
|
None => return Ok(Value::Null),
|
||||||
|
@ -161,31 +161,23 @@ impl<'a> Parser<'a> {
|
|||||||
None => return Err(("Expected identifier.", self.span_before).into()),
|
None => return Err(("Expected identifier.", self.span_before).into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_name_start(first) {
|
match first {
|
||||||
text.push(self.toks.next().unwrap().kind);
|
c if is_name_start(c) => {
|
||||||
} else if first == '\\' {
|
text.push(self.toks.next().unwrap().kind);
|
||||||
self.toks.next();
|
}
|
||||||
text.push_str(&self.escape(true)?);
|
'\\' => {
|
||||||
// TODO: peekmore
|
self.toks.next();
|
||||||
// (first == '#' && scanner.peekChar(1) == $lbrace)
|
text.push_str(&self.escape(true)?);
|
||||||
} else if first == '#' {
|
}
|
||||||
self.toks.next();
|
'#' if matches!(self.toks.peek_forward(1), Some(Token { kind: '{', .. })) => {
|
||||||
let Token { kind, pos } = if let Some(tok) = self.toks.peek() {
|
self.toks.next();
|
||||||
*tok
|
|
||||||
} else {
|
|
||||||
return Err(("Expected identifier.", pos).into());
|
|
||||||
};
|
|
||||||
if kind == '{' {
|
|
||||||
self.toks.next();
|
self.toks.next();
|
||||||
match self.parse_interpolation()?.node {
|
match self.parse_interpolation()?.node {
|
||||||
Value::String(ref s, ..) => text.push_str(s),
|
Value::String(ref s, ..) => text.push_str(s),
|
||||||
v => text.push_str(v.to_css_string(self.span_before)?.borrow()),
|
v => text.push_str(v.to_css_string(self.span_before)?.borrow()),
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err(("Expected identifier.", pos).into());
|
|
||||||
}
|
}
|
||||||
} else {
|
_ => return Err(("Expected identifier.", pos).into()),
|
||||||
return Err(("Expected identifier.", pos).into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.interpolated_ident_body(&mut text)?;
|
self.interpolated_ident_body(&mut text)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user