From abdfa1b87644f5c0859d4cc9806bff99d21a17f0 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 18 Jan 2020 09:42:25 -0500 Subject: [PATCH] Handle interpolation in mixins --- src/main.rs | 15 ++++++++++++++- src/utils.rs | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7d72e61..86b754a 100644 --- a/src/main.rs +++ b/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>( 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" + ); } diff --git a/src/utils.rs b/src/utils.rs index cbb93c6..8464fdd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -18,6 +18,7 @@ pub fn devour_whitespace, W: IsWhitespace>(s: &mut Peekabl found_whitespace } +#[track_caller] pub fn deref_variable(name: &str, scope: &Scope) -> Vec { let mut toks = scope .vars @@ -67,6 +68,7 @@ pub fn eat_variable_value>( scope: &Scope, ) -> Result, (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 {