Repository: sveltejs/language-tools
Pull request #1605 (2022-08-27 03:59:33)

(fix) extract name in destructuring with default
#1604 Missed one spot when we adopt `periscopic` for typescript AST.  

There's still one left that's not adopted.

https://github.com/Rich-Harris/periscopic/blob/2ff43ecd3e60a660acce552046d5c6eac0586ae7/src/index.js#L230

 Still not sure what that's for.  Parameter like `(...args)` ? Not sure if our use case would use that. 



Patch:
diff --git a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts
index 3cddb049..f58893dd 100644
--- a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts
+++ b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts
@@ -100,6 +100,8 @@ export function extractIdentifiers(
                 extractIdentifiers(element, identifiers);
             }
         });
+    } else if (ts.isBinaryExpression(node)) {
+        extractIdentifiers(node.left, identifiers);
     }
 
     return identifiers;


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
index 00b63b1e..602a3c79 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx
@@ -6,6 +6,7 @@ let  { b: d } = __sveltets_1_invalidate(() => ({ b: '' }));
 let  { c: { length } } = __sveltets_1_invalidate(() => ({ c: '' }));
 let  { ...e } = __sveltets_1_invalidate(() => ({ f: ''}));
 let  { f } = __sveltets_1_invalidate(() => ({ f: ''}));
+let  { b: g = 1} = __sveltets_1_invalidate(() => ({ b: 1 }));
 ;
 () => (<></>);
 return { props: {}, slots: {}, getters: {}, events: {} }}
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expectedv2.ts
index a17d7d46..ecad409c 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expectedv2.ts
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expectedv2.ts
@@ -6,6 +6,7 @@ let  { b: d } = __sveltets_1_invalidate(() => ({ b: '' }));
 let  { c: { length } } = __sveltets_1_invalidate(() => ({ c: '' }));
 let  { ...e } = __sveltets_1_invalidate(() => ({ f: ''}));
 let  { f } = __sveltets_1_invalidate(() => ({ f: ''}));
+let  { b: g = 1} = __sveltets_1_invalidate(() => ({ b: 1 }));
 ;
 async () => {};
 return { props: {}, slots: {}, getters: {}, events: {} }}
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte
index 14e4ee60..d42a5693 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte
@@ -4,4 +4,5 @@ $: ({ b: d } = { b: '' });
 $: ({ c: { length } } = { c: '' });
 $: ({ ...e } = { f: ''});
 $: ( { f } = { f: ''} );
+$: ({ b: g = 1} = { b: 1 });
 </script>