diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-10-14 18:28:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-14 18:28:19 +0200 |
commit | ed66d5a22b37425abf5b63c361f91340de89c994 (patch) | |
tree | b52eaa911889ab9b71a2e5e7b003ff226f7a48ea | |
parent | bbad821c399da92995a11b88d6684970479d4a9b (diff) | |
download | jquery-ed66d5a22b37425abf5b63c361f91340de89c994.tar.gz jquery-ed66d5a22b37425abf5b63c361f91340de89c994.zip |
Selector: Make selectors with leading combinators use qSA again
An optimization added in jquery/sizzle#431 skips the temporary IDs for selectors
not using child or descendant combinators. For sibling combinators, though, this
pushes a selector with a leading combinator to qSA directly which crashes and
falls back to a slower Sizzle route.
This commit makes selectors with leading combinators not skip the selector
rewriting. Note that after jquery/jquery#4454 & jquery/sizzle#453, all modern
browsers other than Edge leverage the :scope pseudo-class, avoiding temporary
id attributes.
Closes gh-4509
Ref jquery/sizzle#431
-rw-r--r-- | src/selector.js | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/selector.js b/src/selector.js index ea7a7b591..badb3dd6c 100644 --- a/src/selector.js +++ b/src/selector.js @@ -226,8 +226,11 @@ function find( selector, context, results, seed ) { // descendant combinators, which is not what we want. // In such cases, we work around the behavior by prefixing every selector in the // list with an ID selector referencing the scope context. + // The technique has to be used as well when a leading combinator is used + // as such selectors are not recognized by querySelectorAll. // Thanks to Andrew Dupont for this technique. - if ( nodeType === 1 && rdescend.test( selector ) ) { + if ( nodeType === 1 && + ( rdescend.test( selector ) || rcombinators.test( selector ) ) ) { // Expand context for sibling selectors newContext = rsibling.test( selector ) && testContext( context.parentNode ) || |