Skip to content

Commit

Permalink
fix(transformer-attributify-jsx): improve attribute capturing (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Mar 8, 2023
1 parent 4c49ff7 commit 5d472fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/transformer-attributify-jsx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface TransformerAttributifyJsxOptions {
exclude?: FilterPattern
}

const elementRE = /<([^>\s]*\s)((?:'.*?'|".*?"|`.*?`|\{.*?\}|[^>]*?)*)/g
const elementRE = /(<\w[\w:\.$-]*\s)((?:'[^>]*?'|"[^>]*?"|`(?:[^>]|[\S])*?`|\{(?:[^>]|[\S])*?\}|[^>]*?)*)/g
const attributeRE = /([a-zA-Z()#][\[?a-zA-Z0-9-_:()#%\]?]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g
const valuedAttributeRE = /((?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-.~<]+)=(?:["]([^"]*)["]|[']([^']*)[']|[{]((?:[`(](?:[^`)]*)[`)]|[^}])+)[}])/gms

Expand Down Expand Up @@ -85,7 +85,7 @@ export default function transformerAttributifyJsx(options: TransformerAttributif
tasks.push(uno.parseToken(matchedRule).then((matched) => {
if (matched) {
const tag = item[1]
const startIdx = (item.index || 0) + (attr.index || 0) + tag.length + 1
const startIdx = (item.index || 0) + (attr.index || 0) + tag.length
const endIdx = startIdx + matchedRule.length
code.overwrite(startIdx, endIdx, `${matchedRule}=""`)
}
Expand Down
15 changes: 15 additions & 0 deletions test/transformer-attributify-jsx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('transformerAttributifyJs', () => {
mr-10
className={cn({ 'c-red': variable > 0 }, 'mr-10')}
></section>
<div
label={
<b>1</b>
}
></div>
<div absolute bottom-5 right-0 left-0 text-center op30 fw300>
on-demand · instant · fully customizable
</div>
Expand Down Expand Up @@ -72,6 +77,11 @@ describe('transformerAttributifyJs', () => {
mr-10=\\"\\"
className={cn({ 'c-red': variable > 0 }, 'mr-10')}
></section>
<div
label={
<b>1</b>
}
></div>
<div absolute=\\"\\" bottom-5=\\"\\" right-0=\\"\\" left-0=\\"\\" text-center=\\"\\" op30=\\"\\" fw300=\\"\\">
on-demand · instant · fully customizable
</div>"
Expand Down Expand Up @@ -111,6 +121,11 @@ describe('transformerAttributifyJs', () => {
mr-10=\\"\\"
className={cn({ 'c-red': variable > 0 }, 'mr-10')}
></section>
<div
label={
<b>1</b>
}
></div>
<div absolute bottom-5=\\"\\" right-0=\\"\\" left-0=\\"\\" text-center=\\"\\" op30=\\"\\" fw300=\\"\\">
on-demand · instant · fully customizable
</div>"
Expand Down

0 comments on commit 5d472fa

Please sign in to comment.