Skip to content

feat(printer): implement JSDoc node emission - #65430

Open
el-j (el-j) wants to merge 3 commits into
microsoft:mainfrom
el-j:fix/printer-jsdoc-nodes
Open

el-j (el-j) wants to merge 3 commits into
microsoft:mainfrom
el-j:fix/printer-jsdoc-nodes

Conversation

@el-j

@el-j el-j (el-j) commented Nov 10, 2026 •

Copy link
Copy Markdown

Fixes #65429

Analysis

Printer.emitJSDocNode in tsc/internal/printer/printer.go is a stub (panic("not implemented")), so any JSDoc AST node that reaches the printer, for example one built with NodeFactory.NewJSDoc, crashes it:

doc := factory.NewJSDoc(factory.NewNodeList([]*ast.Node{factory.NewJSDocText([]string{"desc"})}), nil)
printer.NewPrinter(opts, printer.PrintHandlers{}, nil).Emit(doc, nil) // panic: not implemented

Fix

Implements JSDoc emission in the printer: the comment text and the tags (@param, @returns, @type, @typedef, etc.), single-line vs multi-line layout, and the related type expression and name nodes. It also adds a small supporting change in tsc/internal/ast/precedence.go. Tests are in printer_test.go.

Review feedback is addressed in 7ae20f1: documented @property/@param children are kept as separate tag lines, qualified @typedef/@callback names keep their last component, tag comments starting with a newline keep their content, and tests now print JSDoc nodes directly.

This is intentionally scoped to the printer only. An earlier attempt (#65058, closed) also added synthetic-comment API plumbing. That overlaps with open PR #64500, so it is left out here.

Related (not fixed here): #64429 / #64500 (API support for synthetic comments and emit flags), #17146 (transforming and emitting JSDoc comments).

Copilot Checklist

I successfully ran the applicable command at the end of my session, and it completed without error:

  • npx hereby validate
  • npx hereby validate --api (for TypeScript API changes) — not applicable, no API changes

el-j (el-j) and others added 2 commits November 10, 2026 16:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 16:02
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 10, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The JSDoc emitter drops qualified-name components and documentation content, while regression tests bypass the new emitter and leave key behavior unverified.

4 open issues
What changed in this PR

Implements JSDoc AST emission in the native TypeScript printer, replacing the panic reported in #65429. The change stays focused on printing and leaves synthetic-comment API support to #64500.

Changes:

  • Adds formatting for JSDoc comments, tags, links, names, and related type nodes.
  • Adds precedence handling for additional JSDoc node kinds.
  • Adds printer tests for JSDoc output and whitespace preservation.
File Description
tsc/​internal/​printer/​printer.go Implements JSDoc node emission and formatting helpers.
tsc/​internal/​printer/​printer_test.go Adds direct-node and source-comment emission tests.
tsc/​internal/​ast/​precedence.go Defines precedence for additional JSDoc node kinds.

Review effort: Balanced

Comment thread tsc/internal/printer/printer.go Resolved
Comment thread tsc/internal/printer/printer.go Resolved
Comment thread tsc/internal/printer/printer.go Resolved
Comment thread tsc/internal/printer/printer_test.go Resolved
- keep continuation lines when a tag comment starts with a newline
- keep documented @property/@PARAM children as separate tag lines
- print the terminal identifier of qualified typedef/callback names
- omit the stray space after {@link name} without text
- test JSDoc emission by printing JSDoc nodes directly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@el-j

Copy link
Copy Markdown
Author

This fixes a crash in the printer (emitJSDocNode panics) that is also present in 7.1 Beta. If the team considers it suitable, could it be cherry-picked to release-7.1 once it lands on main? Happy to adjust anything first. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Native printer panics when printing JSDoc AST nodes (emitJSDocNode not implemented)

2 participants