From 7a4a191d59d5b37f67e54cf6ab76cf6342337786 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Fri, 7 Aug 2020 02:10:51 -0400 Subject: [PATCH] allow variable declarations before and between `@use` --- src/parse/module.rs | 1 + tests/use.rs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/parse/module.rs b/src/parse/module.rs index ab6924a..f6a056b 100644 --- a/src/parse/module.rs +++ b/src/parse/module.rs @@ -241,6 +241,7 @@ impl<'a> Parser<'a> { Comment::Loud(s) => comments.push(Stmt::Comment(s)), } } + Some(Token { kind: '$', .. }) => self.parse_variable_declaration()?, Some(..) | None => break, } } diff --git a/tests/use.rs b/tests/use.rs index 7c83b2e..0dca5c4 100644 --- a/tests/use.rs +++ b/tests/use.rs @@ -311,8 +311,23 @@ fn use_variable_redeclaration_private() { fn use_variable_redeclaration_builtin() { let input = "@use \"sass:math\";\nmath.$e: red;"; - assert_err!( - "Error: Cannot modify built-in variable.", - input + assert_err!("Error: Cannot modify built-in variable.", input); +} + +#[test] +fn use_variable_declaration_between_use() { + let input = r#" + $a: red; + $b: green; + @use "sass:math"; + $b: red; + @use "sass:meta"; + a { + color: $a $b; + }"#; + + assert_eq!( + "a {\n color: red red;\n}\n", + &grass::from_string(input.to_string(), &grass::Options::default()).expect(input) ); }