diff --git a/packages/svelte2tsx/src/svelte2tsx.ts b/packages/svelte2tsx/src/svelte2tsx.ts index 9688a1a8f..44fc169ee 100644 --- a/packages/svelte2tsx/src/svelte2tsx.ts +++ b/packages/svelte2tsx/src/svelte2tsx.ts @@ -923,7 +923,8 @@ function createRenderFunction({ str.overwrite(scriptTag.start + 1, scriptTagEnd, `function render() {${propsDecl}\n`); const scriptEndTagStart = htmlx.lastIndexOf('<', scriptTag.end - 1); - str.overwrite(scriptEndTagStart, scriptTag.end, ';\n<>', { + // wrap template with callback + str.overwrite(scriptEndTagStart, scriptTag.end, ';\n() => (<>', { contentOnly: true, }); } else { @@ -947,6 +948,12 @@ function createRenderFunction({ isTsFile )}, slots: ${slotsAsDef}, getters: ${createRenderFunctionGetterStr(getters)}` + `, events: ${eventMapToString(events)} }}`; + + // wrap template with callback + if (scriptTag) { + str.append(');'); + } + str.append(returnString); } diff --git a/packages/svelte2tsx/test/sourcemaps/let.html b/packages/svelte2tsx/test/sourcemaps/let.html index a15554f12..cdadec282 100644 --- a/packages/svelte2tsx/test/sourcemaps/let.html +++ b/packages/svelte2tsx/test/sourcemaps/let.html @@ -2,8 +2,8 @@ let selected = __sveltets_invalidate(() => lookup.get(slug)); ; -<> - +() => (<> +); return { props: {}, slots: {}, getters: {}, events: {} }} export default class { diff --git a/packages/svelte2tsx/test/sourcemaps/repl.html b/packages/svelte2tsx/test/sourcemaps/repl.html index 214d6cbed..3e14a138c 100644 --- a/packages/svelte2tsx/test/sourcemaps/repl.html +++ b/packages/svelte2tsx/test/sourcemaps/repl.html @@ -112,7 +112,7 @@ }); } ; -<> +() => (<> @@ -176,7 +176,7 @@ }}} - +); return { props: {slug: slug , chapter: chapter}, slots: {}, getters: {}, events: {} }} export default class { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/array-binding-export/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/array-binding-export/expected.tsx index 9fd91e0a6..da4136ecd 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/array-binding-export/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/array-binding-export/expected.tsx @@ -2,7 +2,7 @@ let [a,b,c] = [1,2,3]; ; -<> +() => (<>); return { props: {a: a , b: b , c: c}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-none/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-none/expected.tsx index 7eeb011ce..1c33ef3d7 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-none/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-none/expected.tsx @@ -1,6 +1,6 @@ <>;function render() { __sveltets_store_get(var); -<> +() => (<>); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-some/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-some/expected.tsx index 93813804f..d44b6b182 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-some/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ast-offset-some/expected.tsx @@ -1,6 +1,6 @@ <>;function render() { __sveltets_store_get(var); -<> +() => (<>); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/await-with-$store/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/await-with-$store/expected.tsx index c0949f3eb..36ff0989e 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/await-with-$store/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/await-with-$store/expected.tsx @@ -5,13 +5,13 @@ function render() { const store = readable(Promise.resolve('test'), () => {}); ; -<> +() => (<> {() => {let _$$p = (__sveltets_store_get(store)); <>

loading

; _$$p.then((data) => {<> {data} -})}} +})}}); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/circle-drawer-example/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/circle-drawer-example/expected.tsx index 7b15ce8e0..27a386e96 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/circle-drawer-example/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/circle-drawer-example/expected.tsx @@ -57,7 +57,7 @@ return circles.map(({ cx, cy, r }) => ({ cx, cy, r })); } ; -<> +() => (<> @@ -86,7 +86,7 @@

adjust diameter of circle at {selected.cx}, {selected.cy}

-}}} +}}}); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-default-slot/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-default-slot/expected.tsx index 64f9630c4..f91edade6 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-default-slot/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-default-slot/expected.tsx @@ -2,10 +2,10 @@ let b = 7; ; -<> +() => (<>
Hello -
+); return { props: {}, slots: {default: {a:b}}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-multiple-slots/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-multiple-slots/expected.tsx index 78e9c8f9e..1e134a858 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-multiple-slots/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-multiple-slots/expected.tsx @@ -4,11 +4,11 @@ let d = 5; let e = 5; ; -<> +() => (<>
Hello -
+); return { props: {}, slots: {default: {a:b}, test: {c:d, e:e}}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-crazy-attributes/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-crazy-attributes/expected.tsx index c5bb7ebe8..fbf88d9af 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-crazy-attributes/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-crazy-attributes/expected.tsx @@ -2,10 +2,10 @@ let b = 7; ; -<> +() => (<>
Hello -
+); return { props: {}, slots: {default: {a:b, b:b, c:"b", d:"__svelte_ts_string", e:b}}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-class/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/export-class/expected.tsx index 61e7f4d1d..87a6af131 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/export-class/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-class/expected.tsx @@ -2,7 +2,7 @@ class Foo {}; ; -<> +() => (<>); return { props: {}, slots: {}, getters: {Foo: Foo}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-js-strictMode/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/export-js-strictMode/expected.tsx index e5987fcb0..9c889fbf6 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/export-js-strictMode/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-js-strictMode/expected.tsx @@ -4,7 +4,7 @@ let b; let c = 123; ; -<> +() => (<>); return { props: {a: a , b: b , c: c}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-list/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/export-list/expected.tsx index b925f5bc9..815c0d1e7 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/export-list/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-list/expected.tsx @@ -4,7 +4,7 @@ let name2 = "world" ; -<> +() => (<>); return { props: {name: name , name2: name2}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-references-local/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/export-references-local/expected.tsx index 82eb280ed..f66b68af2 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/export-references-local/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-references-local/expected.tsx @@ -3,7 +3,7 @@ let world = "world"; let name = world; ; -<> +() => (<>); return { props: {name: name}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-with-default-multi/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/export-with-default-multi/expected.tsx index b400390d5..abb7cfc0b 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/export-with-default-multi/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-with-default-multi/expected.tsx @@ -4,7 +4,7 @@ let name = "world";name = __sveltets_any(name);;let world = ''; ; -<> +() => (<>); return { props: {name: name , world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/import-single-quote/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/import-single-quote/expected.tsx index c402e5264..6e4c43221 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/import-single-quote/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/import-single-quote/expected.tsx @@ -4,8 +4,8 @@ function render() { ; -<> - +() => (<> +); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/imports/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/imports/expected.tsx index 3a3291679..c0b37b8f5 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/imports/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/imports/expected.tsx @@ -8,8 +8,8 @@ function render() { let world = "name" ; -<>

hello {world}

- +() => (<>

hello {world}

+); return { props: {world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line/expected.tsx index d80cedf37..32bacec1c 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line/expected.tsx @@ -1,6 +1,6 @@ <>;let b = 5;;<>;function render() { let world = "name"; -<>

hello {world}

+() => (<>

hello {world}

); return { props: {world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line2/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line2/expected.tsx index d80cedf37..32bacec1c 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line2/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script-in-line2/expected.tsx @@ -1,6 +1,6 @@ <>;let b = 5;;<>;function render() { let world = "name"; -<>

hello {world}

+() => (<>

hello {world}

); return { props: {world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script/expected.tsx index 3a5a10b0b..fced9c237 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script/expected.tsx @@ -5,9 +5,9 @@ let world = "name" ; -<> +() => (<> -

hello {world}

+

hello {world}

); return { props: {world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script2/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script2/expected.tsx index 044bebb64..5c831310b 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script2/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script2/expected.tsx @@ -5,9 +5,9 @@ let world = "name" ; -<>

hello {world}

+() => (<>

hello {world}

- +); return { props: {world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/nested-$-variables-script/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/nested-$-variables-script/expected.tsx index 7558990f2..20e84515a 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/nested-$-variables-script/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/nested-$-variables-script/expected.tsx @@ -21,7 +21,7 @@ function test3() { const test4 = ({a, b: { $top1: $top2 }}) => $top2 && __sveltets_store_get(top1) ; -<> +() => (<>); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/object-binding-export/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/object-binding-export/expected.tsx index 1caf56005..39edfc046 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/object-binding-export/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/object-binding-export/expected.tsx @@ -2,7 +2,7 @@ let { name: rename } = { name: "world" }; ; -<> +() => (<>); return { props: {rename: rename}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-block/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-block/expected.tsx index bc31a82d1..116c4fd50 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-block/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-block/expected.tsx @@ -5,7 +5,7 @@ let a: 1 | 2 = 1; console.log(a + 1); }} ; -<> +() => (<>); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-object/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-object/expected.tsx index 6188c3948..5df5926c4 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-object/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-object/expected.tsx @@ -3,7 +3,7 @@ let b = __sveltets_invalidate(() => ({ a: 1 })); ; -<> +() => (<>); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare/expected.tsx index 4303a8ff5..ec93b4a62 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare/expected.tsx @@ -6,7 +6,7 @@ let b = __sveltets_invalidate(() => 7); let a; $: a = __sveltets_invalidate(() => 5); ; -<> +() => (<>); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/renamed-exports/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/renamed-exports/expected.tsx index 62fbdb17c..65c56c444 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/renamed-exports/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/renamed-exports/expected.tsx @@ -4,7 +4,7 @@ let name2 = "world" ; -<> +() => (<>); return { props: {name3: name , name4: name2}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/script-and-module-script/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/script-and-module-script/expected.tsx index df020fb9a..155bce1c2 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/script-and-module-script/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/script-and-module-script/expected.tsx @@ -5,9 +5,9 @@ let world = "name" ; -<> +() => (<>

hello {world}

- +); return { props: {world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expected.tsx index 948695b5f..a15d7008c 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expected.tsx @@ -2,7 +2,7 @@ let b = 'top level'; ; -<>
+() => (<>
@@ -11,7 +11,7 @@ - +); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/script-on-bottom/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/script-on-bottom/expected.tsx index f8c070375..1b0269497 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/script-on-bottom/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/script-on-bottom/expected.tsx @@ -2,8 +2,8 @@ let world = "name" ; -<>

hello {world}

- +() => (<>

hello {world}

+); return { props: {world: world}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/script-style-like-component/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/script-style-like-component/expected.tsx index 39be5adcd..2d2b5af8b 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/script-style-like-component/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/script-style-like-component/expected.tsx @@ -2,12 +2,12 @@ let Script, Style; ; -<> +() => (<> -