Skip to content

Commit 18cd933

Browse files
committed
fix types for number operators leafo#195 leafo#143 thanks @andrewtch
1 parent 7140eee commit 18cd933

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

lessc.inc.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,11 +1958,8 @@ function op_color_color($op, $left, $right) {
19581958

19591959
// operator on two numbers
19601960
function op_number_number($op, $left, $right) {
1961-
if ($right[0] == '%') $right[1] /= 100;
1962-
1963-
// figure out type
1964-
if ($right[0] == 'number' || $right[0] == '%') $type = $left[0];
1965-
else $type = $right[0];
1961+
$type = is_null($left) ? "number" : $left[0];
1962+
if ($type == "number") $type = $right[0];
19661963

19671964
$value = 0;
19681965
switch ($op) {

tests/inputs/math.less

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,23 @@
9494
margin: 4 * (5 + 5) / 2 - (@var * 2);
9595
}
9696

97+
.percents {
98+
color: 100 * 10%;
99+
color: 10% * 100;
100+
color: 10% * 10%;
101+
102+
color: 100px * 10%; // lessjs makes this px
103+
color: 10% * 100px; // lessjs makes this %
104+
105+
color: 20% + 10%;
106+
color: 20% - 10%;
107+
108+
color: 20% / 10%;
109+
}
110+
111+
.misc {
112+
x: 10px * 4em;
113+
y: 10 * 4em;
114+
115+
}
116+

tests/outputs/math.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@
4444
width:96;
4545
height:113;
4646
margin:12;
47+
}
48+
.percents {
49+
color:1000%;
50+
color:1000%;
51+
color:100%;
52+
color:1000px;
53+
color:1000%;
54+
color:30%;
55+
color:10%;
56+
color:2%;
57+
}
58+
.misc {
59+
x:40px;
60+
y:40em;
4761
}

0 commit comments

Comments
 (0)