Skip to content

Commit

Permalink
fix(variant-group): magic string error
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 25, 2022
1 parent 47a0905 commit 08c7117
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/core/src/utils/variantGroup.ts
Expand Up @@ -2,9 +2,9 @@ import type MagicString from 'magic-string'

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

export function expandVariantGroup(str: string, seperators?: ('-' | ':')[]): string
export function expandVariantGroup(str: MagicString, seperators?: ('-' | ':')[]): MagicString
export function expandVariantGroup(str: string | MagicString, seperators: ('-' | ':')[] = ['-', ':']) {
export function expandVariantGroup(str: string, seperators?: string[], depth?: number): string
export function expandVariantGroup(str: MagicString, seperators?: string[], depth?: number): MagicString
export function expandVariantGroup(str: string | MagicString, seperators = ['-', ':'], depth = 5) {
regexClassGroup.lastIndex = 0
let hasChanged = false
let content = str.toString()
Expand All @@ -23,10 +23,15 @@ export function expandVariantGroup(str: string | MagicString, seperators: ('-' |
},
)
hasChanged = content !== before
} while (hasChanged)
depth -= 1
} while (hasChanged && depth)

if (typeof str === 'string')
if (typeof str === 'string') {
return content
else
return str.overwrite(0, str.length(), content)
}
else {
return str.length()
? str.overwrite(0, str.length(), content)
: str
}
}

0 comments on commit 08c7117

Please sign in to comment.