Fix regression in `:is()` operator

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/2818
This commit is contained in:
Raymond Hill 2023-09-16 09:45:46 -04:00
parent 98e1b264de
commit 7ef3408712
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 25 additions and 37 deletions

View File

@ -3436,35 +3436,6 @@ class ExtSelectorCompiler {
return out.join(''); return out.join('');
} }
astAppendPart(part, out) {
const s = this.astSerializePart(part);
if ( s === undefined ) { return false; }
const { data } = part;
switch ( data.type ) {
case 'Combinator':
if ( out.length === 0 ) {
if ( s !== ' ' ) {
out.push(s, ' ');
}
} else {
out.push(' ');
if ( s !== ' ' ) {
out.push(s, ' ');
}
}
break;
// csstree parses `.promoted*` as valid
case 'TypeSelector':
if ( s === '*' && out.length !== 0 ) {
const before = out[out.length-1];
if ( before.endsWith(' ') === false ) { return false; }
}
out.push(s);
break;
}
return true;
}
astSerialize(parts, plainCSS = true) { astSerialize(parts, plainCSS = true) {
const out = []; const out = [];
for ( const part of parts ) { for ( const part of parts ) {
@ -3482,10 +3453,23 @@ class ExtSelectorCompiler {
out.push(s); out.push(s);
break; break;
} }
case 'Combinator': case 'Combinator': {
case 'TypeSelector': const s = this.astSerializePart(part);
if ( this.astAppendPart(part, out) === false ) { return; } if ( s === undefined ) { return; }
if ( out.length !== 0 ) { out.push(' '); }
if ( s !== ' ' ) { out.push(s, ' '); }
break; break;
}
case 'TypeSelector': {
const s = this.astSerializePart(part);
if ( s === undefined ) { return; }
if ( s === '*' && out.length !== 0 ) {
const before = out[out.length-1];
if ( before.endsWith(' ') === false ) { return; }
}
out.push(s);
break;
}
case 'Raw': case 'Raw':
if ( plainCSS ) { return; } if ( plainCSS ) { return; }
out.push(this.astSerializePart(part)); out.push(this.astSerializePart(part));
@ -3509,8 +3493,9 @@ class ExtSelectorCompiler {
const out = { selector: '' }; const out = { selector: '' };
const prelude = []; const prelude = [];
const tasks = []; const tasks = [];
for ( const part of parts ) { for ( let i = 0; i < parts.length; i++ ) {
if ( out.action !== undefined ) { return; } if ( out.action !== undefined ) { return; }
const part = parts[i];
const { data } = part; const { data } = part;
switch ( data.type ) { switch ( data.type ) {
case 'ActionSelector': { case 'ActionSelector': {
@ -3534,13 +3519,16 @@ class ExtSelectorCompiler {
case 'PseudoClassSelector': case 'PseudoClassSelector':
case 'PseudoElementSelector': case 'PseudoElementSelector':
case 'TypeSelector': { case 'TypeSelector': {
const component = this.astSerializePart(part); const s = this.astSerializePart(part);
if ( component === undefined ) { return; } if ( s === undefined ) { return; }
prelude.push(component); prelude.push(s);
break; break;
} }
case 'Combinator': { case 'Combinator': {
if ( this.astAppendPart(part, prelude) === false ) { return; } const s = this.astSerializePart(part);
if ( s === undefined ) { return; }
if ( i !== 0 || prelude.length !== 0 ) { prelude.push(' '); }
if ( s !== ' ' ) { prelude.push(s, ' '); }
break; break;
} }
case 'ProceduralSelector': { case 'ProceduralSelector': {