Skip to content

Commit d9e8948

Browse files
authored
fix: preserve event attribute casing in svelte 5 (#2347)
#2345
1 parent 957b8d6 commit d9e8948

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/svelte2tsx/src/htmlxtojsx_v2/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export function convertHtmlxToJsx(
179179
node as Attribute,
180180
parent,
181181
options.preserveAttributeCase,
182+
options.svelte5Plus,
182183
element
183184
);
184185
break;
@@ -189,7 +190,14 @@ export function convertHtmlxToJsx(
189190
handleEventHandler(str, node as BaseDirective, element);
190191
break;
191192
case 'Let':
192-
handleLet(str, node, parent, options.preserveAttributeCase, element);
193+
handleLet(
194+
str,
195+
node,
196+
parent,
197+
options.preserveAttributeCase,
198+
options.svelte5Plus,
199+
element
200+
);
193201
break;
194202
case 'Text':
195203
handleText(str, node as Text, parent);

packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function handleAttribute(
5555
attr: Attribute,
5656
parent: BaseNode,
5757
preserveCase: boolean,
58+
svelte5Plus: boolean,
5859
element: Element | InlineComponent
5960
): void {
6061
if (
@@ -112,7 +113,8 @@ export function handleAttribute(
112113
if (
113114
!preserveCase &&
114115
!svgAttributes.find((x) => x == name) &&
115-
!(element instanceof Element && element.tagName.includes('-'))
116+
!(element instanceof Element && element.tagName.includes('-')) &&
117+
!(svelte5Plus && name.startsWith('on'))
116118
) {
117119
return name.toLowerCase();
118120
} else {

packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Let.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function handleLet(
1515
node: BaseNode,
1616
parent: BaseNode,
1717
preserveCase: boolean,
18+
svelte5Plus: boolean,
1819
element: Element | InlineComponent
1920
): void {
2021
if (element instanceof InlineComponent) {
@@ -47,6 +48,7 @@ export function handleLet(
4748
},
4849
parent,
4950
preserveCase,
51+
svelte5Plus,
5052
element
5153
);
5254
}

0 commit comments

Comments
 (0)