-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Fix duplicate JSDoc @typedef and @callback comments in declaration emit #62979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5992,15 +5992,25 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function shouldWriteComment(text: string, pos: number) { | ||||||||||||||||||||||||||
| function shouldWriteComment(text: string, pos: number, end?: number) { | ||||||||||||||||||||||||||
| if (printerOptions.onlyPrintJsDocStyle) { | ||||||||||||||||||||||||||
| return (isJSDocLikeText(text, pos) || isPinnedComment(text, pos)); | ||||||||||||||||||||||||||
| if (!isJSDocLikeText(text, pos) && !isPinnedComment(text, pos)) { | ||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| // Skip @typedef and @callback comments - they're converted to type declarations | ||||||||||||||||||||||||||
| if (end !== undefined) { | ||||||||||||||||||||||||||
| const commentText = text.slice(pos, end); | ||||||||||||||||||||||||||
| if (commentText.includes("@typedef") || commentText.includes("@callback")) { | ||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+6002
to
+6005
|
||||||||||||||||||||||||||
| const commentText = text.slice(pos, end); | |
| if (commentText.includes("@typedef") || commentText.includes("@callback")) { | |
| return false; | |
| } | |
| const typedefIndex = text.indexOf("@typedef", pos); | |
| if (typedefIndex !== -1 && typedefIndex < end) { | |
| return false; | |
| } | |
| const callbackIndex = text.indexOf("@callback", pos); | |
| if (callbackIndex !== -1 && callbackIndex < end) { | |
| return false; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string matching for '@typedef' and '@callback' could produce false positives if these strings appear in comment content that isn't actually a typedef or callback declaration (e.g., in documentation text or code examples). Consider using a more precise pattern match that checks for these tags at word boundaries, such as matching
/@typedef\b/and/@callback\b/to ensure they are actual JSDoc tags.