From 3afe88e2d63380f3d9cf96308e445b09f1647348 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 24 Mar 2020 00:43:09 -0400 Subject: [PATCH] !global variables are also in local scope --- src/lib.rs | 5 +++-- tests/scope.rs | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 80034f5..658f438 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -590,8 +590,9 @@ pub(crate) fn eat_expr>( global, } = eat_variable_value(toks, scope, super_selector)?; if global { - insert_global_var(&name, val)?; - } else if !default || scope.get_var(&name).is_err() { + insert_global_var(&name, val.clone())?; + } + if !default || scope.get_var(&name).is_err() { return Ok(Some(Expr::VariableDecl(name, Box::new(val)))); } } else { diff --git a/tests/scope.rs b/tests/scope.rs index ba1f8fc..98d14a9 100644 --- a/tests/scope.rs +++ b/tests/scope.rs @@ -13,3 +13,8 @@ test!( "a {\n $color: red !global;\n}\n\nb {\n color: $color;\n}\n", "b {\n color: red;\n}\n" ); +test!( + global_inserted_into_local_and_global_scopes, + "$foo: 42;\n\n.foo {\n content: $foo;\n $foo: 1337 !global;\n content: $foo;\n}\n\n.bar {\n content: $foo;\n}\n", + ".foo {\n content: 42;\n content: 1337;\n}\n\n.bar {\n content: 1337;\n}\n" +);