diff --git a/src/js/finder.js b/src/js/finder.js index 738bb5a..69093ee 100644 --- a/src/js/finder.js +++ b/src/js/finder.js @@ -161,6 +161,7 @@ export class Finder { const item = cachedItem.get(`${selector}`); ast = item.ast; this.#descendant = item.descendant; + this.#invalidate = item.invalidate; } } if (ast) { @@ -179,7 +180,7 @@ export class Finder { } catch (e) { this._onError(e); } - const { branches } = walkAST(cssAst); + const { branches, info: { hasHasPseudo: invalidate } } = walkAST(cssAst); let descendant = false; let i = 0; ast = []; @@ -247,10 +248,12 @@ export class Finder { } cachedItem.set(`${selector}`, { ast, - descendant + descendant, + invalidate: !!invalidate }); this.#documentCache.set(this.#document, cachedItem); this.#descendant = descendant; + this.#invalidate = !!invalidate; } return [ ast, diff --git a/src/js/parser.js b/src/js/parser.js index 0694f07..385616f 100644 --- a/src/js/parser.js +++ b/src/js/parser.js @@ -195,6 +195,9 @@ export const walkAST = (ast = {}) => { if (REG_LOGICAL_PSEUDO.test(node.name)) { info.set('hasNestedSelector', true); info.set('hasLogicalPseudoFunc', true); + if (node.name === 'has') { + info.set('hasHasPseudoFunc', true); + } } break; } diff --git a/test/parser.test.js b/test/parser.test.js index dbe8fc3..f66658f 100644 --- a/test/parser.test.js +++ b/test/parser.test.js @@ -7096,6 +7096,7 @@ describe('walk AST', () => { ] ], info: { + hasHasPseudoFunc: true, hasLogicalPseudoFunc: true, hasNestedSelector: true }