Skip to content

Commit 0f366ba

Browse files
committed
Merge pull request leafo#69 from robocoder/issue-68
@if and @while directives should treat null condition like false
2 parents fe43a95 + f8fca9c commit 0f366ba

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

scss.inc.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class scssc {
5454

5555
static public $true = array("keyword", "true");
5656
static public $false = array("keyword", "false");
57+
static public $null = array("null");
5758

5859
static public $defaultValue = array("keyword", "");
5960
static public $selfSelector = array("self");
@@ -575,12 +576,12 @@ protected function compileChild($child, $out) {
575576
break;
576577
case "if":
577578
list(, $if) = $child;
578-
if ($this->reduce($if->cond, true) != self::$false) {
579+
if (($cond = $this->reduce($if->cond, true)) != self::$false && $cond != self::$null) {
579580
return $this->compileChildren($if->children, $out);
580581
} else {
581582
foreach ($if->cases as $case) {
582583
if ($case->type == "else" ||
583-
$case->type == "elseif" && ($this->reduce($case->cond) != self::$false))
584+
$case->type == "elseif" && (($cond = $this->reduce($case->cond)) != self::$false) && $cond != self::$null)
584585
{
585586
return $this->compileChildren($case->children, $out);
586587
}
@@ -602,7 +603,7 @@ protected function compileChild($child, $out) {
602603
break;
603604
case "while":
604605
list(,$while) = $child;
605-
while ($this->reduce($while->cond, true) != self::$false) {
606+
while (($cond = $this->reduce($while->cond, true)) != self::$false && $cond != self::$null) {
606607
$ret = $this->compileChildren($while->children, $out);
607608
if ($ret) return $ret;
608609
}

tests/inputs/if.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ div {
1616
pre {
1717
val-1: conds(true);
1818
val-2: conds(false);
19+
val-3: conds(null);
20+
val-4: conds(1);
21+
val-5: conds(0);
1922
}
2023

2124

tests/inputs/looping.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ pre {
4444

4545
}
4646

47+
$j: null;
48+
@while $j {
49+
.item { width: 2em; }
50+
$j: false;
51+
}

tests/outputs/if.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ div {
33

44
pre {
55
val-1: "red";
6-
val-2: "blue"; }
6+
val-2: "blue";
7+
val-3: "blue";
8+
val-4: "red";
9+
val-5: "red"; }
710

811
span {
912
color: blue;

0 commit comments

Comments
 (0)