Skip to content

Commit da51403

Browse files
fix(issue#4356): parenthesis in media query (#4427)
* Fix issue #4356 issue with parenthesis in media query. * Add tests for issue #4356. Co-authored-by: Matthew Dean <matthew-dean@users.noreply.github.com>
1 parent e3805d0 commit da51403

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

packages/less/lib/less/parser/parser.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
18911891
spacing = true;
18921892
}
18931893
} else if (parserInput.$char('(')) {
1894+
let closed = false;
18941895
p = this.property();
18951896
parserInput.save();
18961897
if (!p && syntaxOptions.queryInParens && parserInput.$re(/^[0-9a-z-]*\s*([<>]=|<=|>=|[<>]|=)/)) {
@@ -1904,9 +1905,20 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
19041905
}
19051906
} else {
19061907
parserInput.restore();
1908+
parserInput.save();
19071909
e = this.value();
1910+
if (e && parserInput.$char(')')) {
1911+
closed = true;
1912+
parserInput.forget();
1913+
} else {
1914+
parserInput.restore();
1915+
e = this.mediaFeature(syntaxOptions);
1916+
}
1917+
}
1918+
if (!closed && parserInput.$char(')')) {
1919+
closed = true;
19081920
}
1909-
if (parserInput.$char(')')) {
1921+
if (closed) {
19101922
if (p && !e) {
19111923
nodes.push(new (tree.Paren)(new (tree.QueryInParens)(p.op, p.lvalue, p.rvalue, rangeP ? rangeP.op : null, rangeP ? rangeP.rvalue : null, p._index)));
19121924
e = p;

packages/test-data/tests-unit/media/media.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,8 @@
274274
color: red;
275275
}
276276
}
277+
@media ((color) and (hover)), all {
278+
body {
279+
background: green;
280+
}
281+
}

packages/test-data/tests-unit/media/media.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,9 @@
302302
color: red;
303303
}
304304
}
305+
306+
@media ((color) and (hover)), all {
307+
body {
308+
background: green;
309+
}
310+
}

0 commit comments

Comments
 (0)