Skip to content

Commit a528ae5

Browse files
authored
Selector: Make selectors with leading combinators use qSA again
An optimization added in #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 & #453, all modern browsers other than Edge leverage the :scope pseudo-class, avoiding temporary id attributes. Closes gh-460 Ref gh-431
1 parent 0f4bd29 commit a528ae5

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

dist/sizzle.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Released under the MIT license
77
* https://js.foundation/
88
*
9-
* Date: 2019-10-01
9+
* Date: 2019-10-13
1010
*/
1111
( function( window ) {
1212
var i,
@@ -323,8 +323,11 @@ function Sizzle( selector, context, results, seed ) {
323323
// descendant combinators, which is not what we want.
324324
// In such cases, we work around the behavior by prefixing every selector in the
325325
// list with an ID selector referencing the scope context.
326+
// The technique has to be used as well when a leading combinator is used
327+
// as such selectors are not recognized by querySelectorAll.
326328
// Thanks to Andrew Dupont for this technique.
327-
if ( nodeType === 1 && rdescend.test( selector ) ) {
329+
if ( nodeType === 1 &&
330+
( rdescend.test( selector ) || rcombinators.test( selector ) ) ) {
328331

329332
// Expand context for sibling selectors
330333
newContext = rsibling.test( selector ) && testContext( context.parentNode ) ||

0 commit comments

Comments
 (0)