!global variables are also in local scope

This commit is contained in:
ConnorSkees 2020-03-24 00:43:09 -04:00
parent 0979f3957b
commit 3afe88e2d6
2 changed files with 8 additions and 2 deletions

View File

@ -590,8 +590,9 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
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 {

View File

@ -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"
);