Repository: sveltejs/language-tools
Pull request #1357 (2022-01-31 09:02:25)

(fix) svg attributes and casing
- move "xml:.." attributes into svg attributes interface
- remove quotes from attribute completions
- lowercase attributes when they are case insensitive

#1352


Patch:
diff --git a/packages/language-server/src/plugins/PluginHost.ts b/packages/language-server/src/plugins/PluginHost.ts
index 6ac84c1b..8a31aff6 100644
--- a/packages/language-server/src/plugins/PluginHost.ts
+++ b/packages/language-server/src/plugins/PluginHost.ts
@@ -141,7 +141,9 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
                     return false;
                 }
                 if (label[0] === '"' && label[label.length - 1] === '"') {
-                    if (htmlCompletions.has(label.slice(1, -1))) {
+                    // this will result in a wrong completion regardless, remove the quotes
+                    item.label = item.label.slice(1, -1);
+                    if (htmlCompletions.has(item.label)) {
                         // "aria-label" -> aria-label -> exists in html completions
                         return false;
                     }
diff --git a/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts b/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts
index 1189eb73..b0f172f4 100644
--- a/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts
+++ b/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts
@@ -77,7 +77,7 @@ export class SemanticTokensProviderImpl implements SemanticTokensProvider {
                 continue;
             }
 
-            const [line, character, length, start] = originalPosition;
+            const [line, character, length] = originalPosition;
 
             // remove identifiers whose start and end mapped to the same location,
             // like the svelte2tsx inserted render function,
diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts
index cfbc3435..7c4cd4e2 100644
--- a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts
+++ b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts
@@ -111,7 +111,7 @@ export function handleAttribute(
         return;
     } else {
         let name =
-            element instanceof Element && attr.value === true
+            element instanceof Element && parent.type === 'Element'
                 ? transformAttributeCase(attr.name)
                 : attr.name;
         // surround with quotes because dashes or other invalid property characters could be part of the name
diff --git a/packages/svelte2tsx/svelte-jsx.d.ts b/packages/svelte2tsx/svelte-jsx.d.ts
index 033bb9f4..fbaf4ce0 100644
--- a/packages/svelte2tsx/svelte-jsx.d.ts
+++ b/packages/svelte2tsx/svelte-jsx.d.ts
@@ -68,7 +68,10 @@ declare namespace svelteHTML {
   interface AriaAttributes extends svelte.JSX.AriaAttributes {}
 
   // eslint-disable-next-line @typescript-eslint/no-empty-interface
-  interface HTMLAttributes<T extends EventTarget> extends svelte.JSX.HTMLAttributes<T> {
+  interface HTMLAttributes<T extends EventTarget> extends svelte.JSX.HTMLAttributes<T> {}
+
+  // eslint-disable-next-line @typescript-eslint/no-empty-interface
+  interface SVGAttributes<T extends EventTarget> extends svelte.JSX.SVGAttributes<T> {
     'xlink:actuate'?: string | undefined;
     'xlink:arcrole'?: string | undefined;
     'xlink:href'?: string | undefined;
@@ -83,9 +86,6 @@ declare namespace svelteHTML {
     'xmlns:xlink'?: string | undefined;
   }
 
-  // eslint-disable-next-line @typescript-eslint/no-empty-interface
-  interface SVGAttributes<T extends EventTarget> extends svelte.JSX.SVGAttributes<T> {}
-
   // eslint-disable-next-line @typescript-eslint/no-empty-interface
   interface HTMLProps<T extends EventTarget> extends HTMLAttributes<T> {}
 


Test patch:
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/attribute-element/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/attribute-element/expectedv2.js
index fadc425a..ad39acb8 100644
--- a/packages/svelte2tsx/test/htmlx2jsx/samples/attribute-element/expectedv2.js
+++ b/packages/svelte2tsx/test/htmlx2jsx/samples/attribute-element/expectedv2.js
@@ -1,3 +1,3 @@
  { svelteHTML.createElement("div", {"contenteditable":true,}); }
  { svelteHTML.createElement("div", { contentEditable,}); }
- { svelteHTML.createElement("div", { "contentEditable":contenteditable,}); }
\ No newline at end of file
+ { svelteHTML.createElement("div", { "contenteditable":contenteditable,}); }
\ No newline at end of file