Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fix for svelte extractor (#1830)
- Loading branch information
1 parent
73d00d6
commit 52a71f4
Showing
2 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
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,45 @@ | ||
import { extractorSplit } from '@unocss/core' | ||
import { extractorSplit, extractorSvelte } from '@unocss/core' | ||
import { expect, it } from 'vitest' | ||
|
||
it('extractorSplit', async () => { | ||
let code = '' | ||
async function extract() { | ||
async function extract(code: string) { | ||
return [...await extractorSplit.extract({ code, original: code }) || []] | ||
} | ||
|
||
code = 'foo' | ||
expect(await extract()).eql(['foo']) | ||
expect(await extract('foo')).eql(['foo']) | ||
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red') | ||
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg') | ||
expect(await extract('"class=\"bg-white\""')).toContain('bg-white') | ||
}) | ||
|
||
it('extractorSvelte uses regular split with non .svelte files', async () => { | ||
async function extract(code: string) { | ||
return [...await extractorSvelte.extract({ code, original: code }) || []] | ||
} | ||
|
||
expect(await extract('foo')).eql(['foo']) | ||
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red') | ||
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg') | ||
expect(await extract('"class=\"bg-white\""')).toContain('bg-white') | ||
|
||
code = '<div class="text-red border">foo</div>' | ||
expect(await extract()).toContain('text-red') | ||
expect(await extract('<div class:text-orange-400={foo} />')).toContain('class:text-orange-400=') | ||
expect(await extract('class:text-gray-800={$page.url.pathname.startsWith(\'/test\')}')).toContain('class:text-gray-800=') | ||
expect(await extract('<div class="data-[a~=b]:text-red">foo</div>')).toContain('data-[a~=b]:text-red') | ||
expect(await extract('<div class:text-[32px]="{true}" />')).toContain('class:text-[32px]=') | ||
}) | ||
|
||
it('extractorSvelte uses svelte-specific split with .svelte files', async () => { | ||
async function extract(code: string) { | ||
return [...await extractorSvelte.extract({ code, original: code, id: 'file.svelte' }) || []] | ||
} | ||
|
||
code = '<div class="<sm:text-lg">foo</div>' | ||
expect(await extract()).toContain('<sm:text-lg') | ||
expect(await extract('foo')).eql(['foo']) | ||
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red') | ||
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg') | ||
expect(await extract('"class=\"bg-white\""')).toContain('bg-white') | ||
|
||
code = '"class=\"bg-white\""' | ||
expect(await extract()).toContain('bg-white') | ||
expect(await extract('<div class:text-orange-400={foo} />')).toContain('text-orange-400') | ||
expect(await extract('class:text-gray-800={$page.url.pathname.startsWith(\'/test\')}')).toContain('text-gray-800') | ||
expect(await extract('<div class="data-[a~=b]:text-red">foo</div>')).toContain('data-[a~=b]:text-red') | ||
expect(await extract('<div class:text-[32px]="{true}" />')).toContain('text-[32px]') | ||
}) |