MCPcopy Create free account
hub / github.com/JsAaron/jQuery / superMatcher

Function superMatcher

2.0.3/Sizzle-annotation.js:1951–2053  ·  view source on GitHub ↗
(seed, context, xml, results, expandContext)

Source from the content-addressed store, hash-verified

1949 byElement = elementMatchers.length > 0,
1950
1951 superMatcher = function(seed, context, xml, results, expandContext) {
1952 var elem, j, matcher,
1953 setMatched = [],
1954 matchedCount = 0,
1955 i = "0",
1956 unmatched = seed && [],
1957 outermost = expandContext != null,
1958 contextBackup = outermostContext,
1959
1960 //这一步很关键!
1961 //如果说有初始集合seed,那用它
1962 //如果没有,那只能把整个DOM树节点取出来过滤了,可以看出选择器最右边应该写一个
1963 // We must always have either seed elements or context
1964 elems = seed || byElement && Expr.find["TAG"]("*", expandContext && context.parentNode || context),
1965 // Use integer dirruns iff this is the outermost matcher
1966 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
1967 len = elems.length;
1968
1969 if (outermost) {
1970 outermostContext = context !== document && context;
1971 cachedruns = matcherCachedRuns;
1972 }
1973
1974 //好,开始过滤这个elems集合了!
1975 // Add elements passing elementMatchers directly to results
1976 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
1977 // Support: IE<9, Safari
1978 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
1979 for (; i !== len && (elem = elems[i]) != null; i++) {
1980 if (byElement && elem) {
1981 j = 0;
1982
1983 //把所有的过滤器拿出来
1984 //这里的每个匹配器都是上边提到的终极匹配器,既然是终极匹配器,那为什么会有多个呢?
1985 //因为:div, p实际上是需要两个终极匹配器的(逗号分隔开表示有两个选择器了),:)
1986 while ((matcher = elementMatchers[j++])) {
1987 //过滤这个集合的元素elem,如果符合匹配器的规则,那么就添加到结果集里边去
1988 if (matcher(elem, context, xml)) {
1989 results.push(elem);
1990 break;
1991 }
1992 }
1993 if (outermost) {
1994 dirruns = dirrunsUnique;
1995 cachedruns = ++matcherCachedRuns;
1996 }
1997 }
1998
1999 // Track unmatched elements for set filters
2000 if (bySet) {
2001 // They will have gone through all possible matchers
2002 if ((elem = !matcher && elem)) {
2003 matchedCount--;
2004 }
2005
2006 // Lengthen the array for every element, matched or not
2007 if (seed) {
2008 unmatched.push(elem);

Callers

nothing calls this directly

Calls 1

condenseFunction · 0.70

Tested by

no test coverage detected