66 * Released under the MIT license
77 * http://jquery.org/license
88 *
9- * Date: 2014-02-12
9+ * Date: 2014-02-13
1010 */
1111( function ( window ) {
1212
@@ -1778,24 +1778,24 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers, siblings, reduc
17781778 * @return {Array|undefined } The list of unmatched seed elements
17791779 */
17801780 superMatcher = function ( context , results , seed , xml ) {
1781- var elems , elem , i , j , matcher , find , unmatched , len ,
1781+ var elem , len , i , j , matcher , unmatched ,
17821782 matchedCount = 0 ,
17831783 setMatched = [ ] ,
17841784 dirrunsBackup = dirruns ,
17851785 expansionBackup = contextExpanded ,
17861786 outermost = contextExpanded == null ;
17871787
17881788 // Use previously-established HTML vs. XML mode if not explicitly specified
1789- if ( xml === undefined ) {
1789+ if ( xml == null ) {
17901790 xml = ! documentIsHTML ;
17911791 }
17921792
17931793 // Try to reduce context
17941794 // Because setMatchers reenter Sizzle for their seeds, we can ignore them here
17951795 if ( reduceContext && context && context . nodeType === 9 && support . getById && byElement && ! xml ) {
1796- if ( ( elems = Expr . find [ "ID" ] ( reduceContext , context ) ) ) {
1797- if ( elems . length ) {
1798- context = elems [ 0 ] ;
1796+ if ( ( elem = Expr . find [ "ID" ] ( reduceContext , context ) ) ) {
1797+ if ( elem . length ) {
1798+ context = elem [ 0 ] ;
17991799 } else {
18001800 return results ;
18011801 }
@@ -1805,8 +1805,8 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers, siblings, reduc
18051805 // Try to find a small seed collection
18061806 i = byElement && ! seed && seeders . length ;
18071807 while ( i -- ) {
1808- if ( ( find = Expr . find [ seeders [ i ] . type ] ) ) {
1809- if ( ( seed = find (
1808+ if ( ( matcher = Expr . find [ seeders [ i ] . type ] ) ) {
1809+ if ( ( seed = matcher (
18101810 seeders [ i ] . matches [ 0 ] . replace ( runescape , funescape ) ,
18111811 siblings && expandContext ( context . parentNode ) || context
18121812 ) ) ) {
@@ -1819,22 +1819,27 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers, siblings, reduc
18191819 // Reserve integer dirruns for the outermost matcher
18201820 dirruns += outermost ? 1 : Math . random ( ) || 0.1 ;
18211821 // Don't let any parts of the selector escape our context
1822- if ( elems ) {
1822+ if ( elem ) {
18231823 context = context . parentNode ;
18241824 }
18251825 contextExpanded = context && context !== document && siblings != null || ! seed && siblings ;
18261826
1827- // We must always have either seed elements or outermost context
1828- unmatched = seed && [ ] ;
1829- elems = seed || byElement && Expr . find [ "TAG" ] ( "*" ,
1830- siblings && expandContext ( context . parentNode ) || context ) ;
1831- len = elems . length ;
1827+ // If we have a seed, we need to keep track of unmatched elements
1828+ if ( seed ) {
1829+ unmatched = [ ] ;
1830+
1831+ // ...but ultimately, we require a seed regardless
1832+ } else {
1833+ seed = byElement ?
1834+ Expr . find [ "TAG" ] ( "*" , siblings && expandContext ( context . parentNode ) || context ) :
1835+ [ ] ;
1836+ }
18321837
18331838 // Add elements passing elementMatchers directly to results
1834- // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
18351839 // Support: IE<9, Safari
18361840 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
1837- for ( i = "0" ; i !== len && ( elem = elems [ i ] ) != null ; i ++ ) {
1841+ len = seed . length ;
1842+ for ( i = 0 ; i !== len && ( elem = seed [ i ] ) != null ; i ++ ) {
18381843 if ( byElement && elem ) {
18391844 j = 0 ;
18401845 while ( ( matcher = elementMatchers [ j ++ ] ) ) {
@@ -1853,23 +1858,23 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers, siblings, reduc
18531858 }
18541859
18551860 // Lengthen the array for every element, matched or not
1856- if ( seed ) {
1861+ if ( unmatched ) {
18571862 unmatched . push ( elem ) ;
18581863 }
18591864 }
18601865 }
18611866
18621867 // Apply set filters to unmatched elements
18631868 matchedCount += i ;
1864- if ( bySet && i !== matchedCount ) {
1869+ if ( bySet && matchedCount < ( i || 1 ) ) {
18651870 j = 0 ;
18661871 while ( ( matcher = setMatchers [ j ++ ] ) ) {
18671872 matcher ( unmatched , setMatched , context , xml ) ;
18681873 }
18691874
1870- if ( seed ) {
1875+ if ( unmatched ) {
18711876 // Reintegrate element matches to eliminate the need for sorting
1872- if ( matchedCount > 0 ) {
1877+ if ( matchedCount ) {
18731878 while ( i -- ) {
18741879 if ( ! ( unmatched [ i ] || setMatched [ i ] ) ) {
18751880 setMatched [ i ] = pop . call ( results ) ;
@@ -1885,7 +1890,7 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers, siblings, reduc
18851890 push . apply ( results , setMatched ) ;
18861891
18871892 // Seedless set matches succeeding multiple successful matchers stipulate sorting
1888- if ( outermost && ! seed && setMatched . length > 0 &&
1893+ if ( outermost && ! unmatched && setMatched . length &&
18891894 ( matchedCount + setMatchers . length ) > 1 ) {
18901895
18911896 Sizzle . uniqueSort ( results ) ;
0 commit comments