fix(declarations): keep JSDoc @typedef/@callback comments with their type - #64180
Open
Eugene Kalinin (ekalinin) wants to merge 1 commit into
Open
fix(declarations): keep JSDoc @typedef/@callback comments with their type#64180Eugene Kalinin (ekalinin) wants to merge 1 commit into
Eugene Kalinin (ekalinin) wants to merge 1 commit into
Conversation
… type Declarations reparsed from a JSDoc `@typedef`/`@callback` take the text range of the tag they came from, which sits inside the comment. The printer finds no leading comment there and the comment is instead swept up by the next statement's leading comment scan, so the type is emitted undocumented while an unrelated declaration gets its docs. Add comment ownership to EmitContext: a claimed comment is emitted by its owner and skipped by every other node scanning across it, and the owner emits nothing but the comment it claimed. The declaration transformer claims a JSDoc comment for the first declaration reparsed out of it when every tag in the comment is one that reparses into a declaration of its own. Fixes microsoft#63958
Copilot started reviewing on behalf of
Eugene Kalinin (ekalinin)
September 5, 2026 11:50
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two moderate comment-ownership gaps remain for generic aliases and standalone @import declarations.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Introduces comment ownership so JSDoc @typedef and @callback documentation remains attached to generated declarations.
Changes:
- Adds ownership tracking and printer filtering for claimed comments.
- Claims eligible JSDoc comments during declaration transformation.
- Adds placement tests and updates affected baselines.
Review findings:
- Moderate (1 vote):
transform.go:477excludes@templatefrom declaration-only blocks, leaving generic@typedef/@callbackaliases separated from their documentation. - Moderate (1 vote):
transform.go:507cannot claim standalone@importcomments because reparsed imports lack JSDoc metadata; this path needs correction and standalone regression coverage.
File summaries
| File | Description |
|---|---|
tsc/testdata/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefCommentPlacement.ts |
Adds comment-placement scenarios. |
tsc/testdata/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-and-emits-them-correctly.js |
Updates build output. |
tsc/testdata/baselines/reference/conformance/typedefOnStatements.js |
Preserves comments from elided statements. |
tsc/testdata/baselines/reference/conformance/typedefOnSemicolonClassElement.js |
Preserves a class-element typedef comment. |
tsc/testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.js |
Repositions typedef comments. |
tsc/testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.js |
Repositions typedef comments. |
tsc/testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.js |
Repositions typedef comments. |
tsc/testdata/baselines/reference/conformance/templateInsideCallback.js |
Updates callback/type comment placement. |
tsc/testdata/baselines/reference/conformance/recursiveTypeReferences2.js |
Associates recursive-type comments. |
tsc/testdata/baselines/reference/conformance/linkTagEmit1.js |
Associates linked typedef comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsUniqueSymbolUsage.js |
Repositions typedef documentation. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefPropertyAndExportAssignment.js |
Associates exported type comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefDescriptionsPreserved.js |
Preserves description placement. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefCommentPlacement.types |
Adds the type baseline. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefCommentPlacement.symbols |
Adds the symbol baseline. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefCommentPlacement.js |
Adds the emit baseline. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefAndImportTypes.js |
Updates import-related comment placement. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypeAliases.js |
Updates type-alias comment placement. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js |
Repositions callback/type comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsImportNamespacedType.js |
Moves documentation into the generated namespace. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js |
Associates namespace alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsImportAliasExposedWithinNamespace.js |
Associates namespace alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).js |
Repositions callback documentation. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsFunctionClassesCjsExportAssignment(target=es2015).js |
Associates generated type comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsDefaultsErr(target=es2015).js |
Repositions default alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsDefault(target=es2015).js |
Repositions default alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsClassStatic(target=es2015).js |
Associates options documentation. |
tsc/testdata/baselines/reference/conformance/checkJsdocSatisfiesTag15.js |
Repositions typedef documentation. |
tsc/testdata/baselines/reference/conformance/callbackOnConstructor.js |
Moves callback documentation to its alias. |
tsc/testdata/baselines/reference/compiler/typedefHoisting.js |
Associates hoisted typedef comments. |
tsc/testdata/baselines/reference/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js |
Repositions typedef documentation. |
tsc/testdata/baselines/reference/compiler/jsTypedefMergedWithModuleExportProperty.js |
Associates merged typedef comments. |
tsc/testdata/baselines/reference/compiler/jsdocNonIdentifierPropertiesAndParams.js |
Repositions callback documentation. |
tsc/testdata/baselines/reference/compiler/jsdocMultilineUnion.js |
Associates a multiline typedef comment. |
tsc/testdata/baselines/reference/compiler/jsDocCallbackExport2.js |
Repositions exported callback documentation. |
tsc/testdata/baselines/reference/compiler/jsDocCallbackExport1.js |
Repositions callback documentation. |
tsc/testdata/baselines/reference/compiler/jsDeclarationsInheritedTypes.js |
Associates inherited-type documentation. |
tsc/testdata/baselines/reference/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.js |
Moves typedef documentation to the exported alias. |
tsc/testdata/baselines/reference/compiler/jsDeclarationEmitDoesNotRenameImport.js |
Associates options typedef documentation. |
tsc/testdata/baselines/reference/compiler/exportAssignmentMerging6.js |
Repositions merged typedef comments. |
tsc/testdata/baselines/reference/compiler/exportAssignmentMerging5.js |
Repositions merged typedef comments. |
tsc/internal/transformers/declarations/transform.go |
Claims JSDoc comments for reparsed declarations. |
tsc/internal/printer/printer.go |
Restricts claimed-comment emission to owners. |
tsc/internal/printer/emitcontext.go |
Tracks claimed-comment ownership. |
Review details
- Files reviewed: 44/44 changed files
- Comments generated: 2
- Review effort level: Balanced
Comment on lines
+477
to
+480
| func documentsOnlyReparsedDeclarations(jsdoc *ast.Node) bool { | ||
| tags := jsdoc.AsJSDoc().Tags | ||
| return tags != nil && len(tags.Nodes) > 0 && core.Every(tags.Nodes, isUnhostedJSDocTag) | ||
| } |
Comment on lines
+507
to
+508
| jsdoc := core.FirstOrNil(original.EagerJSDoc(file)) | ||
| if jsdoc == nil || !documentsOnlyReparsedDeclarations(jsdoc) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #63958
A JSDoc
@typedef/@callbackpreceded by another top-level declaration loses its comment to the next statement: