MCPcopy Index your code
hub / github.com/jquery/jquery / matcherFromTokens

Function matcherFromTokens

dist-module/jquery.factory.module.js:2140–2206  ·  view source on GitHub ↗
( tokens )

Source from the content-addressed store, hash-verified

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