-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AG-37643 Convert ABP's rules to AdGuard syntax.
Squashed commit of the following: commit a709d71 Merge: 9502b10 e64bdd1 Author: jellizaveta <[email protected]> Date: Wed Dec 18 15:40:51 2024 +0300 Merge branch 'fix/AG-37643' of ssh://bit.int.agrd.dev:7999/adguard-filters/tsurlfilter into fix/AG-37643 commit 9502b10 Author: jellizaveta <[email protected]> Date: Wed Dec 18 15:40:27 2024 +0300 add jsDoc comment commit e64bdd1 Author: Dávid Tóta <[email protected]> Date: Wed Dec 18 14:35:57 2024 +0300 Applied suggestion commit 89715a4 Author: jellizaveta <[email protected]> Date: Wed Dec 18 12:51:02 2024 +0300 add test, fix chngelog commit 6c57008 Author: Slava Leleka <[email protected]> Date: Wed Dec 18 12:50:03 2024 +0300 Applied suggestion commit 07b2ad4 Author: Slava Leleka <[email protected]> Date: Wed Dec 18 12:49:56 2024 +0300 Applied suggestion commit 00342b6 Author: jellizaveta <[email protected]> Date: Mon Dec 16 12:44:47 2024 +0300 fix changelog, styles commit 8496d6a Author: Dávid Tóta <[email protected]> Date: Mon Dec 16 12:46:49 2024 +0300 Applied suggestion commit 9fe7dcf Author: jellizaveta <[email protected]> Date: Mon Dec 16 11:39:23 2024 +0300 fix jsDoc commit 06ae9b8 Author: Slava Leleka <[email protected]> Date: Mon Dec 16 11:24:48 2024 +0300 Applied suggestion commit 959f8dd Author: jellizaveta <[email protected]> Date: Fri Dec 13 19:18:11 2024 +0300 fix naming in tests commit 429c699 Author: jellizaveta <[email protected]> Date: Fri Dec 13 19:13:01 2024 +0300 update version to 2.3.0 commit 3c7b8e2 Author: jellizaveta <[email protected]> Date: Fri Dec 13 19:06:54 2024 +0300 eslint commit a38ad21 Author: jellizaveta <[email protected]> Date: Fri Dec 13 19:06:01 2024 +0300 add jsDocs commit 1dab9d0 Author: jellizaveta <[email protected]> Date: Fri Dec 13 19:04:19 2024 +0300 fix the latest tests commit 1a93eca Author: scripthunter7 <[email protected]> Date: Fri Dec 13 17:01:00 2024 +0100 fix one test commit 004f3f4 Author: scripthunter7 <[email protected]> Date: Fri Dec 13 17:00:38 2024 +0100 add util method for last slot commit 21ab05e Author: scripthunter7 <[email protected]> Date: Fri Dec 13 17:00:16 2024 +0100 fix error offsets in css token stream constructor commit 071fca7 Merge: c6f6196 2db9ade Author: jellizaveta <[email protected]> Date: Fri Dec 13 18:31:24 2024 +0300 resolve conflict commit c6f6196 Author: jellizaveta <[email protected]> Date: Fri Dec 13 18:30:06 2024 +0300 add check for curly breckets ... and 11 more commits
- Loading branch information
1 parent
014a3df
commit 45c8052
Showing
8 changed files
with
728 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { type TokenType, tokenizeExtended } from '@adguard/css-tokenizer'; | ||
|
||
/** | ||
* Represents an error that occurs when an operation is aborted. | ||
*/ | ||
class AbortError extends Error { | ||
constructor() { | ||
super('Aborted'); | ||
} | ||
} | ||
|
||
// TODO: AG-38480 add a stop function to the tokenizers callback and move `hasToken` to CSS Tokenizer as well | ||
/** | ||
* Checks if the given raw string contains any of the specified tokens. | ||
* This function uses error throwing inside the abort tokenization process. | ||
* | ||
* @param raw - The raw string to be tokenized and checked. | ||
* @param tokens - A set of token types to check for in the raw string. | ||
* @returns `true` if any of the specified tokens are found in the raw string, otherwise `false`. | ||
*/ | ||
export const hasToken = (raw: string, tokens: Set<TokenType>): boolean => { | ||
try { | ||
tokenizeExtended( | ||
raw, | ||
(type: TokenType) => { | ||
if (tokens.has(type)) { | ||
throw new AbortError(); | ||
} | ||
}, | ||
); | ||
} catch (e) { | ||
if (e instanceof AbortError) { | ||
return true; | ||
} | ||
throw e; | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.