MCPcopy
hub / github.com/jquery/jquery / addCombinator

Function addCombinator

dist-module/jquery.slim.module.js:1930–1990  ·  view source on GitHub ↗
( matcher, combinator, base )

Source from the content-addressed store, hash-verified

1928jQuery.expr.setFilters = new setFilters();
1929
1930function addCombinator( matcher, combinator, base ) {
1931 var dir = combinator.dir,
1932 skip = combinator.next,
1933 key = skip || dir,
1934 checkNonElements = base && key === "parentNode",
1935 doneName = done++;
1936
1937 return combinator.first ?
1938
1939 // Check against closest ancestor/preceding element
1940 function( elem, context, xml ) {
1941 while ( ( elem = elem[ dir ] ) ) {
1942 if ( elem.nodeType === 1 || checkNonElements ) {
1943 return matcher( elem, context, xml );
1944 }
1945 }
1946 return false;
1947 } :
1948
1949 // Check against all ancestor/preceding elements
1950 function( elem, context, xml ) {
1951 var oldCache, outerCache,
1952 newCache = [ dirruns, doneName ];
1953
1954 // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching
1955 if ( xml ) {
1956 while ( ( elem = elem[ dir ] ) ) {
1957 if ( elem.nodeType === 1 || checkNonElements ) {
1958 if ( matcher( elem, context, xml ) ) {
1959 return true;
1960 }
1961 }
1962 }
1963 } else {
1964 while ( ( elem = elem[ dir ] ) ) {
1965 if ( elem.nodeType === 1 || checkNonElements ) {
1966 outerCache = elem[ jQuery.expando ] || ( elem[ jQuery.expando ] = {} );
1967
1968 if ( skip && nodeName( elem, skip ) ) {
1969 elem = elem[ dir ] || elem;
1970 } else if ( ( oldCache = outerCache[ key ] ) &&
1971 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
1972
1973 // Assign to newCache so results back-propagate to previous elements
1974 return ( newCache[ 2 ] = oldCache[ 2 ] );
1975 } else {
1976
1977 // Reuse newcache so results back-propagate to previous elements
1978 outerCache[ key ] = newCache;
1979
1980 // A match means we're done; a fail means we have to keep checking
1981 if ( ( newCache[ 2 ] = matcher( elem, context, xml ) ) ) {
1982 return true;
1983 }
1984 }
1985 }
1986 }
1987 }

Callers 2

jQueryFactoryFunction · 0.70
matcherFromTokensFunction · 0.70

Calls 1

nodeNameFunction · 0.70

Tested by

no test coverage detected