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(attributify-jsx): support rewriting colon operator #1524

Merged
merged 2 commits into from Sep 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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