fix(issue:4268) nested pseudo-selector parsing (#4290)

* Fix nested pseudo-selector parsing where selectors are separated by
  one or more commas.
This commit is contained in:
Daniel Puckowski
2024-12-07 11:40:42 -05:00
committed by GitHub
parent 773e157c76
commit e4198bafc8
3 changed files with 38 additions and 4 deletions

View File

@@ -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
@@ -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 \')\'');
}
@@ -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 ];

View File

@@ -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;
}

View File

@@ -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;
}