From 5db3f872ff96d30cf39aae531896ed02e0b6ff5e Mon Sep 17 00:00:00 2001 From: Jayce Jones Date: Wed, 24 Apr 2024 10:07:32 -0500 Subject: [PATCH] Preserve event attribute casing in svelte 5 --- packages/svelte2tsx/src/htmlxtojsx_v2/index.ts | 10 +++++++++- .../svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts | 4 +++- packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Let.ts | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/index.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/index.ts index 8d297520c..406ed7589 100644 --- a/packages/svelte2tsx/src/htmlxtojsx_v2/index.ts +++ b/packages/svelte2tsx/src/htmlxtojsx_v2/index.ts @@ -178,6 +178,7 @@ export function convertHtmlxToJsx( node as Attribute, parent, options.preserveAttributeCase, + options.svelte5Plus, element ); break; @@ -188,7 +189,14 @@ export function convertHtmlxToJsx( handleEventHandler(str, node as BaseDirective, element); break; case 'Let': - handleLet(str, node, parent, options.preserveAttributeCase, element); + handleLet( + str, + node, + parent, + options.preserveAttributeCase, + options.svelte5Plus, + element + ); break; case 'Text': handleText(str, node as Text, parent); diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts index ff29f73ad..12f3396ee 100644 --- a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts +++ b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts @@ -55,6 +55,7 @@ export function handleAttribute( attr: Attribute, parent: BaseNode, preserveCase: boolean, + svelte5Plus: boolean, element: Element | InlineComponent ): void { if ( @@ -112,7 +113,8 @@ export function handleAttribute( if ( !preserveCase && !svgAttributes.find((x) => x == name) && - !(element instanceof Element && element.tagName.includes('-')) + !(element instanceof Element && element.tagName.includes('-')) && + !(svelte5Plus && name.startsWith('on')) ) { return name.toLowerCase(); } else { diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Let.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Let.ts index 1848f6a63..579001ea0 100644 --- a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Let.ts +++ b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Let.ts @@ -15,6 +15,7 @@ export function handleLet( node: BaseNode, parent: BaseNode, preserveCase: boolean, + svelte5Plus: boolean, element: Element | InlineComponent ): void { if (element instanceof InlineComponent) { @@ -47,6 +48,7 @@ export function handleLet( }, parent, preserveCase, + svelte5Plus, element ); }