From 1270b5c5437559b07f9237aa11ee035c9a07d997 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 16 Jun 2016 21:28:23 +0300 Subject: [PATCH] Fix mixin and variable scopes (#440) --- src/Compiler.php | 10 ++++++++ tests/inputs/functions.scss | 38 ++++++++++++++++++++++++++++ tests/inputs/mixins.scss | 18 +++++++++++++ tests/outputs/functions.css | 4 +++ tests/outputs/mixins.css | 7 +++++ tests/outputs_numbered/functions.css | 4 +++ tests/outputs_numbered/mixins.css | 8 ++++++ 7 files changed, 89 insertions(+) diff --git a/src/Compiler.php b/src/Compiler.php index 6e5e45dc..96e71692 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -1696,6 +1696,9 @@ protected function compileChild($child, OutputBlock $out) $this->pushEnv(); $this->env->depth--; + $storeEnv = $this->storeEnv; + $this->storeEnv = $this->env; + if (isset($content)) { $content->scope = $callingScope; @@ -1710,6 +1713,8 @@ protected function compileChild($child, OutputBlock $out) $this->compileChildrenNoReturn($mixin->children, $out); + $this->storeEnv = $storeEnv; + $this->popEnv(); break; @@ -3346,6 +3351,9 @@ protected function callScssFunction($name, $argValues, &$returnValue) $this->pushEnv(); + $storeEnv = $this->storeEnv; + $this->storeEnv = $this->env; + // set the args if (isset($func->args)) { $this->applyArguments($func->args, $argValues); @@ -3360,6 +3368,8 @@ protected function callScssFunction($name, $argValues, &$returnValue) $ret = $this->compileChildren($func->children, $tmp); + $this->storeEnv = $storeEnv; + $this->popEnv(); $returnValue = ! isset($ret) ? self::$defaultValue : $ret; diff --git a/tests/inputs/functions.scss b/tests/inputs/functions.scss index bcceaffd..bf3edf1f 100644 --- a/tests/inputs/functions.scss +++ b/tests/inputs/functions.scss @@ -128,3 +128,41 @@ $str: 'global'; l4: inspect((a: 1, b: 2)); l5: inspect($value: (a: 1, b: 2)); } + +@function contains($list, $values...) { + @each $value in $values { + @if type-of(index($list, $value)) != "number" { + @return false; + } + } + + @return true; +} + +@function mapping($items) { + $src: (); + $map: ( + one: 1px 1px, + two: 2px 2px, + ); + + @each $key, $values in $map { + @if contains($items, $key) { + $value1: nth($values, 1); + $value2: nth($values, 2); + + $src: append($src, $value1 $value2, space); + } + } + + @return $src; +} + +@mixin test() { + padding: mapping(one two); +} + +div { + margin: mapping(one two); + @include test(); +} \ No newline at end of file diff --git a/tests/inputs/mixins.scss b/tests/inputs/mixins.scss index 63f9007b..02ed81d0 100644 --- a/tests/inputs/mixins.scss +++ b/tests/inputs/mixins.scss @@ -190,3 +190,21 @@ div.parameter-name-scope { .test{ @include test-mixin(); } + +@mixin inner($value) {} + +@mixin outer($value) { + #{$value} { + content: "#{$value}"; + @content; + content: "#{$value}"; + } +} + +@include outer(div) { + @include inner('break'); + @include outer(p) { + @include inner('break'); + } +} + diff --git a/tests/outputs/functions.css b/tests/outputs/functions.css index 252e3909..aa0bebbb 100644 --- a/tests/outputs/functions.css +++ b/tests/outputs/functions.css @@ -45,3 +45,7 @@ p { l3: 5, 6; l4: (a: 1, b: 2); l5: (a: 1, b: 2); } + +div { + margin: 1px 1px 2px 2px; + padding: 1px 1px 2px 2px; } diff --git a/tests/outputs/mixins.css b/tests/outputs/mixins.css index e2004a07..ee692574 100644 --- a/tests/outputs/mixins.css +++ b/tests/outputs/mixins.css @@ -95,3 +95,10 @@ div.parameter-name-scope { @media screen and (min-width:0\0) { .test { color: #000; } } + +div { + content: "div"; + content: "div"; } + div p { + content: "p"; + content: "p"; } diff --git a/tests/outputs_numbered/functions.css b/tests/outputs_numbered/functions.css index 9b525e8d..6583ff05 100644 --- a/tests/outputs_numbered/functions.css +++ b/tests/outputs_numbered/functions.css @@ -47,3 +47,7 @@ p { l3: 5, 6; l4: (a: 1, b: 2); l5: (a: 1, b: 2); } +/* line 165, inputs/functions.scss */ +div { + margin: 1px 1px 2px 2px; + padding: 1px 1px 2px 2px; } diff --git a/tests/outputs_numbered/mixins.css b/tests/outputs_numbered/mixins.css index 2df05142..ed1f4ffb 100644 --- a/tests/outputs_numbered/mixins.css +++ b/tests/outputs_numbered/mixins.css @@ -108,3 +108,11 @@ div.parameter-name-scope { @media screen and (min-width:0\0) { .test { color: #000; } } +/* line 197, inputs/mixins.scss */ +div { + content: "div"; + content: "div"; } +/* line 197, inputs/mixins.scss */ +div p { + content: "p"; + content: "p"; }