@@ -39,8 +39,8 @@ export interface TransformerAttributifyJsxOptions {
39
39
40
40
const elementRE = / < ( [ ^ > \s ] * \s ) ( (?: ' .* ?' | " .* ?" | ` .* ?` | \{ .* ?\} | [ ^ > ] * ?) * ) / g
41
41
const attributeRE = / ( [ a - z A - Z ( ) # ] [ \[ ? a - z A - Z 0 - 9 - _ : ( ) # % \] ? ] * ) (?: \s * = \s * ( (?: ' [ ^ ' ] * ' ) | (?: " [ ^ " ] * " ) | \S + ) ) ? / g
42
- const classFilterRE = / ( c l a s s N a m e | c l a s s ) \s * = \s * \{ [ ^ \} ] * \} / i
43
- const curlybraceRE = / \w + \s ? = \s ? \{ . + ? \} / g
42
+ const valuedAttributeRE = / ( (? ! \d | - { 2 } | - \d ) [ a - z A - Z 0 - 9 \u00A0 - \uFFFF - _ : ! % - . ~ < ] + ) = (?: [ " ] ( [ ^ " ] * ) [ " ] | [ ' ] ( [ ^ ' ] * ) [ ' ] | [ { ] ( (?: [ ` ( ] (?: [ ^ ` ) ] * ) [ ` ) ] | [ ^ } ] ) + ) [ } ] ) / gms
43
+
44
44
export default function transformerAttributifyJsx ( options : TransformerAttributifyJsxOptions = { } ) : SourceCodeTransformer {
45
45
const {
46
46
blocklist = [ ] ,
@@ -74,12 +74,9 @@ export default function transformerAttributifyJsx(options: TransformerAttributif
74
74
75
75
for ( const item of Array . from ( code . original . matchAll ( elementRE ) ) ) {
76
76
// Get the length of the className part, and replace it with the equal length of empty string
77
- const classNamePart = item [ 2 ] . match ( classFilterRE )
78
77
let attributifyPart = item [ 2 ]
79
- if ( classNamePart )
80
- attributifyPart = item [ 2 ] . replace ( classFilterRE , ' ' . repeat ( classNamePart [ 0 ] . length ) )
81
- if ( curlybraceRE . test ( attributifyPart ) )
82
- attributifyPart = attributifyPart . replace ( curlybraceRE , match => ' ' . repeat ( match . length ) )
78
+ if ( valuedAttributeRE . test ( attributifyPart ) )
79
+ attributifyPart = attributifyPart . replace ( valuedAttributeRE , match => ' ' . repeat ( match . length ) )
83
80
for ( const attr of attributifyPart . matchAll ( attributeRE ) ) {
84
81
const matchedRule = attr [ 0 ] . replace ( / \: / i, '-' )
85
82
if ( matchedRule . includes ( '=' ) || isBlocked ( matchedRule ) )
0 commit comments