Skip to content

Commit

Permalink
fix(jsx): ObjectExpression transform
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Jan 20, 2024
1 parent 0e0258b commit 2f9685e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"properties": {
"tailwindMagic.variantGroup": {
"type": "boolean",
"default": false,
"default": true,
"description": "Enable/disable transform hover:(x1 x2) to hover:x1 hover:x2"
},
"tailwindMagic.strictMode": {
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"properties": {
"tailwindMagic.variantGroup": {
"type": "boolean",
"default": false,
"default": true,
"description": "Enable/disable transform hover:(x1 x2) to hover:x1 hover:x2"
},
"tailwindMagic.strictMode": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"properties": {
"tailwindMagic.variantGroup": {
"type": "boolean",
"default": false,
"default": true,
"description": "Enable/disable transform hover:(x1 x2) to hover:x1 hover:x2"
},
"tailwindMagic.strictMode": {
Expand Down
40 changes: 38 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { transform, transformClass } from '../src/transform'
import { transform, transformClass, transformClassAttr } from '../src/transform'

describe('should', () => {
it('exported', () => {
Expand Down Expand Up @@ -289,10 +289,12 @@ describe('should', () => {
transform('class="md:(w10px h20px)"')).toMatchInlineSnapshot('"class=\\"md:w-[10px] md:h-[20px]\\""')
expect(
transform('class="hover:(text-red bg-blue)"')).toMatchInlineSnapshot('"class=\\"hover:text-red hover:bg-blue\\""')
expect(
transform('className="hover:(text-red bg-blue)"')).toMatchInlineSnapshot('"className=\\"hover:text-red hover:bg-blue\\""')
expect(
transformClass('hover:(text-red bg-blue)"')).toMatchInlineSnapshot('"hover:text-red hover:bg-blue\\""')
expect(
transformClass('hover:(flex-center)')).toMatchInlineSnapshot('"hover:flex hover:justify-center hover:items-center"')
transformClass('hover:(text-red bg-blue)')).toMatchInlineSnapshot('"hover:text-red hover:bg-blue"')
expect(
transformClass('md:(flex-center)')).toMatchInlineSnapshot('"md:flex md:justify-center md:items-center"')
expect(
Expand All @@ -302,6 +304,40 @@ describe('should', () => {
})
})

describe('transformClassAttr', () => {
it('transformClassAttr', async () => {
expect(await transformClassAttr([{
content: 'hover:(text-red bg-blue)',
line: 0,
charater: 0,
end: {
column: 0,
line: 0,
},
start: {
column: 0,
line: 0,
},
}])).toMatchInlineSnapshot(`
[
{
"content": "hover:text-red hover:bg-blue",
"end": {
"column": 0,
"line": 0,
},
"node": undefined,
"raw": "hover:(text-red bg-blue)",
"start": {
"column": 0,
"line": 0,
},
},
]
`)
})
})

describe('transformClass', () => {
it('transformClass', () => {
expect(transformClass('[\n isDarkBg && \'bg-[#0A0B0D]\',\n isSinglePage ? \'\' : \'pt-[64px]\',\n isShowTabs && editableTabs.length > 0 ?\'mt40px\':\'\'\n ]')).toMatchInlineSnapshot(`
Expand Down

0 comments on commit 2f9685e

Please sign in to comment.