(tokens)
| 1692 | } |
| 1693 | |
| 1694 | function matcherFromTokens(tokens) { |
| 1695 | var checkContext, matcher, j, |
| 1696 | len = tokens.length, |
| 1697 | leadingRelative = Expr.relative[tokens[0].type], |
| 1698 | implicitRelative = leadingRelative || Expr.relative[" "], |
| 1699 | i = leadingRelative ? 1 : 0, |
| 1700 | |
| 1701 | // The foundational matcher ensures that elements are reachable from top-level context(s) |
| 1702 | matchContext = addCombinator(function(elem) { |
| 1703 | return elem === checkContext; |
| 1704 | }, implicitRelative, true), |
| 1705 | matchAnyContext = addCombinator(function(elem) { |
| 1706 | return indexOf.call(checkContext, elem) > -1; |
| 1707 | }, implicitRelative, true), |
| 1708 | matchers = [ |
| 1709 | function(elem, context, xml) { |
| 1710 | return (!leadingRelative && (xml || context !== outermostContext)) || ( |
| 1711 | (checkContext = context).nodeType ? |
| 1712 | matchContext(elem, context, xml) : |
| 1713 | matchAnyContext(elem, context, xml)); |
| 1714 | } |
| 1715 | ]; |
| 1716 | |
| 1717 | for (; i < len; i++) { |
| 1718 | if ((matcher = Expr.relative[tokens[i].type])) { |
| 1719 | matchers = [addCombinator(elementMatcher(matchers), matcher)]; |
| 1720 | } else { |
| 1721 | matcher = Expr.filter[tokens[i].type].apply(null, tokens[i].matches); |
| 1722 | |
| 1723 | // Return special upon seeing a positional matcher |
| 1724 | if (matcher[expando]) { |
| 1725 | // Find the next relative operator (if any) for proper handling |
| 1726 | j = ++i; |
| 1727 | for (; j < len; j++) { |
| 1728 | if (Expr.relative[tokens[j].type]) { |
| 1729 | break; |
| 1730 | } |
| 1731 | } |
| 1732 | return setMatcher( |
| 1733 | i > 1 && elementMatcher(matchers), |
| 1734 | i > 1 && toSelector( |
| 1735 | // If the preceding token was a descendant combinator, insert an implicit any-element `*` |
| 1736 | tokens.slice(0, i - 1).concat({ |
| 1737 | value: tokens[i - 2].type === " " ? "*" : "" |
| 1738 | }) |
| 1739 | ).replace(rtrim, "$1"), |
| 1740 | matcher, |
| 1741 | i < j && matcherFromTokens(tokens.slice(i, j)), |
| 1742 | j < len && matcherFromTokens((tokens = tokens.slice(j))), |
| 1743 | j < len && toSelector(tokens) |
| 1744 | ); |
| 1745 | } |
| 1746 | matchers.push(matcher); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | return elementMatcher(matchers); |
| 1751 | } |
no test coverage detected