diff --git a/src/Compiler.php b/src/Compiler.php index 16ed3bf8..f02a4b7e 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -1272,6 +1272,7 @@ protected function compileChild($child, $out) if (isset($content)) { $content->scope = $callingScope; + $this->setRaw(self::$namespaces['special'] . 'content', $content); } @@ -1279,6 +1280,8 @@ protected function compileChild($child, $out) $this->applyArguments($mixin->args, $argValues); } + $this->env->marker = 'mixin'; + foreach ($mixin->children as $child) { $this->compileChild($child, $out); } @@ -2433,11 +2436,18 @@ protected function setExisting($name, $value, $env = null) $storeEnv = $env; + $hasNamespace = $name[0] === '^' || $name[0] === '@' || $name[0] === '%'; + for (;;) { if (array_key_exists($name, $env->store)) { break; } + if (! $hasNamespace && isset($env->marker)) { + $env = $storeEnv; + break; + } + if (! isset($env->parent)) { $env = $storeEnv; break; @@ -2491,6 +2501,11 @@ public function get($name, $shouldThrow = true, $env = null) return $env->store[$name]; } + if (! $hasNamespace && isset($env->marker)) { + $env = $this->rootEnv; + continue; + } + if (! isset($env->parent)) { break; } @@ -2499,7 +2514,7 @@ public function get($name, $shouldThrow = true, $env = null) } if ($shouldThrow) { - $this->throwError('undefined variable $' . $name); + $this->throwError("Undefined variable \$$name"); } // found nothing diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php index 50255f40..12ec165f 100644 --- a/tests/ExceptionTest.php +++ b/tests/ExceptionTest.php @@ -103,6 +103,32 @@ public function provideScss() , 'expecting color' ), + array(<<<'END_OF_SCSS' +BODY { + DIV { + $bg: red; + } + + background: $bg; +} +END_OF_SCSS + , + 'Undefined variable $bg' + ), + array(<<<'END_OF_SCSS' +@mixin example { + background: $bg; +} + +P { + $bg: red; + + @include example; +} +END_OF_SCSS + , + 'Undefined variable $bg' + ), ); } diff --git a/tests/FailingTest.php b/tests/FailingTest.php index cf4677d3..f6ec0ffc 100644 --- a/tests/FailingTest.php +++ b/tests/FailingTest.php @@ -153,23 +153,6 @@ public function provideFailing() transform: scale(0.5); } to { transform: scale(1); } } -END_OF_EXPECTED - ), - array( - '#295 - variable scope bug', <<<'END_OF_SCSS' -@mixin example { - $color: red; -} - -A { - $color: green; - @include example; - color: $color; -} -END_OF_SCSS - , <<