Skip to content

Commit

Permalink
fix(core): trim input to reduce loop number
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyv committed Sep 28, 2022
1 parent 2d2c631 commit 9b2dc77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export class UnoGenerator {

// expand nested shortcuts
if (isString(result))
result = expandVariantGroup(result).split(/\s+/g)
result = expandVariantGroup(result.trim()).split(/\s+/g)

// expand nested shortcuts with variants
if (!result) {
Expand Down
11 changes: 11 additions & 0 deletions test/variant-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ describe('variant-group', () => {
test('square bracket case2', async () => {
expect(expandVariantGroup('[&]:(a-b c-d)')).toEqual('[&]:a-b [&]:c-d')
})

test('expand with space', async () => {
const shortcut = ' a:(b:(c-d d-c)) '
expect(expandVariantGroup(shortcut)).toEqual(' a:b:c-d a:b:d-c ')
expect(expandVariantGroup(shortcut.trim()).split(/\s+/g)).toMatchInlineSnapshot(`
[
"a:b:c-d",
"a:b:d-c",
]
`)
})
})

0 comments on commit 9b2dc77

Please sign in to comment.