properly handle hash in string
This commit is contained in:
parent
31ec0cc7f8
commit
7164728c69
49
src/utils.rs
49
src/utils.rs
@ -56,49 +56,17 @@ pub(crate) fn devour_whitespace_or_comment<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_interpolation<I: Iterator<Item = Token>>(
|
pub(crate) fn parse_interpolation<I: Iterator<Item = Token>>(
|
||||||
tokens: &mut Peekable<I>,
|
toks: &mut Peekable<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Value> {
|
) -> SassResult<Value> {
|
||||||
let mut val = String::new();
|
let val = Value::from_tokens(
|
||||||
while let Some(tok) = tokens.next() {
|
&mut read_until_closing_curly_brace(toks).into_iter().peekable(),
|
||||||
match tok.kind {
|
scope,
|
||||||
'}' => break,
|
super_selector,
|
||||||
'{' => todo!("invalid character in interpolation"),
|
)?;
|
||||||
q @ '"' | q @ '\'' => {
|
toks.next();
|
||||||
val.push_str(&parse_quoted_string(tokens, scope, q, super_selector)?.to_string())
|
Ok(val.eval()?.unquote())
|
||||||
}
|
|
||||||
'$' => val.push_str(
|
|
||||||
&scope
|
|
||||||
.get_var(&eat_ident(tokens, scope, super_selector)?)?
|
|
||||||
.clone()
|
|
||||||
.unquote()
|
|
||||||
.to_string(),
|
|
||||||
),
|
|
||||||
'#' => {
|
|
||||||
if tokens.next().unwrap().kind == '{' {
|
|
||||||
val.push_str(
|
|
||||||
&Lexer::new(
|
|
||||||
&parse_interpolation(tokens, scope, super_selector)?.to_string(),
|
|
||||||
)
|
|
||||||
.map(|x| x.kind.to_string())
|
|
||||||
.collect::<String>(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return Err("Expected identifier.".into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => val.push_str(&tok.kind.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if val.trim().is_empty() {
|
|
||||||
return Ok(Value::Ident(String::new(), QuoteKind::None));
|
|
||||||
}
|
|
||||||
Ok(
|
|
||||||
Value::from_tokens(&mut Lexer::new(&val).peekable(), scope, super_selector)?
|
|
||||||
.eval()?
|
|
||||||
.unquote(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct VariableDecl {
|
pub(crate) struct VariableDecl {
|
||||||
@ -598,6 +566,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
s.push('#');
|
s.push('#');
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'\n' => return Err("Expected \".".into()),
|
'\n' => return Err("Expected \".".into()),
|
||||||
|
@ -310,3 +310,8 @@ test!(
|
|||||||
"$zzz: zzz;\n##{$zzz} {\n a: b;\n}\n",
|
"$zzz: zzz;\n##{$zzz} {\n a: b;\n}\n",
|
||||||
"#zzz {\n a: b;\n}\n"
|
"#zzz {\n a: b;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
interpolate_id_selector,
|
||||||
|
"$bar: \"#foo\";\nul li#{$bar} {\n foo: bar;\n}\n",
|
||||||
|
"ul li#foo {\n foo: bar;\n}\n"
|
||||||
|
);
|
||||||
|
@ -230,3 +230,4 @@ test!(
|
|||||||
"a {\n color: str-insert($string: \"foo\", $insert: \"X\", $index: -99999999999999999999);\n}\n",
|
"a {\n color: str-insert($string: \"foo\", $insert: \"X\", $index: -99999999999999999999);\n}\n",
|
||||||
"a {\n color: \"Xfoo\";\n}\n"
|
"a {\n color: \"Xfoo\";\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(hash_in_string, "a {\n color: \"#foo\";\n}\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user