From da9c0b78b28e6a3dca8a7cecfe07791942938717 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Thu, 30 Jul 2020 22:26:24 -0400 Subject: [PATCH] variables declared in mixins can be accessed after `@content` --- src/parse/mixin.rs | 7 ++++--- src/scope.rs | 2 +- tests/mixins.rs | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/parse/mixin.rs b/src/parse/mixin.rs index 1e3466c..84830d1 100644 --- a/src/parse/mixin.rs +++ b/src/parse/mixin.rs @@ -190,7 +190,7 @@ impl<'a> Parser<'a> { } } - Ok(if let Some(content) = &self.content.pop() { + Ok(if let Some(content) = self.content.pop() { let stmts = if let Some(body) = content.content.clone() { Parser { toks: &mut body.into_iter().peekmore(), @@ -212,8 +212,9 @@ impl<'a> Parser<'a> { } else { Vec::new() }; - self.content.push(content.clone()); - self.scopes.exit_scope(); + + self.content.push(content); + stmts } else { Vec::new() diff --git a/src/scope.rs b/src/scope.rs index 484b1aa..25b84ef 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -105,7 +105,7 @@ impl Scopes { if let Some(scope) = self.0.last_mut() { scope.merge(other) } else { - panic!() + self.0.push(other) } } } diff --git a/tests/mixins.rs b/tests/mixins.rs index 5d58f6a..79cbb5c 100644 --- a/tests/mixins.rs +++ b/tests/mixins.rs @@ -449,6 +449,22 @@ test!( }", "a {\n color: foo;\n color: foo;\n}\n" ); +test!( + can_access_variables_declared_before_content, + "@mixin foo { + $a: red; + + @content; + + color: $a; + } + + + a { + @include foo; + }", + "a {\n color: red;\n}\n" +); error!( mixin_in_function, "@function foo() {