Skip to content

Commit

Permalink
fix: type and reduce lookups
Browse files Browse the repository at this point in the history
Co-authored-by: Remi <remusao@users.noreply.github.com>
  • Loading branch information
seia-soto and remusao committed Jun 17, 2024
1 parent 3e8365b commit bb75d59
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/adblocker/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type NetworkFilterMatchingContext = {
// but cosmetic filter is used for better documentation.
type CosmeticFilterMatchingContextBase = {
url: string;
domain: string | null | undefined;
domain: string;
hostname: string | undefined;

filterType: FilterType.COSMETIC;
Expand Down Expand Up @@ -751,8 +751,10 @@ export default class FilterEngine extends EventEmitter<EngineEventHandlers> {
return htmlSelectors;
}

domain ||= '';

const { rules, candidates, exceptions } = this.cosmetics.getHtmlRules({
domain: domain || '',
domain,
hostname,
isFilterExcluded: this.isFilterExcluded.bind(this),
});
Expand Down Expand Up @@ -935,8 +937,9 @@ export default class FilterEngine extends EventEmitter<EngineEventHandlers> {
for (const match of candidates) {
this.emit('filter-matched', match, context);

if (exceptionMatches.has(match)) {
this.emit('filter-matched', exceptionMatches.get(match)!, context);
const exception = exceptionMatches.get(match);
if (exception !== undefined) {
this.emit('filter-matched', exception, context);
}
}
}
Expand Down

0 comments on commit bb75d59

Please sign in to comment.