Skip to content

Commit f12e4b7

Browse files
committed
Improve "and"/"or" compatibility with reference implementation
1 parent f8f3f4a commit f12e4b7

4 files changed

Lines changed: 69 additions & 4 deletions

File tree

src/Compiler.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,7 @@ protected function filterWithout($envs, $without)
11511151
$ec->block = null;
11521152
$ec->selectors = [];
11531153
$filtered[] = $ec;
1154-
}
1155-
else {
1154+
} else {
11561155
$filtered[] = $e;
11571156
}
11581157
}
@@ -2937,8 +2936,14 @@ protected function opAdd($left, $right)
29372936
*/
29382937
protected function opAnd($left, $right, $shouldEval)
29392938
{
2939+
$truthy = ($left === static::$null || $right === static::$null) ||
2940+
($left === static::$false || $left === static::$true) &&
2941+
($right === static::$false || $right === static::$true);
2942+
29402943
if (! $shouldEval) {
2941-
return null;
2944+
if (! $truthy) {
2945+
return null;
2946+
}
29422947
}
29432948

29442949
if ($left !== static::$false && $left !== static::$null) {
@@ -2959,8 +2964,14 @@ protected function opAnd($left, $right, $shouldEval)
29592964
*/
29602965
protected function opOr($left, $right, $shouldEval)
29612966
{
2967+
$truthy = ($left === static::$null || $right === static::$null) ||
2968+
($left === static::$false || $left === static::$true) &&
2969+
($right === static::$false || $right === static::$true);
2970+
29622971
if (! $shouldEval) {
2963-
return null;
2972+
if (! $truthy) {
2973+
return null;
2974+
}
29642975
}
29652976

29662977
if ($left !== static::$false && $left !== static::$null) {

tests/inputs/operators.scss

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,37 @@ $gridRowWidth: 20px;
191191
{
192192
width: (2.5 / $gridRowWidth * 100px * 1% );
193193
}
194+
195+
$and: true and false;
196+
$or: false or true;
197+
198+
$and1: null and true; // (null)
199+
$and2: true and null; // (null)
200+
$and3: null and false; // (null)
201+
$and4: false and null; // false
202+
$and5: one and null; // (null)
203+
$and6: null and one; // (null)
204+
205+
$or1: null or true; // true
206+
$or2: true or null; // true
207+
$or3: null or false; // false
208+
$or4: false or null; // (null)
209+
$or5: one or null; // one
210+
$or6: null or one; // one
211+
212+
#bools-test {
213+
a: $and;
214+
b: $or;
215+
c: $and1;
216+
d: $and2;
217+
e: $and3;
218+
f: $and4;
219+
g: $and5;
220+
h: $and6;
221+
n: $or1;
222+
o: $or2;
223+
p: $or3;
224+
q: $or4;
225+
r: $or5;
226+
s: $or6;
227+
}

tests/outputs/operators.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,13 @@ div {
173173

174174
.foo {
175175
width: 12.5%; }
176+
177+
#bools-test {
178+
a: false;
179+
b: true;
180+
f: false;
181+
n: true;
182+
o: true;
183+
p: false;
184+
r: one;
185+
s: one; }

tests/outputs_numbered/operators.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,13 @@ div {
174174
/* line 190, inputs/operators.scss */
175175
.foo {
176176
width: 12.5%; }
177+
/* line 212, inputs/operators.scss */
178+
#bools-test {
179+
a: false;
180+
b: true;
181+
f: false;
182+
n: true;
183+
o: true;
184+
p: false;
185+
r: one;
186+
s: one; }

0 commit comments

Comments
 (0)