Skip to content

Commit

Permalink
feat(core): variant group supports bracket selector (#1415)
Browse files Browse the repository at this point in the history
* fix(core): variant group supports :not selector

* fix(core): variant group more precise square bracket css selector match
  • Loading branch information
agufagit committed Aug 15, 2022
1 parent 540163a commit dfc9ddc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/utils/variantGroup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type MagicString from 'magic-string'

export const regexClassGroup = /([!\w+:_/-]+?)([:-])\(((?:[~!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm
export const regexClassGroup = /((?:[!\w+:_/-]|\[&?>?:.+?\])+?)([:-])\(((?:[~!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm

export function expandVariantGroup(str: string, seperators?: ('-' | ':')[]): string
export function expandVariantGroup(str: MagicString, seperators?: ('-' | ':')[]): MagicString
Expand Down
4 changes: 4 additions & 0 deletions test/variant-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ describe('variant-group', () => {
test('spaces', () => {
expect(expandVariantGroup('a-( ~ b c )')).toEqual('a a-b a-c')
})

test('square bracket', async () => {
expect(expandVariantGroup('b:[&:not(c)]:d:(!a z)')).toEqual('!b:[&:not(c)]:d:a b:[&:not(c)]:d:z')
})
})

0 comments on commit dfc9ddc

Please sign in to comment.