Skip to content

Commit

Permalink
fix(issue:4268) nested pseudo-selector parsing (#4290)
Browse files Browse the repository at this point in the history
* Fix nested pseudo-selector parsing where selectors are separated by
  one or more commas.
  • Loading branch information
puckowski authored Dec 7, 2024
1 parent 773e157 commit e4198ba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
28 changes: 24 additions & 4 deletions packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import getParserInput from './parser-input';
import * as utils from '../utils';
import functionRegistry from '../functions/function-registry';
import { ContainerSyntaxOptions, MediaSyntaxOptions } from '../tree/atrule-syntax';
import Selector from '../tree/selector';
import Anonymous from '../tree/anonymous';

//
// less.js - parser
Expand Down Expand Up @@ -1312,9 +1314,25 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
if (!e) {
parserInput.save();
if (parserInput.$char('(')) {
if ((v = this.selector(false)) && parserInput.$char(')')) {
e = new(tree.Paren)(v);
parserInput.forget();
if ((v = this.selector(false))) {
let selectors = [];
while (parserInput.$char(',')) {
selectors.push(v);
selectors.push(new Anonymous(','));
v = this.selector(false);
}
selectors.push(v);

if (parserInput.$char(')')) {
if (selectors.length > 1) {
e = new (tree.Paren)(new Selector(selectors));
} else {
e = new(tree.Paren)(v);
}
parserInput.forget();
} else {
parserInput.restore('Missing closing \')\'');
}
} else {
parserInput.restore('Missing closing \')\'');
}
Expand Down Expand Up @@ -1395,7 +1413,9 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
} else {
if (allExtends) { error('Extend can only be used at the end of selector'); }
c = parserInput.currentChar();
if (elements) {
if (Array.isArray(e)){
e.forEach(ele => elements.push(ele));
} if (elements) {
elements.push(e);
} else {
elements = [ e ];
Expand Down
6 changes: 6 additions & 0 deletions packages/test-data/css/_main/selectors.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ blank blank blank blank blank blank blank blank blank blank blank blank blank bl
.first-level .second-level.active2 {
content: '\2661';
}
a:is(.b, :is(.c)) {
color: blue;
}
a:is(.b, :is(.c), :has(div)) {
color: red;
}
8 changes: 8 additions & 0 deletions packages/test-data/less/_main/selectors.less
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,11 @@ blank blank blank blank blank blank blank blank blank blank blank blank blank bl
&.active2:extend(.extend-this) { }
}
}

a:is(.b, :is(.c)) {
color: blue;
}

a:is(.b, :is(.c), :has(div)) {
color: red;
}

0 comments on commit e4198ba

Please sign in to comment.