Skip to content

Commit 1b5e913

Browse files
authored
fix: adjust $props() comment type logic (#2294)
Look at the last comment before the node first, check for `@type` and prevent `@typedef` false positive sveltejs/svelte#10541 (comment)
1 parent efe8463 commit 1b5e913

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,21 @@ export class ExportedNames {
187187
const text = node.getSourceFile().getFullText();
188188
let start = -1;
189189
let comment: string;
190-
for (const c of ts.getLeadingCommentRanges(text, node.pos) || []) {
190+
// reverse because we want to look at the last comment before the node first
191+
for (const c of [...(ts.getLeadingCommentRanges(text, node.pos) || [])].reverse()) {
191192
const potential_match = text.substring(c.pos, c.end);
192-
if (potential_match.includes('@type')) {
193+
if (/@type\b/.test(potential_match)) {
193194
comment = potential_match;
194195
start = c.pos + this.astOffset;
195196
break;
196197
}
197198
}
198199
if (!comment) {
199-
for (const c of ts.getLeadingCommentRanges(text, node.parent.pos) || []) {
200+
for (const c of [
201+
...(ts.getLeadingCommentRanges(text, node.parent.pos) || []).reverse()
202+
]) {
200203
const potential_match = text.substring(c.pos, c.end);
201-
if (potential_match.includes('@type')) {
204+
if (/@type\b/.test(potential_match)) {
202205
comment = potential_match;
203206
start = c.pos + this.astOffset;
204207
break;

0 commit comments

Comments
 (0)