Skip to content

Commit

Permalink
fix: wrong transform
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Oct 16, 2024
1 parent b27544c commit d6eb8e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ export const rules: any = [
[/([\s'])contain([\s'!]|$)/, (_: string, v1: string, v2: string) => `${v1}bg-contain${v2}`],
[/([\s'])cover([\s'!]|$)/, (_: string, v1: string, v2: string) => `${v1}bg-cover${v2}`],
[/([\s'])line(\d+)([\s'!]|$)/, (_: string, v1: string, v2: string, v3: string) => `${v1}line-clamp-${v2}${v3}`],
[/([\s!])\(([^)]+)\)([\s'!]|$)/, (_: string, v1: string, v2: string, v3: string) => v2.replace(/\s+/g, ' ').split(' ').map(item => `!${item}`).join(' ') + v3],
[/([\s!])\(([^)]+)\)([\s'!]|$)/, (_: string, v1: string, v2: string, v3: string) => {
if (v1 === '!')
return v2.replace(/\s+/g, ' ').split(' ').map(item => `!${item}`).join(' ') + v3
if (v3 === '!')
return v2.replace(/\s+/g, ' ').split(' ').map(item => `!${item}`).join(' ')
return _
}],
].filter(Boolean)

export function transform(content: string) {
Expand Down
1 change: 1 addition & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@ describe('should', () => {
it('magic transformClass w!', () => {
expect(transformClass('<div class=" w10!" >')).toMatchInlineSnapshot('"<div class=\\" w-[10]!\\" >"')
expect(transformClass('<div class=" minw10px!" >')).toMatchInlineSnapshot('"<div class=\\" min-w-[10px]!\\" >"')
expect(transformClass('{ active: modelValue === (tab.name || index) }')).toMatchInlineSnapshot('"{ active: modelValue === (tab.name || index) }"')
})
})

0 comments on commit d6eb8e2

Please sign in to comment.