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)); <>
+() => (<>
@@ -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;
;
-<>
+() => (<>
->
+>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/self-closing-component/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/self-closing-component/expected.tsx
index 8e0c1a999..b3aa94de8 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/self-closing-component/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/self-closing-component/expected.tsx
@@ -5,8 +5,8 @@ function render() {
let a = 'b';
;
-<>
->
+() => (<>
+>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/single-export/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/single-export/expected.tsx
index 340b375b1..dbba77e50 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/single-export/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/single-export/expected.tsx
@@ -2,7 +2,7 @@
let name = "world"
;
-<>>
+() => (<>>);
return { props: {name: name}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-arrow-function/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-arrow-function/expected.tsx
index 79819e032..a933e964f 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-arrow-function/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-arrow-function/expected.tsx
@@ -5,7 +5,7 @@
return c;
}
;
-<>>
+() => (<>>);
return { props: {f: f} as {f?: typeof f}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-const/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-const/expected.tsx
index 4fb695c64..863669aad 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-const/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-const/expected.tsx
@@ -3,7 +3,7 @@
const name: string = "world";
const SOME = 1, CONSTANT = 2;
;
-<>>
+() => (<>>);
return { props: {}, slots: {}, getters: {name: name, SOME: SOME, CONSTANT: CONSTANT}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-initializer/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-initializer/expected.tsx
index b9c1bc5ae..a2f66e0e8 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-initializer/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-initializer/expected.tsx
@@ -2,7 +2,7 @@
let a = '';
;
-<>>
+() => (<>>);
return { props: {a: a} as {a?: typeof a}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-type/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-type/expected.tsx
index 64736f87b..66fee1e23 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-type/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-has-type/expected.tsx
@@ -4,7 +4,7 @@
let a: A;
let b: A = {};b = __sveltets_any(b);;
;
-<>>
+() => (<>>);
return { props: {a: a , b: b} as {a: A, b?: A}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-strictMode/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-strictMode/expected.tsx
index 79560e15a..f2a963384 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-strictMode/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-strictMode/expected.tsx
@@ -4,7 +4,7 @@
let b: number | undefined;
let c: number = 123;c = __sveltets_any(c);;
;
-<>>
+() => (<>>);
return { props: {a: a , b: b , c: c} as {a: number, b: number | undefined, c?: number}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-multiple-export/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-multiple-export/expected.tsx
index 67c763c49..395d2c557 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-multiple-export/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-multiple-export/expected.tsx
@@ -3,8 +3,8 @@
let number1: number
let number2: number
;
-<>
-
{number1} + {number2} = {number1 + number2}
>
+() => (<>
+
{number1} + {number2} = {number1 + number2}
>);
return { props: {number1: number1 , number2: number2} as {number1: number, number2: number}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-typed-export-with-default/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-typed-export-with-default/expected.tsx
index 8d6b8b3e3..83ac0f53a 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-typed-export-with-default/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-typed-export-with-default/expected.tsx
@@ -2,7 +2,7 @@
let name: string | number = "world";name = __sveltets_any(name);
;
-<>>
+() => (<>>);
return { props: {name: name} as {name?: string | number}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-uses-$$props-strictMode/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-uses-$$props-strictMode/expected.tsx
index 3b92b9ad3..ba501cddd 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-uses-$$props-strictMode/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-uses-$$props-strictMode/expected.tsx
@@ -1,7 +1,7 @@
<>>;function render() { let $$props = __sveltets_allPropsType();
;
-<>
-
{$$props['name']}
>
+() => (<>
+
{$$props['name']}
>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$props-script/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$props-script/expected.tsx
index 0b5df8253..6c8b028a4 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$props-script/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$props-script/expected.tsx
@@ -2,8 +2,8 @@
let name = $$props['name'];
;
-<>
{name}
->
+() => (<>
{name}
+>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$restProps-script/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$restProps-script/expected.tsx
index 4e233e657..3ebc15c3a 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$restProps-script/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$$restProps-script/expected.tsx
@@ -2,8 +2,8 @@
let name = $$restProps['name'];
;
-<>
{name}
->
+() => (<>
{name}
+>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-assignment-operators/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-assignment-operators/expected.tsx
index b0ff191e7..bbe53bb66 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-assignment-operators/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-assignment-operators/expected.tsx
@@ -18,7 +18,7 @@ function render() {
const handler11 = () => count.set( __sveltets_store_get(count) ^ myvar)
const handler12 = () => count.set( __sveltets_store_get(count) | myvar)
;
-<>
+() => (<>
@@ -31,7 +31,7 @@ function render() {
-
>
+
>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-exclamation-mark/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-exclamation-mark/expected.tsx
index 68e929ddd..7c5c47fed 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-exclamation-mark/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-with-exclamation-mark/expected.tsx
@@ -6,9 +6,9 @@ function render() {
const count = writable(0);
const handler1 = () => !__sveltets_store_get(count)
;
-<>
+() => (<>
-
>
+
>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
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 4fe5cf67d..a91be7603 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
@@ -7,10 +7,10 @@ function render() {
const handler1 = () => count.set( __sveltets_store_get(count) + 1)
const handler2 = () => count.set( __sveltets_store_get(count) - 1)
;
-<>
+() => (<>
-
>
+
>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store/expected.tsx
index aafa3ef99..cf7431d49 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store/expected.tsx
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store/expected.tsx
@@ -1,7 +1,7 @@
<>>;function render() {
b.set(__sveltets_store_get(b).concat(5));
-<>
-
b.set(__sveltets_store_get(b).concat(5))}>{__sveltets_store_get(b)}
>
+() => (<>
+
b.set(__sveltets_store_get(b).concat(5))}>{__sveltets_store_get(b)}
>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class Input__SvelteComponent_ {