From f34e09f8c80fef3c81efe97c935b0567dca8eef1 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 20 Feb 2022 11:52:19 +0100 Subject: [PATCH 1/2] (fix) $store++/$store-- return type #1382 --- packages/svelte2tsx/src/svelte2tsx/nodes/Stores.ts | 2 +- .../src/svelte2tsx/processInstanceScriptContent.ts | 2 +- .../samples/uses-$store-with-increments/expected.tsx | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/Stores.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/Stores.ts index 4f784964c..b782e2b25 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/Stores.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/Stores.ts @@ -49,7 +49,7 @@ export function handleStore(node: Node, parent: Node, str: MagicString): void { str.overwrite( parent.start, parent.end, - `${storename}.set( $${storename} ${simpleOperator} 1)` + `(${storename}.set( $${storename} ${simpleOperator} 1), $${storename})` ); } else { console.warn( diff --git a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts index b65afe563..6fe43bb10 100644 --- a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts +++ b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts @@ -152,7 +152,7 @@ export function processInstanceScriptContent( str.overwrite( parent.getStart() + astOffset, parent.end + astOffset, - `${storename}.set( $${storename} ${simpleOperator} 1)` + `(${storename}.set( $${storename} ${simpleOperator} 1), $${storename})` ); return; } else { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expected.tsx index f1b64cf12..d98823f06 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expected.tsx @@ -5,14 +5,14 @@ function render() { const count = writable(0)/*Ωignore_startΩ*/;let $count = __sveltets_1_store_get(count);/*Ωignore_endΩ*/; - const handler1 = () => count.set( $count + 1) - const handler2 = () => count.set( $count - 1) + const handler1 = () => (count.set( $count + 1), $count) + const handler2 = () => (count.set( $count - 1), $count) ; () => (<> - - -); + + +); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) { From 1b4778d611d858aa806ecd1deeb81327ea2f1ec1 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 20 Feb 2022 12:04:13 +0100 Subject: [PATCH 2/2] v2 test --- .../samples/uses-$store-with-increments/expectedv2.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expectedv2.ts index c2ad8b746..d613365d6 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expectedv2.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-increments/expectedv2.ts @@ -5,14 +5,14 @@ function render() { const count = writable(0)/*Ωignore_startΩ*/;let $count = __sveltets_1_store_get(count);/*Ωignore_endΩ*/; - const handler1 = () => count.set( $count + 1) - const handler2 = () => count.set( $count - 1) + const handler1 = () => (count.set( $count + 1), $count) + const handler2 = () => (count.set( $count - 1), $count) ; async () => { - { svelteHTML.createElement("button", { "onclick":() => count.set( $count + 1),}); } - { svelteHTML.createElement("button", { "onclick":() => count.set( $count - 1),}); } - { svelteHTML.createElement("button", { "onclick":() => count.set( $count + 1),}); }}; + { svelteHTML.createElement("button", { "onclick":() => (count.set( $count + 1), $count),}); } + { svelteHTML.createElement("button", { "onclick":() => (count.set( $count - 1), $count),}); } + { svelteHTML.createElement("button", { "onclick":() => (count.set( $count + 1), $count),}); }}; return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {