diff --git a/src/match.js b/src/match.js index 40d1bf1..37ef306 100644 --- a/src/match.js +++ b/src/match.js @@ -139,11 +139,12 @@ function findAttributesPattern (priority, element, ignore) { const sortedKeys = Object.keys(attributes).sort((curr, next) => { const currPos = priority.indexOf(attributes[curr].name) const nextPos = priority.indexOf(attributes[next].name) - if (nextPos === -1) { - if (currPos === -1) { - return 0 - } - return -1 + if (nextPos === -1 || currPos === -1) { + if (nextPos === -1) { + return -1; + } else { + return 1; + } } return currPos - nextPos }) diff --git a/src/optimize.js b/src/optimize.js index 2d89309..2c9acfb 100644 --- a/src/optimize.js +++ b/src/optimize.js @@ -129,7 +129,7 @@ function optimizePart (prePart, current, postPart, elements) { while (names.length) { const partial = current.replace(names.shift(), '').trim() var pattern = `${prePart}${partial}${postPart}`.trim() - if (!pattern.length || pattern.charAt(0) === '>' || pattern.charAt(pattern.length-1) === '>') { + if (!pattern.length || pattern.charAt(0) === '>' || pattern.charAt(pattern.length-1) === '>' || partial === '>') { break } var matches = document.querySelectorAll(pattern)