Skip to content

Commit

Permalink
feat(extractor): split backslash (#1371)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
XiNiHa and antfu committed Aug 4, 2022
1 parent 99212eb commit da90c6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/extractors/split.ts
@@ -1,7 +1,7 @@
import type { Extractor } from '../types'
import { isValidSelector } from '../utils'

export const splitCode = (code: string) => code.split(/[\s'"`;=]+/g).filter(isValidSelector)
export const splitCode = (code: string) => code.split(/\\?[\s'"`;=]+/g).filter(isValidSelector)

export const extractorSplit: Extractor = {
name: 'split',
Expand Down
21 changes: 21 additions & 0 deletions test/extractor.test.ts
@@ -0,0 +1,21 @@
import { extractorSplit } from '@unocss/core'
import { expect, it } from 'vitest'

it('extractorSplit', async () => {
let code = ''
async function extract() {
return [...await extractorSplit.extract({ code, original: code }) || []]
}

code = 'foo'
expect(await extract()).eql(['foo'])

code = '<div class="text-red border">foo</div>'
expect(await extract()).toContain('text-red')

code = '<div class="<sm:text-lg">foo</div>'
expect(await extract()).toContain('<sm:text-lg')

code = '"class=\"bg-white\""'
expect(await extract()).toContain('bg-white')
})

0 comments on commit da90c6b

Please sign in to comment.