Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(variant-group)!: remove quotes matching, add option to config sep…
…erator (#1231) Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
- Loading branch information
Showing
6 changed files
with
40 additions
and
215 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,21 +1,30 @@ | ||
import type { SourceCodeTransformer } from '@unocss/core' | ||
import { expandVariantGroup, extractQuoted } from '@unocss/core' | ||
import { expandVariantGroup } from '@unocss/core' | ||
|
||
export default function transformerVariantGroup(): SourceCodeTransformer { | ||
export interface TransformerVariantGroupOptions { | ||
/** | ||
* Separators to expand. | ||
* | ||
* ``` | ||
* foo-(bar baz) -> foo-bar foo-baz | ||
* ^ | ||
* separator | ||
* ``` | ||
* | ||
* You may set it to `[':']` for strictness. | ||
* | ||
* @default [':', '-'] | ||
* @see https://github.com/unocss/unocss/pull/1231 | ||
*/ | ||
separators?: (':' | '-')[] | ||
} | ||
|
||
export default function transformerVariantGroup(options: TransformerVariantGroupOptions = {}): SourceCodeTransformer { | ||
return { | ||
name: 'variant-group', | ||
enforce: 'pre', | ||
transform(s) { | ||
extractQuoted( | ||
s.toString(), | ||
{ | ||
details: true, | ||
templateStaticOnly: true, | ||
deep: true, | ||
}, | ||
) | ||
.filter(({ value: { length } }) => length) | ||
.forEach(({ value, range }) => s.overwrite(...range, expandVariantGroup(value))) | ||
expandVariantGroup(s, options.separators) | ||
}, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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