Skip to content

Commit 0056f66

Browse files
committed
fix: has many comments function
1 parent bf6ff5f commit 0056f66

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/ast/ast.service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,19 @@ class AstService {
163163
}
164164

165165
public countComments(node: t.Node): number {
166-
let count = 0;
166+
const seen = new Set<number>();
167167
t.traverse(node, {
168168
enter(node) {
169-
count += (node.leadingComments ?? []).length;
170-
count += (node.trailingComments ?? []).length;
171-
count += (node.innerComments ?? []).length;
169+
for (const comment of [
170+
...(node.leadingComments ?? []),
171+
...(node.trailingComments ?? []),
172+
...(node.innerComments ?? []),
173+
]) {
174+
seen.add(comment.start!);
175+
}
172176
},
173177
});
174-
return count;
178+
return seen.size;
175179
}
176180

177181
public isFunction(node: t.Node): boolean {

0 commit comments

Comments
 (0)