-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
51 additions
and
24 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
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,20 @@ | ||
import type {AstElement} from '../lib/element'; | ||
import type { | ||
Token, | ||
} from '../internal'; | ||
|
||
// @ts-expect-error unconstrained predicate | ||
export type TokenPredicate<T = Token> = (token: AstElement) => token is T; | ||
|
||
/** | ||
* 将选择器转化为类型谓词 | ||
* @param selector 选择器 | ||
* @param scope 作用对象 | ||
* @param has `:has()`伪选择器 | ||
*/ | ||
export const getCondition = <T>(selector: string, scope: AstElement, has?: Token): TokenPredicate<T> => ( | ||
({type, name}): boolean => selector.split(',').some(str => { | ||
const [t, ...ns] = str.trim().split('#'); | ||
return (!t || t === type) && ns.every(n => n === name); | ||
}) | ||
) as TokenPredicate<T>; |
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