nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sveltejs/eslint-plugin-svelte
Pull request #1040 (2025-01-26 02:56:20)

fix: account for \n and \r in `TemplateLiteral` handling for the `no-useless-mustaches` rule
close: https://github.com/sveltejs/eslint-plugin-svelte/issues/1036

changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: 95c035f4d8fcd05ca7c874c67d707e893ea55b6c

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name                 | Type  |
| -------------------- | ----- |
| eslint-plugin-svelte | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/sveltejs/eslint-plugin-svelte/new/fix/no-useless-mustaches?filename=.changeset/happy-beers-play.md&value=---%0A%22eslint-plugin-svelte%22%3A%20patch%0A---%0A%0Afix%3A%20account%20for%20%5Cn%20and%20%5Cr%20in%20%60TemplateLiteral%60%20handling%20for%20the%20%60no-useless-mustaches%60%20rule%0A)


pkg-pr-new[bot]: 
[Open in Stackblitz](https://pkg.pr.new/template/b461e7c6-612e-48a1-9ef9-3f6928f2eea8)


```
npm i https://pkg.pr.new/eslint-plugin-svelte@1040
```


_commit: <a href="https://github.com/sveltejs/eslint-plugin-svelte/runs/36176526173"><code>95c035f</code></a>_


Patch:
diff --git a/.changeset/old-numbers-pull.md b/.changeset/old-numbers-pull.md
new file mode 100644
index 0000000..9bcf48b
--- /dev/null
+++ b/.changeset/old-numbers-pull.md
@@ -0,0 +1,5 @@
+---
+'eslint-plugin-svelte': patch
+---
+
+fix: account for \n and \r in `TemplateLiteral` handling for the `no-useless-mustaches` rule
diff --git a/packages/eslint-plugin-svelte/src/rules/no-useless-mustaches.ts b/packages/eslint-plugin-svelte/src/rules/no-useless-mustaches.ts
index 56c80c3..88010dc 100644
--- a/packages/eslint-plugin-svelte/src/rules/no-useless-mustaches.ts
+++ b/packages/eslint-plugin-svelte/src/rules/no-useless-mustaches.ts
@@ -81,6 +81,10 @@ export default createRule('no-useless-mustaches', {
 				return;
 			}
 
+			if (expression.type === 'TemplateLiteral' && /[\n\r]/.test(rawValue)) {
+				return;
+			}
+
 			let hasEscape = false;
 			if (rawValue !== strValue) {
 				// check escapes


Test patch:
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/no-useless-mustaches/valid/valid-test02-input.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/no-useless-mustaches/valid/valid-test02-input.svelte
new file mode 100644
index 0000000..18ac5de
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/no-useless-mustaches/valid/valid-test02-input.svelte
@@ -0,0 +1,5 @@
+<HyperMD
+	value={`# Doc
+
+Text goes here`}
+/>
Repository: sveltejs/language-tools
Pull request #1165 (2021-09-05 05:26:16)

(fix) reacitve declare destructuring with alias
#1164

I missed this situation when migrating `extract_identifiers` for typescript AST from `periscopic`. They're multiple types of AST node in typescript for this situation but only one in the estree. 


Patch:
diff --git a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts
index 5bc60743..3cddb049 100644
--- a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts
+++ b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts
@@ -87,6 +87,9 @@ export function extractIdentifiers(
             } else if (ts.isShorthandPropertyAssignment(child)) {
                 // in ts Ast { a = 1 } and { a } are both ShorthandPropertyAssignment
                 extractIdentifiers(child.name, identifiers);
+            } else if (ts.isPropertyAssignment(child)) {
+                // { a: b }
+                extractIdentifiers(child.initializer, identifiers);
             }
         });
     } else if (ts.isArrayLiteralExpression(node)) {


Test patch:
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx
new file mode 100644
index 00000000..110af63a
--- /dev/null
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx
@@ -0,0 +1,13 @@
+///<reference types="svelte" />
+<></>;function render() {
+
+let  { a } = __sveltets_1_invalidate(() => ({ a: '' }));
+let  { b: d } = __sveltets_1_invalidate(() => ({ b: '' }));
+let  { c: { length } } = __sveltets_1_invalidate(() => ({ c: '' }));
+let  { ...e } = __sveltets_1_invalidate(() => ({ f: ''}));
+;
+() => (<></>);
+return { props: {}, slots: {}, getters: {}, events: {} }}
+
+export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
+}
\ No newline at end of file
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte
new file mode 100644
index 00000000..73646101
--- /dev/null
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte
@@ -0,0 +1,6 @@
+<script>
+$: ({ a } = { a: '' });
+$: ({ b: d } = { b: '' });
+$: ({ c: { length } } = { c: '' });
+$: ({ ...e } = { f: ''});
+</script>
Repository: sveltejs/language-tools
Pull request #1169 (2021-09-09 08:50:55)

(fix) fix doc for comma separated exports
#1168


Patch:
diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts
index 122e067b..f509a7fc 100644
--- a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts
+++ b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts
@@ -290,10 +290,17 @@ export class ExportedNames {
 
     private getDoc(target: ts.BindingName) {
         let doc = undefined;
+        // Traverse `a` one up. If the declaration is part of a declaration list,
+        // the comment is at this point already
+        const variableDeclaration = target?.parent;
         // Traverse `a` up to `export let a`
         const exportExpr = target?.parent?.parent?.parent;
 
-        if (exportExpr) {
+        if (variableDeclaration) {
+            doc = getLastLeadingDoc(variableDeclaration);
+        }
+
+        if (exportExpr && !doc) {
             doc = getLastLeadingDoc(exportExpr);
         }
 


Test patch:
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx
index 5a45bef2..47024ccb 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx
@@ -13,6 +13,14 @@
      */
      let b;
      let c;
+    /**
+     * d
+     */
+     let d;let 
+    /**
+     * e
+     */
+     e;
 ;
 () => (<></>);
 return { props: {
@@ -21,7 +29,13 @@ return { props: {
      */a: a , 
 /**
      * MORE DOCS!
-     */b: b , c: c}, slots: {}, getters: {}, events: {} }}
+     */b: b , c: c , 
+/**
+     * d
+     */d: d , 
+/**
+     * e
+     */e: e}, slots: {}, getters: {}, events: {} }}
 
 export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
 }
\ No newline at end of file
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte
index 54dd7ba9..919cd9d6 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte
@@ -11,4 +11,12 @@
      */
     export let b;
     export let c;
+    /**
+     * d
+     */
+    export let d,
+    /**
+     * e
+     */
+     e;
 </script>
Repository: sveltejs/language-tools
Pull request #1170 (2021-09-09 08:59:10)

(fix) handle action on svelte:body
Narrows the type to HTMLBodyElement


Patch:
diff --git a/packages/svelte2tsx/src/htmlxtojsx/nodes/action-directive.ts b/packages/svelte2tsx/src/htmlxtojsx/nodes/action-directive.ts
index 60fad587..e46d9914 100644
--- a/packages/svelte2tsx/src/htmlxtojsx/nodes/action-directive.ts
+++ b/packages/svelte2tsx/src/htmlxtojsx/nodes/action-directive.ts
@@ -12,16 +12,17 @@ export function handleActionDirective(
     parent: BaseNode
 ): void {
     str.overwrite(attr.start, attr.start + 'use:'.length, '{...__sveltets_1_ensureAction(');
+    const name = parent.name === 'svelte:body' ? 'body' : parent.name;
 
     if (!attr.expression) {
-        str.appendLeft(attr.end, `(__sveltets_1_mapElementTag('${parent.name}')))}`);
+        str.appendLeft(attr.end, `(__sveltets_1_mapElementTag('${name}')))}`);
         return;
     }
 
     str.overwrite(
         attr.start + `use:${attr.name}`.length,
         attr.expression.start,
-        `(__sveltets_1_mapElementTag('${parent.name}'),(`
+        `(__sveltets_1_mapElementTag('${name}'),(`
     );
     str.appendLeft(attr.expression.end, ')))');
     const lastChar = htmlx[attr.end - 1];


Test patch:
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/action-svelte-body/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/action-svelte-body/expected.jsx
new file mode 100644
index 00000000..896a20ba
--- /dev/null
+++ b/packages/svelte2tsx/test/htmlx2jsx/samples/action-svelte-body/expected.jsx
@@ -0,0 +1,1 @@
+<><sveltebody {...__sveltets_1_ensureAction(blink(__sveltets_1_mapElementTag('body')))} /></>
\ No newline at end of file
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/action-svelte-body/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/action-svelte-body/input.svelte
new file mode 100644
index 00000000..534dac77
--- /dev/null
+++ b/packages/svelte2tsx/test/htmlx2jsx/samples/action-svelte-body/input.svelte
@@ -0,0 +1,1 @@
+<svelte:body use:blink />
\ No newline at end of file
Repository: sveltejs/language-tools
Pull request #1322 (2022-01-06 10:11:59)

(fix) handle $store shorthand prop assignment
#1321


Patch:
diff --git a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts
index 75583f3b..fa5d3732 100644
--- a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts
+++ b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts
@@ -170,7 +170,12 @@ export function processInstanceScriptContent(
         // - in order to get ts errors if store is not assignable to SvelteStore
         // - use $store variable defined above to get ts flow control
         const dollar = str.original.indexOf('$', ident.getStart() + astOffset);
-        const getPrefix = isSafeToPrefixWithSemicolon(ident) ? ';' : '';
+        const getPrefix = isSafeToPrefixWithSemicolon(ident)
+            ? ';'
+            : ts.isShorthandPropertyAssignment(parent)
+            ? // { $store } --> { $store: __sveltets_1_store_get(..)}
+              ident.text + ': '
+            : '';
         str.overwrite(dollar, dollar + 1, getPrefix + '(__sveltets_1_store_get(');
         str.prependLeft(ident.end + astOffset, `), $${storename})`);
     };


Test patch:
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/$store-prop-init/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/$store-prop-init/expected.tsx
new file mode 100644
index 00000000..bf227624
--- /dev/null
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/$store-prop-init/expected.tsx
@@ -0,0 +1,12 @@
+///<reference types="svelte" />
+<></>;function render() {
+
+    let store = null/*Ωignore_startΩ*/;let $store = __sveltets_1_store_get(store);/*Ωignore_endΩ*/;
+    const foo = { $store: (__sveltets_1_store_get(store), $store) };
+    const bar = { $store: (__sveltets_1_store_get(store), $store) };
+;
+() => (<></>);
+return { props: {}, slots: {}, getters: {}, events: {} }}
+
+export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
+}
\ No newline at end of file
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/$store-prop-init/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/$store-prop-init/input.svelte
new file mode 100644
index 00000000..e14a1f8b
--- /dev/null
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/$store-prop-init/input.svelte
@@ -0,0 +1,5 @@
+<script lang="ts">
+    let store = null;
+    const foo = { $store };
+    const bar = { $store: $store };
+</script>
Repository: sveltejs/language-tools
Pull request #1662 (2022-09-26 13:35:24)

(fix) don't blank non-top-level scripts
..in the new transformation
#1644


Patch:
diff --git a/packages/svelte2tsx/src/svelte2tsx/index.ts b/packages/svelte2tsx/src/svelte2tsx/index.ts
index 6d947b2b..20d95e5f 100644
--- a/packages/svelte2tsx/src/svelte2tsx/index.ts
+++ b/packages/svelte2tsx/src/svelte2tsx/index.ts
@@ -282,7 +282,9 @@ function processSvelteTemplate(
 
     // resolve scripts
     const { scriptTag, moduleScriptTag } = scripts.getTopLevelScriptTags();
-    scripts.blankOtherScriptTags(str);
+    if (options.mode !== 'ts') {
+        scripts.blankOtherScriptTags(str);
+    }
 
     //resolve stores
     const resolvedStores = stores.getStoreNames();
diff --git a/packages/svelte2tsx/src/utils/htmlxparser.ts b/packages/svelte2tsx/src/utils/htmlxparser.ts
index ca6caf9b..adf01f93 100644
--- a/packages/svelte2tsx/src/utils/htmlxparser.ts
+++ b/packages/svelte2tsx/src/utils/htmlxparser.ts
@@ -46,7 +46,7 @@ function extractTag(htmlx: string, tag: 'script' | 'style', useNewTransformation
         let content = match[4];
         if (!content) {
             if (useNewTransformation) {
-                // Keep tag and transform it properly by removing it
+                // Keep tag and transform it like a regular element
                 content = '';
             } else {
                 // Self-closing/empty tags don't need replacement


Test patch:
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/script-in-rawhtml/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/script-in-rawhtml/expectedv2.ts
index aecb30d9..d1fbd438 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/script-in-rawhtml/expectedv2.ts
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/script-in-rawhtml/expectedv2.ts
@@ -7,7 +7,7 @@
 ;
 async () => {
 
- ``;};
+ `<script type="application/ld+json">${JSON.stringify(schema)}</script>`;};
 return { props: {}, slots: {}, getters: {}, events: {} }}
 
 export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expectedv2.ts
index a21a8ca2..52200358 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expectedv2.ts
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expectedv2.ts
@@ -4,14 +4,16 @@
   let b = 'top level';
 ;
 async () => { { svelteHTML.createElement("div", {});
-  
+   { svelteHTML.createElement("script", {});                         }
  }
 
 
 
  { svelteHTML.createElement("svelte:head", {});
    { svelteHTML.createElement("link", {    "rel":`stylesheet`,"href":`/lib/jodit.es2018.min.css`,});}
-  
+   { svelteHTML.createElement("script", { "src":`/lib/jodit.es2018.min.js`,});
+
+   }
  }};
 return { props: {}, slots: {}, getters: {}, events: {} }}