diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts index 122e067b3..f509a7fc6 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts @@ -290,10 +290,17 @@ export class ExportedNames { private getDoc(target: ts.BindingName) { let doc = undefined; + // Traverse `a` one up. If the declaration is part of a declaration list, + // the comment is at this point already + const variableDeclaration = target?.parent; // Traverse `a` up to `export let a` const exportExpr = target?.parent?.parent?.parent; - if (exportExpr) { + if (variableDeclaration) { + doc = getLastLeadingDoc(variableDeclaration); + } + + if (exportExpr && !doc) { doc = getLastLeadingDoc(exportExpr); } diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx index 5a45bef23..47024ccbd 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/expected.tsx @@ -13,6 +13,14 @@ */ let b; let c; + /** + * d + */ + let d;let + /** + * e + */ + e; ; () => (<>); return { props: { @@ -21,7 +29,13 @@ return { props: { */a: a , /** * MORE DOCS! - */b: b , c: c}, slots: {}, getters: {}, events: {} }} + */b: b , c: c , +/** + * d + */d: d , +/** + * e + */e: e}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) { } \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte index 54dd7ba95..919cd9d69 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte +++ b/packages/svelte2tsx/test/svelte2tsx/samples/export-doc/input.svelte @@ -11,4 +11,12 @@ */ export let b; export let c; + /** + * d + */ + export let d, + /** + * e + */ + e;