Skip to content

Commit 3b2cbf7

Browse files
committed
Treat 0 as correct CSS length
`(min-width: 0)` is parsed and picked up correctly, but was inspected as a invalid CSS length whereas 0 is a valid CSS length. MQPacker should special-case `0` (only `0`). This fixed hail2u#57.
1 parent bb449f0 commit 3b2cbf7

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ function parseQueryList(queryList) {
5656
}
5757

5858
function inspectLength(length) {
59+
if (length === "0") {
60+
return 0;
61+
}
62+
5963
length = /(-?\d*\.?\d+)(ch|em|ex|px|rem)/.exec(length);
6064

6165
if (!length) {

test/expected/sort_zero.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.foo {
2+
z-index: 0;
3+
}
4+
5+
@media (min-width: 0) {
6+
.foo {
7+
z-index: 1;
8+
}
9+
}
10+
11+
@media (min-width: 9px) {
12+
.foo {
13+
z-index: 2;
14+
}
15+
}
16+
17+
@media (min-width: 99px) {
18+
.foo {
19+
z-index: 3;
20+
}
21+
}

test/fixtures/sort_zero.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.foo {
2+
z-index: 0;
3+
}
4+
5+
@media (min-width: 99px) {
6+
.foo {
7+
z-index: 3;
8+
}
9+
}
10+
11+
@media (min-width: 0) {
12+
.foo {
13+
z-index: 1;
14+
}
15+
}
16+
17+
@media (min-width: 9px) {
18+
.foo {
19+
z-index: 2;
20+
}
21+
}

0 commit comments

Comments
 (0)