Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading