Skip to content

Commit a9934c3

Browse files
authored
fix single line comment before props (#531)
#530 prevent `// comment` being treat as props docstring
1 parent cc2fc95 commit a9934c3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export class ExportedNames
5353
const comment = ts.getLeadingCommentRanges(fileText, exportExpr.getFullStart());
5454

5555
if (comment) {
56-
doc = fileText.substring(comment[0].pos, comment[0].end);
56+
const [first] = comment;
57+
if (first?.kind === ts.SyntaxKind.MultiLineCommentTrivia) {
58+
doc = fileText.substring(first.pos, first.end);
59+
}
5760
}
5861
}
5962

packages/svelte2tsx/test/svelte2tsx/samples/ts-export-doc/expected.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
*/
1111
let b = 1;
1212
let c;
13+
14+
// not this one
15+
let d;
1316
;
1417
() => (<></>);
15-
return { props: {a: a , b: b , c: c} as {
18+
return { props: {a: a , b: b , c: c , d: d} as {
1619
/**
1720
* DOCS!
1821
*/a: string,
1922
/**
2023
* MORE DOCS!
21-
*/b?: typeof b, c: typeof c}, slots: {}, getters: {}, events: {} }}
24+
*/b?: typeof b, c: typeof c, d: typeof d}, slots: {}, getters: {}, events: {} }}
2225

2326
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) {
24-
}
27+
}

packages/svelte2tsx/test/svelte2tsx/samples/ts-export-doc/input.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
*/
99
export let b = 1;
1010
export let c;
11+
12+
// not this one
13+
export let d;
1114
</script>

0 commit comments

Comments
 (0)