From f8fca9c156b08d88d00ffe2b2b252d298536efb5 Mon Sep 17 00:00:00 2001 From: Anthon Pang Date: Mon, 25 Mar 2013 18:21:01 -0400 Subject: [PATCH] @if and @while directives use the styles nested beneath if the expression returns anything other than false or null --- scss.inc.php | 7 ++++--- tests/inputs/if.scss | 3 +++ tests/inputs/looping.scss | 5 +++++ tests/outputs/if.css | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scss.inc.php b/scss.inc.php index 22ab58b4..20caaf92 100644 --- a/scss.inc.php +++ b/scss.inc.php @@ -54,6 +54,7 @@ class scssc { static public $true = array("keyword", "true"); static public $false = array("keyword", "false"); + static public $null = array("null"); static public $defaultValue = array("keyword", ""); static public $selfSelector = array("self"); @@ -575,12 +576,12 @@ protected function compileChild($child, $out) { break; case "if": list(, $if) = $child; - if ($this->reduce($if->cond, true) != self::$false) { + if (($cond = $this->reduce($if->cond, true)) != self::$false && $cond != self::$null) { return $this->compileChildren($if->children, $out); } else { foreach ($if->cases as $case) { if ($case->type == "else" || - $case->type == "elseif" && ($this->reduce($case->cond) != self::$false)) + $case->type == "elseif" && (($cond = $this->reduce($case->cond)) != self::$false) && $cond != self::$null) { return $this->compileChildren($case->children, $out); } @@ -602,7 +603,7 @@ protected function compileChild($child, $out) { break; case "while": list(,$while) = $child; - while ($this->reduce($while->cond, true) != self::$false) { + while (($cond = $this->reduce($while->cond, true)) != self::$false && $cond != self::$null) { $ret = $this->compileChildren($while->children, $out); if ($ret) return $ret; } diff --git a/tests/inputs/if.scss b/tests/inputs/if.scss index c8363e5a..3a7a816e 100644 --- a/tests/inputs/if.scss +++ b/tests/inputs/if.scss @@ -16,6 +16,9 @@ div { pre { val-1: conds(true); val-2: conds(false); + val-3: conds(null); + val-4: conds(1); + val-5: conds(0); } diff --git a/tests/inputs/looping.scss b/tests/inputs/looping.scss index 258cd361..6f25e722 100644 --- a/tests/inputs/looping.scss +++ b/tests/inputs/looping.scss @@ -44,3 +44,8 @@ pre { } +$j: null; +@while $j { + .item { width: 2em; } + $j: false; +} diff --git a/tests/outputs/if.css b/tests/outputs/if.css index 0d4e5d97..b2a90666 100644 --- a/tests/outputs/if.css +++ b/tests/outputs/if.css @@ -3,7 +3,10 @@ div { pre { val-1: "red"; - val-2: "blue"; } + val-2: "blue"; + val-3: "blue"; + val-4: "red"; + val-5: "red"; } span { color: blue;