Fix detection of leading combinators

Related feedback:
https://github.com/uBlockOrigin/uBlock-issues/issues/2778#issuecomment-1722488224
This commit is contained in:
Raymond Hill 2023-09-17 10:37:43 -04:00
parent d005e3f3ac
commit 20d3c6a466
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 10 additions and 3 deletions

View File

@ -3493,9 +3493,9 @@ class ExtSelectorCompiler {
const out = { selector: '' };
const prelude = [];
const tasks = [];
for ( let i = 0; i < parts.length; i++ ) {
let startOfSelector = true;
for ( const part of parts ) {
if ( out.action !== undefined ) { return; }
const part = parts[i];
const { data } = part;
switch ( data.type ) {
case 'ActionSelector': {
@ -3522,13 +3522,17 @@ class ExtSelectorCompiler {
const s = this.astSerializePart(part);
if ( s === undefined ) { return; }
prelude.push(s);
startOfSelector = false;
break;
}
case 'Combinator': {
const s = this.astSerializePart(part);
if ( s === undefined ) { return; }
if ( i !== 0 || prelude.length !== 0 ) { prelude.push(' '); }
if ( startOfSelector === false || prelude.length !== 0 ) {
prelude.push(' ');
}
if ( s !== ' ' ) { prelude.push(s, ' '); }
startOfSelector = false;
break;
}
case 'ProceduralSelector': {
@ -3545,14 +3549,17 @@ class ExtSelectorCompiler {
const args = this.compileArgumentAst(data.name, part.args);
if ( args === undefined ) { return; }
tasks.push([ data.name, args ]);
startOfSelector = false;
break;
}
case 'Selector':
if ( prelude.length !== 0 ) {
prelude.push(', ');
}
startOfSelector = true;
break;
case 'SelectorList':
startOfSelector = true;
break;
default:
return;