Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add prefix handling for shortcuts #4

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function transformAlias(
if (typeof keep === 'string')
keep = { prefix: keep, block: true }

const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep.prefix)})([\\w-]+)`, 'g')
const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep.prefix)})([\\w-:]+)`, 'g')
const map = new Map<string, ShortcutValue | false>()

for (const item of Array.from(code.original.matchAll(extraRE))) {
Expand Down
11 changes: 11 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const uno = createGenerator({
shortcuts: [
['btn', 'text-(white xl) font-bold py-2 px-4 rounded cursor-pointer'],
[/^btn-(.+)$/, ([,d]) => `bg-${d}-500 hover:bg-${d}-700 btn`],
[/^tapped:(.*)$/, ([, c]) => `hover:${c} active:${c}`],
],
})

Expand All @@ -31,6 +32,7 @@ describe('transformer alias', () => {
<div *btn>
<div text-xl class="*btn-red" />
<div *btn-teal />
<div text-red *tapped:text-blue />
</div>
</template>
`.trim()
Expand All @@ -40,6 +42,7 @@ describe('transformer alias', () => {
<div text-white text-xl font-bold py-2 px-4 rounded cursor-pointer>
<div text-xl class="bg-red-500 hover:bg-red-700 text-white text-xl font-bold py-2 px-4 rounded cursor-pointer" />
<div bg-teal-500 hover:bg-teal-700 text-white text-xl font-bold py-2 px-4 rounded cursor-pointer />
<div text-red hover:text-blue active:text-blue />
</div>
</template>"
`)
Expand All @@ -53,6 +56,8 @@ describe('transformer alias', () => {
<div &test-none>
<div text-xl class="&btn-red" />
<div *btn-red />
<div *tapped:text-blue />
<div &tapped:text-blue />
</div>
</template>
`.trim()
Expand All @@ -62,6 +67,8 @@ describe('transformer alias', () => {
<div &test-none>
<div text-xl class="bg-red-500 hover:bg-red-700 text-white text-xl font-bold py-2 px-4 rounded cursor-pointer" />
<div *btn-red />
<div *tapped:text-blue />
<div hover:text-blue active:text-blue />
</div>
</template>"
`)
Expand All @@ -72,6 +79,8 @@ describe('transformer alias', () => {
<template>
<div class="*btn-red" />
<div *btn-red />
<div class="*tapped:text-blue" />
<div *tapped:text-blue />
</template>
`.trim()
const transform = createTransformer()
Expand All @@ -80,6 +89,8 @@ describe('transformer alias', () => {
"<template>
<div class="bg-red-500 hover:bg-red-700 text-white text-xl font-bold py-2 px-4 rounded cursor-pointer" />
<div bg-red-500 hover:bg-red-700 text-white text-xl font-bold py-2 px-4 rounded cursor-pointer />
<div class="hover:text-blue active:text-blue" />
<div hover:text-blue active:text-blue />
</template>"
`)

Expand Down
Loading