MCPcopy Create free account
hub / github.com/nwutils/nw-sample-apps / matcherFromTokens

Function matcherFromTokens

camera/jquery.js:2256–2309  ·  view source on GitHub ↗
( tokens )

Source from the content-addressed store, hash-verified

2254}
2255
2256function matcherFromTokens( tokens ) {
2257 var checkContext, matcher, j,
2258 len = tokens.length,
2259 leadingRelative = Expr.relative[ tokens[0].type ],
2260 implicitRelative = leadingRelative || Expr.relative[" "],
2261 i = leadingRelative ? 1 : 0,
2262
2263 // The foundational matcher ensures that elements are reachable from top-level context(s)
2264 matchContext = addCombinator( function( elem ) {
2265 return elem === checkContext;
2266 }, implicitRelative, true ),
2267 matchAnyContext = addCombinator( function( elem ) {
2268 return indexOf.call( checkContext, elem ) > -1;
2269 }, implicitRelative, true ),
2270 matchers = [ function( elem, context, xml ) {
2271 return ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
2272 (checkContext = context).nodeType ?
2273 matchContext( elem, context, xml ) :
2274 matchAnyContext( elem, context, xml ) );
2275 } ];
2276
2277 for ( ; i < len; i++ ) {
2278 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
2279 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
2280 } else {
2281 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
2282
2283 // Return special upon seeing a positional matcher
2284 if ( matcher[ expando ] ) {
2285 // Find the next relative operator (if any) for proper handling
2286 j = ++i;
2287 for ( ; j < len; j++ ) {
2288 if ( Expr.relative[ tokens[j].type ] ) {
2289 break;
2290 }
2291 }
2292 return setMatcher(
2293 i > 1 && elementMatcher( matchers ),
2294 i > 1 && toSelector(
2295 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
2296 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
2297 ).replace( rtrim, "$1" ),
2298 matcher,
2299 i < j && matcherFromTokens( tokens.slice( i, j ) ),
2300 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
2301 j < len && toSelector( tokens )
2302 );
2303 }
2304 matchers.push( matcher );
2305 }
2306 }
2307
2308 return elementMatcher( matchers );
2309}
2310
2311function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
2312 var bySet = setMatchers.length > 0,

Callers 1

jquery.jsFile · 0.85

Calls 4

addCombinatorFunction · 0.85
elementMatcherFunction · 0.85
setMatcherFunction · 0.85
toSelectorFunction · 0.85

Tested by

no test coverage detected