Skip to content

Commit bbdd425

Browse files
giaBaoJSautofix-ci[bot]zyyv
authored
fix(extractor-arbitrary-variants): extract quoted attribute selectors behind class and pseudo-class prefixes (#5285)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Chris <hizyyv@gmail.com>
1 parent 3945ca8 commit bbdd425

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

packages-presets/extractor-arbitrary-variants/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { restoreSkipCode, transformSkipCode } from '#integration/utils'
44
import { removeSourceMap } from './source-map'
55

66
export const quotedArbitraryValuesRE
7-
= /(?:[\w&:[\]-]|\[\S{1,64}=\S{1,64}\]){1,64}\[\\?['"]?\S{1,64}?['"]\]\]?[\w:-]{0,64}/g
7+
= /(?:[\w&:[\].(-]|\[\S{1,64}=\S{1,64}\]){1,64}\[\\?['"]?\S{1,64}?['"]\](?:\)?\])?[\w:-]{0,64}/g
88

99
export const arbitraryPropertyRE
1010
= /\[(\\\W|[\w-]){1,64}:[^\s:]{0,64}?("\S{1,64}?"|'\S{1,64}?'|`\S{1,64}?`|[^\s:]{1,64}?)[^\s:]{0,64}?\)?\]/g

packages-presets/extractor-arbitrary-variants/test/extractor-arbitrary-variants.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFile } from 'node:fs/promises'
22
import { describe, expect, it } from 'vitest'
3-
import { quotedArbitraryValuesRE } from '../src/index'
3+
import { quotedArbitraryValuesRE, splitCodeWithArbitraryVariants } from '../src/index'
44
import { removeSourceMap } from '../src/source-map'
55

66
describe('removeSourceMap()', () => {
@@ -24,3 +24,30 @@ describe('quotedArbitraryValuesRE', () => {
2424
quotedArbitraryValuesRE.test(code)
2525
})
2626
})
27+
28+
describe('splitCodeWithArbitraryVariants()', () => {
29+
it('extracts quoted attribute selectors behind a class or pseudo-class prefix', () => {
30+
const code = [
31+
`<div class='[&_.recharts-cartesian-grid_line[stroke="#ccc"]]:hidden'></div>`,
32+
`<button class="[&_svg:not([class*='size-'])]:size-4"></button>`,
33+
].join('\n')
34+
35+
expect(splitCodeWithArbitraryVariants(code)).toEqual(
36+
expect.arrayContaining([
37+
'[&_.recharts-cartesian-grid_line[stroke="#ccc"]]:hidden',
38+
`[&_svg:not([class*='size-'])]:size-4`,
39+
]),
40+
)
41+
})
42+
43+
it('keeps extracting quoted attribute selectors without such a prefix', () => {
44+
const code = `<div class='[&_[stroke="#ccc"]]:hidden [&_tag[stroke="#ccc"]]:hidden'></div>`
45+
46+
expect(splitCodeWithArbitraryVariants(code)).toEqual(
47+
expect.arrayContaining([
48+
'[&_[stroke="#ccc"]]:hidden',
49+
'[&_tag[stroke="#ccc"]]:hidden',
50+
]),
51+
)
52+
})
53+
})

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo