Skip to content
Permalink
Browse files

Selector: update Sizzle

  • Loading branch information...
mgol committed Feb 5, 2014
1 parent cab1835 commit a74ad04bc9c4c7203303b2547e94f1cc53c2a460
Showing with 94 additions and 64 deletions.
  1. +1 −1 bower.json
  2. +77 −58 src/sizzle/dist/sizzle.js
  3. +2 −2 src/sizzle/dist/sizzle.min.js
  4. +1 −1 src/sizzle/dist/sizzle.min.map
  5. +13 −2 src/sizzle/test/unit/selector.js
@@ -13,7 +13,7 @@
"bower.json"
],
"dependencies": {
"sizzle": "1.10.16"
"sizzle": "1.10.18"
},
"devDependencies": {
"requirejs": "2.1.10",
@@ -1,12 +1,12 @@
/*!
* Sizzle CSS Selector Engine v1.10.16
* Sizzle CSS Selector Engine v1.10.18
* http://sizzlejs.com/
*
* Copyright 2013 jQuery Foundation, Inc. and other contributors
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2014-01-13
* Date: 2014-02-05
*/
(function( window ) {

@@ -16,6 +16,7 @@ var i,
getText,
isXML,
compile,
select,
outermostContext,
sortInput,
hasDuplicate,
@@ -137,7 +138,7 @@ var i,
funescape = function( _, escaped, escapedWhitespace ) {
var high = "0x" + escaped - 0x10000;
// NaN means non-codepoint
// Support: Firefox
// Support: Firefox<24
// Workaround erroneous numeric interpretation of +"0x"
return high !== high || escapedWhitespace ?
escaped :
@@ -1570,6 +1571,15 @@ function elementMatcher( matchers ) {
matchers[0];
}

function multipleContexts( selector, contexts, results ) {
var i = 0,
len = contexts.length;
for ( ; i < len; i++ ) {
Sizzle( selector, contexts[i], results );
}
return results;
}

function condense( unmatched, map, filter, context, xml ) {
var elem,
newUnmatched = [],
@@ -1838,20 +1848,20 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
superMatcher;
}

compile = Sizzle.compile = function( selector, group /* Internal Use Only */ ) {
compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
var i,
setMatchers = [],
elementMatchers = [],
cached = compilerCache[ selector + " " ];

if ( !cached ) {
// Generate a function of recursive functions that can be used to check each element
if ( !group ) {
group = tokenize( selector );
if ( !match ) {
match = tokenize( selector );
}
i = group.length;
i = match.length;
while ( i-- ) {
cached = matcherFromTokens( group[i] );
cached = matcherFromTokens( match[i] );
if ( cached[ expando ] ) {
setMatchers.push( cached );
} else {
@@ -1861,82 +1871,91 @@ compile = Sizzle.compile = function( selector, group /* Internal Use Only */ ) {

// Cache the compiled function
cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );

// Save selector and tokenization
cached.selector = selector;
}
return cached;
};

function multipleContexts( selector, contexts, results ) {
var i = 0,
len = contexts.length;
for ( ; i < len; i++ ) {
Sizzle( selector, contexts[i], results );
}
return results;
}

function select( selector, context, results, seed ) {
/**
* A low-level selection function that works with Sizzle's compiled
* selector functions
* @param {String|Function} selector A selector or a pre-compiled
* selector function built with Sizzle.compile
* @param {Element} context
* @param {Array} [results]
* @param {Array} [seed] A set of elements to match against
*/
select = Sizzle.select = function( selector, context, results, seed ) {
var i, tokens, token, type, find,
match = tokenize( selector );
compiled = typeof selector === "function" && selector,
match = !seed && tokenize( (selector = compiled.selector || selector) );

if ( !seed ) {
// Try to minimize operations if there is only one group
if ( match.length === 1 ) {
results = results || [];

// Take a shortcut and set the context if the root selector is an ID
tokens = match[0] = match[0].slice( 0 );
if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
support.getById && context.nodeType === 9 && documentIsHTML &&
Expr.relative[ tokens[1].type ] ) {
// Try to minimize operations if there is no seed and only one group
if ( match.length === 1 ) {

context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
if ( !context ) {
return results;
}
selector = selector.slice( tokens.shift().value.length );
// Take a shortcut and set the context if the root selector is an ID
tokens = match[0] = match[0].slice( 0 );
if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
support.getById && context.nodeType === 9 && documentIsHTML &&
Expr.relative[ tokens[1].type ] ) {

context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
if ( !context ) {
return results;

// Precompiled matchers will still verify ancestry, so step up a level
} else if ( compiled ) {
context = context.parentNode;
}

// Fetch a seed set for right-to-left matching
i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
while ( i-- ) {
token = tokens[i];
selector = selector.slice( tokens.shift().value.length );
}

// Abort if we hit a combinator
if ( Expr.relative[ (type = token.type) ] ) {
break;
}
if ( (find = Expr.find[ type ]) ) {
// Search, expanding context for leading sibling combinators
if ( (seed = find(
token.matches[0].replace( runescape, funescape ),
rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
)) ) {

// If seed is empty or no tokens remain, we can return early
tokens.splice( i, 1 );
selector = seed.length && toSelector( tokens );
if ( !selector ) {
push.apply( results, seed );
return results;
}
// Fetch a seed set for right-to-left matching
i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
while ( i-- ) {
token = tokens[i];

break;
// Abort if we hit a combinator
if ( Expr.relative[ (type = token.type) ] ) {
break;
}
if ( (find = Expr.find[ type ]) ) {
// Search, expanding context for leading sibling combinators
if ( (seed = find(
token.matches[0].replace( runescape, funescape ),
rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
)) ) {

// If seed is empty or no tokens remain, we can return early
tokens.splice( i, 1 );
selector = seed.length && toSelector( tokens );
if ( !selector ) {
push.apply( results, seed );
return results;
}

break;
}
}
}
}

// Compile and execute a filtering function
// Compile and execute a filtering function if one is not provided
// Provide `match` to avoid retokenization if we modified the selector above
compile( selector, match )(
( compiled || compile( selector, match ) )(
seed,
context,
!documentIsHTML,
results,
rsibling.test( selector ) && testContext( context.parentNode ) || context
);
return results;
}
};

// One-time assignments

Oops, something went wrong.

0 comments on commit a74ad04

Please sign in to comment.
You can’t perform that action at this time.