Skip to content

Commit

Permalink
feat(attributify-jsx): support rewriting colon operator (#1524)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flower-F committed Sep 2, 2022
1 parent 1e68d33 commit b7270ef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions packages/transformer-attributify-jsx/README.md
Expand Up @@ -73,8 +73,6 @@ export default defineConfig({
```html
<div translate-x-100% /> <!-- cannot end with `%` -->

<div hover:text-2xl /> <!-- cannot contain `:` -->

<div translate-x-[100px] /> <!-- cannot contain `[` or `]` -->
```

Expand All @@ -83,8 +81,6 @@ Instead, you may want to use valued attributes instead:
```html
<div translate="x-100%" />

<div hover="text-2xl" />

<div translate="x-[100px]" />
```

Expand Down
2 changes: 1 addition & 1 deletion packages/transformer-attributify-jsx/src/index.ts
Expand Up @@ -73,7 +73,7 @@ export default function transformerAttributifyJsx(options: TransformerAttributif

for (const item of Array.from(code.original.matchAll(elementRE))) {
for (const attr of item[3].matchAll(attributeRE)) {
const matchedRule = attr[0]
const matchedRule = attr[0].replace(/\:/i, '-')
if (matchedRule.includes('=') || isBlocked(matchedRule))
continue

Expand Down
12 changes: 6 additions & 6 deletions test/transformer-attributify-jsx.test.ts
Expand Up @@ -15,7 +15,7 @@ describe('transformerAttributifyJs', () => {
<div op30 text-lg fw300 m1>
The instant on-demand Atomic CSS engine.
</div>
<div m2 flex justify-center text-2xl op30 hover="op80">
<div m2 flex justify-center text-2xl op30 hover:op80 hover:text-2xl>
<a
i-carbon-logo-github
text-inherit
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('transformerAttributifyJs', () => {
<div op30=\\"\\" text-lg=\\"\\" fw300=\\"\\" m1=\\"\\">
The instant on-demand Atomic CSS engine.
</div>
<div m2=\\"\\" flex=\\"\\" justify-center=\\"\\" text-2xl=\\"\\" op30=\\"\\" hover=\\"op80\\">
<div m2=\\"\\" flex=\\"\\" justify-center=\\"\\" text-2xl=\\"\\" op30=\\"\\" hover-op80=\\"\\" hover-text-2xl=\\"\\">
<a
i-carbon-logo-github
text-inherit=\\"\\"
Expand All @@ -68,7 +68,7 @@ describe('transformerAttributifyJs', () => {

test('blocklist', async () => {
const code = new MagicString(originalCode)
const blocklist = ['flex', 'absolute', /op[0-9]+/]
const blocklist: (string | RegExp)[] = ['flex', 'absolute']

await transformerAttributifyJsx({
blocklist,
Expand All @@ -80,10 +80,10 @@ describe('transformerAttributifyJs', () => {
<div text-5xl=\\"\\" fw100=\\"\\" animate-bounce-alt=\\"\\" animate-count-infinite=\\"\\" animate-duration-1s=\\"\\">
unocss
</div>
<div op30 text-lg=\\"\\" fw300=\\"\\" m1=\\"\\">
<div op30=\\"\\" text-lg=\\"\\" fw300=\\"\\" m1=\\"\\">
The instant on-demand Atomic CSS engine.
</div>
<div m2=\\"\\" flex justify-center=\\"\\" text-2xl=\\"\\" op30 hover=\\"op80\\">
<div m2=\\"\\" flex justify-center=\\"\\" text-2xl=\\"\\" op30=\\"\\" hover-op80=\\"\\" hover-text-2xl=\\"\\">
<a
i-carbon-logo-github
text-inherit=\\"\\"
Expand All @@ -93,7 +93,7 @@ describe('transformerAttributifyJs', () => {
</div>
</div>
</div>
<div absolute bottom-5=\\"\\" right-0=\\"\\" left-0=\\"\\" text-center=\\"\\" op30 fw300=\\"\\">
<div absolute bottom-5=\\"\\" right-0=\\"\\" left-0=\\"\\" text-center=\\"\\" op30=\\"\\" fw300=\\"\\">
on-demand · instant · fully customizable
</div>"
`)
Expand Down

0 comments on commit b7270ef

Please sign in to comment.