Skip to content

Commit

Permalink
Set invalidation if selector contains :has()
Browse files Browse the repository at this point in the history
Follow up #107
  • Loading branch information
asamuzaK committed Jul 25, 2024
1 parent 96e38cd commit 4a229bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/js/finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/js/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7096,6 +7096,7 @@ describe('walk AST', () => {
]
],
info: {
hasHasPseudoFunc: true,
hasLogicalPseudoFunc: true,
hasNestedSelector: true
}
Expand Down

0 comments on commit 4a229bb

Please sign in to comment.