Handle interpolation in mixins
This commit is contained in:
parent
ab8e98244f
commit
abdfa1b876
15
src/main.rs
15
src/main.rs
@ -24,6 +24,7 @@
|
||||
clippy::let_underscore_must_use,
|
||||
clippy::module_name_repetitions
|
||||
)]
|
||||
#![feature(track_caller)]
|
||||
// todo! handle erroring on styles at the toplevel
|
||||
use std::fmt::{self, Display};
|
||||
use std::fs;
|
||||
@ -426,7 +427,9 @@ fn parse_mixin<I: Iterator<Item = Token>>(
|
||||
while nesting > 0 {
|
||||
if let Some(tok) = toks.next() {
|
||||
match &tok.kind {
|
||||
TokenKind::Symbol(Symbol::OpenCurlyBrace) => nesting += 1,
|
||||
TokenKind::Symbol(Symbol::OpenCurlyBrace)
|
||||
// interpolation token eats the opening brace but not the closing
|
||||
| TokenKind::Interpolation => nesting += 1,
|
||||
TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1,
|
||||
_ => {}
|
||||
}
|
||||
@ -1136,4 +1139,14 @@ mod css_mixins {
|
||||
"@mixin a($b, $c,) {\n color: $b;\n color: $c\n}\nd {\n @include a(red, blue);\n}\n",
|
||||
"d {\n color: red;\n color: blue;\n}\n"
|
||||
);
|
||||
test!(
|
||||
mixin_property_interpolation,
|
||||
"@mixin a($b) {\n #{$b}: red;\n}\nd {\n @include a(color);\n}\n",
|
||||
"d {\n color: red;\n}\n"
|
||||
);
|
||||
test!(
|
||||
mixin_style_interpolation,
|
||||
"@mixin a($b) {\n color: #{$b};\n}\nd {\n @include a(red);\n}\n",
|
||||
"d {\n color: red;\n}\n"
|
||||
);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ pub fn devour_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(s: &mut Peekabl
|
||||
found_whitespace
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn deref_variable(name: &str, scope: &Scope) -> Vec<Token> {
|
||||
let mut toks = scope
|
||||
.vars
|
||||
@ -67,6 +68,7 @@ pub fn eat_variable_value<I: Iterator<Item = Token>>(
|
||||
scope: &Scope,
|
||||
) -> Result<Vec<Token>, (Pos, &'static str)> {
|
||||
devour_whitespace(toks);
|
||||
// todo!(line might not end with semicolon)
|
||||
let iter1 = toks.take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon));
|
||||
let mut iter2 = Vec::new();
|
||||
for tok in iter1 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user