Skip to content

Commit

Permalink
support special case for custom pseudo element selector
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Aug 14, 2024
1 parent 8187632 commit 63529c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Added support of special case for custom pseudo element selector.

## v2.11.4

- Fixed parsing unclosed attribute selector (such as `a[href`).
Expand Down
7 changes: 4 additions & 3 deletions parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type GetLastTag<I> = I extends `${string}${Combinators}${infer Right}`
: GetLastTag<Right>
: I

type PseudoClassesFirstChar =
type PseudoPrefix =
| 'a'
| 'b'
| 'c'
Expand All @@ -31,6 +31,7 @@ type PseudoClassesFirstChar =
| 'u'
| 'v'
| 'w'
| ':-'

type Split<S> = S extends `${string},` // invalid selector
? unknown
Expand Down Expand Up @@ -108,9 +109,9 @@ type PostprocessEachUnchecked<I> =
? PostprocessEachUnchecked<`${Tag}&${Rest}`>
: I extends `${infer Tag}#${string}`
? PostprocessEachUnchecked<Tag>
: I extends `${infer Tag}:${PseudoClassesFirstChar}${string}&${infer Rest}`
: I extends `${infer Tag}:${PseudoPrefix}${string}&${infer Rest}`
? PostprocessEachUnchecked<`${Tag}&${Rest}`>
: I extends `${infer Tag}:${PseudoClassesFirstChar}${string}`
: I extends `${infer Tag}:${PseudoPrefix}${string}`
? PostprocessEachUnchecked<Tag>
: I extends `${string}|${infer Tag}` // namespace prefix
? PostprocessEachUnchecked<Tag>
Expand Down
1 change: 1 addition & 0 deletions parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ type _Tests = [
>,
Expect<Equal<ParseSelector<':func(arg)'>, Element>>,
Expect<Equal<ParseSelector<'::func(arg)'>, Element>>,
Expect<Equal<ParseSelector<'a::-p-text(Hello)'>, HTMLAnchorElement>>,
]

declare function delegate<
Expand Down

0 comments on commit 63529c6

Please sign in to comment.