-
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?
Conversation
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.
Pull request overview
This PR fixes a bug where JSDoc @typedef and @callback comments were being duplicated in TypeScript declaration files. The comments were appearing both as converted TypeScript type declarations (correct) and as the original JSDoc comments (duplicate).
Changes:
- Modified the
shouldWriteCommentfunction in the emitter to detect and skip@typedefand@callbackcomments during declaration emit - Updated baseline test files to reflect the removal of duplicate JSDoc comments
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/compiler/emitter.ts | Added logic to filter out @typedef and @callback comments when emitting declarations |
| tests/baselines/reference/*.js | Updated baseline expectations to reflect removal of duplicate JSDoc comments in declaration files |
| // 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")) { |
Copilot
AI
Jan 12, 2026
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.
| if (commentText.includes("@typedef") || commentText.includes("@callback")) { | |
| if (/@typedef\b/.test(commentText) || /@callback\b/.test(commentText)) { |
| const commentText = text.slice(pos, end); | ||
| if (commentText.includes("@typedef") || commentText.includes("@callback")) { | ||
| return false; | ||
| } |
Copilot
AI
Jan 12, 2026
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.
Creating a substring via slice() for every comment during emit could impact performance when processing files with many comments. Consider checking for the presence of '@typedef' or '@callback' using indexOf() with boundary checks on the original string instead of creating a new substring.
| 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; | |
| } |
|
Both suggestions would deviate from existing codebase conventions, but happy to make a change if a human replies. |
Fixes #62453.
When emitting declaration files from JavaScript with JSDoc
@typedefand@callbacktags, the comments were being emitted twice: once as converted TypeScript type declarations (correct) and once as raw JSDoc comments (duplicate).The fix skips emitting
@typedefand@callbackcomments during declaration emit since they are already represented as type declarations.