(selector, context, results, seed)
| 2829 | } |
| 2830 | |
| 2831 | function select(selector, context, results, seed) { |
| 2832 | var i, tokens, token, type, find, |
| 2833 | match = tokenize(selector); |
| 2834 | |
| 2835 | if (!seed) { |
| 2836 | // Try to minimize operations if there is only one group |
| 2837 | if (match.length === 1) { |
| 2838 | // Take a shortcut and set the context if the root selector is an ID |
| 2839 | tokens = match[0] = match[0].slice(0); |
| 2840 | if (tokens.length > 2 && (token = tokens[0]).type === "ID" && |
| 2841 | support.getById && context.nodeType === 9 && documentIsHTML && |
| 2842 | Expr.relative[tokens[1].type]) { |
| 2843 | context = (Expr.find["ID"](token.matches[0].replace(runescape, funescape), context) || [])[0]; |
| 2844 | if (!context) { |
| 2845 | return results; |
| 2846 | } |
| 2847 | selector = selector.slice(tokens.shift().value.length); |
| 2848 | } |
| 2849 | |
| 2850 | // Fetch a seed set for right-to-left matching |
| 2851 | i = matchExpr["needsContext"].test(selector) ? 0 : tokens.length; |
| 2852 | while (i--) { |
| 2853 | token = tokens[i]; |
| 2854 | |
| 2855 | // Abort if we hit a combinator |
| 2856 | if (Expr.relative[(type = token.type)]) { |
| 2857 | break; |
| 2858 | } |
| 2859 | if ((find = Expr.find[type])) { |
| 2860 | // Search, expanding context for leading sibling combinators |
| 2861 | if ((seed = find( |
| 2862 | token.matches[0].replace(runescape, funescape), |
| 2863 | rsibling.test(tokens[0].type) && context.parentNode || context |
| 2864 | ))) { |
| 2865 | // If seed is empty or no tokens remain, we can return early |
| 2866 | tokens.splice(i, 1); |
| 2867 | selector = seed.length && toSelector(tokens); |
| 2868 | if (!selector) { |
| 2869 | push.apply(results, seed); |
| 2870 | return results; |
| 2871 | } |
| 2872 | |
| 2873 | break; |
| 2874 | } |
| 2875 | } |
| 2876 | } |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | // Compile and execute a filtering function |
| 2881 | // Provide `match` to avoid retokenization if we modified the selector above |
| 2882 | compile(selector, match)( |
| 2883 | seed, |
| 2884 | context, |
| 2885 | !documentIsHTML, |
| 2886 | results, |
| 2887 | rsibling.test(selector) |
| 2888 | ); |
no test coverage detected