diff --git a/packages/svelte2tsx/src/svelte2tsx/index.ts b/packages/svelte2tsx/src/svelte2tsx/index.ts index b3898bcd2..fea34351c 100644 --- a/packages/svelte2tsx/src/svelte2tsx/index.ts +++ b/packages/svelte2tsx/src/svelte2tsx/index.ts @@ -401,12 +401,14 @@ declare function __sveltets_1_createSvelteComponentTyped( ); let code = str.toString(); // Remove all tsx occurences and the template part from the output - code = - code - .substr(0, code.indexOf('\n() => (<>')) - // prepended before each script block - .replace('<>;', '') - .replace('<>;', '') + code.substr(code.lastIndexOf(');') + ');'.length); + code = code + // prepended before each script block + .replace('<>;', '') + .replace('<>;', '') + // tsx in render function + .replace(/<>.*<\/>/s, '') + .replace('\n() => ();', ''); + return { code }; diff --git a/packages/svelte2tsx/test/emitDts/samples/javascript/expected/TestNoScript.svelte.d.ts b/packages/svelte2tsx/test/emitDts/samples/javascript/expected/TestNoScript.svelte.d.ts new file mode 100644 index 000000000..f102c232d --- /dev/null +++ b/packages/svelte2tsx/test/emitDts/samples/javascript/expected/TestNoScript.svelte.d.ts @@ -0,0 +1,27 @@ +/** @typedef {typeof __propDef.props} TestNoScriptProps */ +/** @typedef {typeof __propDef.events} TestNoScriptEvents */ +/** @typedef {typeof __propDef.slots} TestNoScriptSlots */ +export default class TestNoScript extends SvelteComponentTyped<{}, { + click: MouseEvent; +} & { + [evt: string]: CustomEvent; +}, { + default: {}; +}> { +} +export type TestNoScriptProps = typeof __propDef.props; +export type TestNoScriptEvents = typeof __propDef.events; +export type TestNoScriptSlots = typeof __propDef.slots; +import { SvelteComponentTyped } from "svelte"; +declare const __propDef: { + props: {}; + events: { + click: MouseEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: {}; + }; +}; +export {}; diff --git a/packages/svelte2tsx/test/emitDts/samples/javascript/src/TestNoScript.svelte b/packages/svelte2tsx/test/emitDts/samples/javascript/src/TestNoScript.svelte new file mode 100644 index 000000000..652e1fa99 --- /dev/null +++ b/packages/svelte2tsx/test/emitDts/samples/javascript/src/TestNoScript.svelte @@ -0,0 +1,3 @@ +
+ +
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/expected.tsx new file mode 100644 index 000000000..9fa8f915e --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/expected.tsx @@ -0,0 +1,16 @@ +import { SvelteComponentTyped } from "svelte" + +declare function __sveltets_1_createSvelteComponentTyped( + render: {props: Props, events: Events, slots: Slots } +): SvelteComponentConstructor,Svelte2TsxComponentConstructorParameters>; + +function render() { + +return { props: {}, slots: {'default': {}}, getters: {}, events: {'click':__sveltets_1_mapElementEvent('click')} }} +const __propDef = __sveltets_1_partial(__sveltets_1_with_any_event(render())); +/** @typedef {typeof __propDef.props} InputProps */ +/** @typedef {typeof __propDef.events} InputEvents */ +/** @typedef {typeof __propDef.slots} InputSlots */ + +export default class Input extends __sveltets_1_createSvelteComponentTyped(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) { +} \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/input.svelte new file mode 100644 index 000000000..71f606acf --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/input.svelte @@ -0,0 +1,4 @@ + +{#await Promise.resolve(0) then n} + {n} +{/await} \ No newline at end of file