MCPcopy Create free account
hub / github.com/components/jquery / matcherFromTokens

Function matcherFromTokens

jquery.js:2149–2215  ·  view source on GitHub ↗
( tokens )

Source from the content-addressed store, hash-verified

2147}
2148
2149function matcherFromTokens( tokens ) {
2150 var checkContext, matcher, j,
2151 len = tokens.length,
2152 leadingRelative = jQuery.expr.relative[ tokens[ 0 ].type ],
2153 implicitRelative = leadingRelative || jQuery.expr.relative[ " " ],
2154 i = leadingRelative ? 1 : 0,
2155
2156 // The foundational matcher ensures that elements are reachable from top-level context(s)
2157 matchContext = addCombinator( function( elem ) {
2158 return elem === checkContext;
2159 }, implicitRelative, true ),
2160 matchAnyContext = addCombinator( function( elem ) {
2161 return indexOf.call( checkContext, elem ) > -1;
2162 }, implicitRelative, true ),
2163 matchers = [ function( elem, context, xml ) {
2164
2165 // Support: IE 11+
2166 // IE sometimes throws a "Permission denied" error when strict-comparing
2167 // two documents; shallow comparisons work.
2168 // eslint-disable-next-line eqeqeq
2169 var ret = ( !leadingRelative && ( xml || context != outermostContext ) ) || (
2170 ( checkContext = context ).nodeType ?
2171 matchContext( elem, context, xml ) :
2172 matchAnyContext( elem, context, xml ) );
2173
2174 // Avoid hanging onto element
2175 // (see https://github.com/jquery/sizzle/issues/299)
2176 checkContext = null;
2177 return ret;
2178 } ];
2179
2180 for ( ; i < len; i++ ) {
2181 if ( ( matcher = jQuery.expr.relative[ tokens[ i ].type ] ) ) {
2182 matchers = [ addCombinator( elementMatcher( matchers ), matcher ) ];
2183 } else {
2184 matcher = jQuery.expr.filter[ tokens[ i ].type ].apply( null, tokens[ i ].matches );
2185
2186 // Return special upon seeing a positional matcher
2187 if ( matcher[ jQuery.expando ] ) {
2188
2189 // Find the next relative operator (if any) for proper handling
2190 j = ++i;
2191 for ( ; j < len; j++ ) {
2192 if ( jQuery.expr.relative[ tokens[ j ].type ] ) {
2193 break;
2194 }
2195 }
2196 return setMatcher(
2197 i > 1 && elementMatcher( matchers ),
2198 i > 1 && toSelector(
2199
2200 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
2201 tokens.slice( 0, i - 1 )
2202 .concat( { value: tokens[ i - 2 ].type === " " ? "*" : "" } )
2203 ).replace( rtrimCSS, "$1" ),
2204 matcher,
2205 i < j && matcherFromTokens( tokens.slice( i, j ) ),
2206 j < len && matcherFromTokens( ( tokens = tokens.slice( j ) ) ),

Callers 1

compileFunction · 0.70

Calls 4

addCombinatorFunction · 0.70
elementMatcherFunction · 0.70
setMatcherFunction · 0.70
toSelectorFunction · 0.70

Tested by

no test coverage detected