MCPcopy
hub / github.com/jquery/jquery / matcherFromTokens

Function matcherFromTokens

dist-module/jquery.slim.module.js:2135–2201  ·  view source on GitHub ↗
( tokens )

Source from the content-addressed store, hash-verified

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