@@ -39,10 +39,19 @@ export function handleAttribute(
39
39
htmlx : string ,
40
40
str : MagicString ,
41
41
attr : Attribute ,
42
- parent : BaseNode
42
+ parent : BaseNode ,
43
+ preserveCase : boolean
43
44
) : void {
44
45
let transformedFromDirectiveOrNamespace = false ;
45
46
47
+ const transformAttributeCase = ( name : string ) => {
48
+ if ( ! preserveCase && ! svgAttributes . find ( ( x ) => x == name ) ) {
49
+ return name . toLowerCase ( ) ;
50
+ } else {
51
+ return name ;
52
+ }
53
+ } ;
54
+
46
55
//if we are on an "element" we are case insensitive, lowercase to match our JSX
47
56
if ( parent . type == 'Element' ) {
48
57
const sapperLinkActions = [ 'sapper:prefetch' , 'sapper:noscroll' ] ;
@@ -58,10 +67,7 @@ export function handleAttribute(
58
67
sapperLinkActions . includes ( attr . name ) ||
59
68
sveltekitLinkActions . includes ( attr . name )
60
69
) {
61
- let name = attr . name ;
62
- if ( ! svgAttributes . find ( ( x ) => x == name ) ) {
63
- name = name . toLowerCase ( ) ;
64
- }
70
+ let name = transformAttributeCase ( attr . name ) ;
65
71
66
72
//strip ":" from out attribute name and uppercase the next letter to convert to jsx attribute
67
73
const colonIndex = name . indexOf ( ':' ) ;
@@ -83,7 +89,7 @@ export function handleAttribute(
83
89
! transformedFromDirectiveOrNamespace &&
84
90
parent . name !== '!DOCTYPE'
85
91
) {
86
- str . overwrite ( attr . start , attr . end , attr . name . toLowerCase ( ) ) ;
92
+ str . overwrite ( attr . start , attr . end , transformAttributeCase ( attr . name ) ) ;
87
93
}
88
94
return ;
89
95
}
@@ -101,10 +107,7 @@ export function handleAttribute(
101
107
if ( attrVal . type == 'AttributeShorthand' ) {
102
108
let attrName = attrVal . expression . name ;
103
109
if ( parent . type == 'Element' ) {
104
- // eslint-disable-next-line max-len
105
- attrName = svgAttributes . find ( ( a ) => a == attrName )
106
- ? attrName
107
- : attrName . toLowerCase ( ) ;
110
+ attrName = transformAttributeCase ( attrName ) ;
108
111
}
109
112
110
113
str . appendRight ( attr . start , `${ attrName } =` ) ;
0 commit comments