Skip to content

Commit 037ba01

Browse files
zyyvCopilot
andauthored
feat(core): support * parse in variant group (#5124)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fa85154 commit 037ba01

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages-engine/core/src/utils/variant-group.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const regexCache: Record<string, RegExp> = {}
77
export function makeRegexClassGroup(separators = ['-', ':']) {
88
const key = separators.join('|')
99
if (!regexCache[key])
10-
regexCache[key] = new RegExp(`((?:[!@<~\\w+:_-]|\\[&?>?:?\\S*\\])+?)(${key})\\(((?:[~!<>\\w\\s:/\\\\,%#.$?-]|\\[[^\\]]*?\\])+?)\\)(?!\\s*?=>)`, 'gm')
10+
regexCache[key] = new RegExp(`((?:[!@*<~\\w+:_-]|\\[&?>?:?\\S*\\])+?)(${key})\\(((?:[~!<>\\w\\s:/\\\\,%#.$?-]|\\[[^\\]]*?\\])+?)\\)(?!\\s*?=>)`, 'gm')
1111
regexCache[key].lastIndex = 0
1212
return regexCache[key]
1313
}
@@ -55,7 +55,7 @@ export function parseVariantGroup(str: string | MagicString, separators = ['-',
5555
}
5656
for (const item of innerItems) {
5757
item.className = item.className === '~'
58-
? pre
58+
? (sep === ':' ? `${pre}${sep}~` : pre)
5959
: item.className.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)
6060
group.items.push(item)
6161
}

packages-engine/core/test/variant-group.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ describe('variant-group', () => {
3737
expect(expandVariantGroup('[&]:(a-b c-d)')).toEqual('[&]:a-b [&]:c-d')
3838
})
3939

40+
it('asterisk with tilde', async () => {
41+
// `*` is the children variant shorthand (issue: #5099)
42+
expect(expandVariantGroup('*:(~ a-b)')).toEqual('*:~ *:a-b')
43+
})
44+
4045
it('expand with space', async () => {
4146
const shortcut = ' a:(b:(c-d d-c)) '
4247
expect(expandVariantGroup(shortcut)).toEqual(' a:b:c-d a:b:d-c ')

0 commit comments

Comments
 (0)