Skip to content

feat(tsdoc): Don't replace line breaks when emitting comments - #443

Merged
Ian Clanton-Thuon (iclanton) merged 6 commits into
microsoft:mainfrom
Josmithr:josmithr/dont-strip-line-breaks
Mar 31, 2026
Merged

feat(tsdoc): Don't replace line breaks when emitting comments#443
Ian Clanton-Thuon (iclanton) merged 6 commits into
microsoft:mainfrom
Josmithr:josmithr/dont-strip-line-breaks

Conversation

@Josmithr

@Josmithr Joshua Smithrud (Josmithr) commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

Preserves line breaks when emitting TSDoc comments. Ensures information is not lost.

Comment thread common/config/rush/command-line.json
Comment thread tsdoc/src/__tests__/__snapshots__/DocNodeTransforms.test.ts.snap Outdated
@Josmithr Joshua Smithrud (Josmithr) changed the title feat(tsdoc): Don't strip line breaks when parsing comments feat(tsdoc): Don't strip line breaks when emitting comments Oct 7, 2025
@Josmithr Joshua Smithrud (Josmithr) changed the title feat(tsdoc): Don't strip line breaks when emitting comments feat(tsdoc): Don't replace line breaks when emitting comments Oct 7, 2025
@octogonz

Copy link
Copy Markdown
Collaborator

This LGTM but I'm currently traveling, so I'm not able to test it.

Ian Clanton-Thuon (@iclanton) maybe you can try it in the playground?

@iclanton

Ian Clanton-Thuon (iclanton) commented Oct 9, 2025

Copy link
Copy Markdown
Member

Joshua Smithrud (@Josmithr), can you provide some examples of what this actually changes? Maybe inputs and diffs of the before/after outputs?

…s_2025-10-07-21-19.json

Co-authored-by: Ian Clanton-Thuon <iclanton@users.noreply.github.com>
@Josmithr

Joshua Smithrud (Josmithr) commented Nov 17, 2025

Copy link
Copy Markdown
Contributor Author

Joshua Smithrud (@Josmithr), can you provide some examples of what this actually changes? Maybe inputs and diffs of the before/after outputs?

Ian Clanton-Thuon (@iclanton) Sorry, I completely missed the notifications on this and have been working in other areas.

The main goal here is to preserve the doc author's line breaks when parsing the comments. This makes round-tripping of comments non-lossy.

For example, consider this multi-line TSDoc comment:

/**
 * Hello
 * world
 * !
 */

Round-tripping this comment through TSDoc's current parser and emitter will yield:

/**
 * Hello world!
 */

Which is lossy and potentially changes the doc-author's intention. Where with my above changes you would get the original comment with its original line formatting.

A particularly relevant case that can be useful to tools consuming the parsed comment is preservation of list-like syntax. Consider the following:

/**
 * Prerequisites:
 * - Foo
 * - Bar
 */

This is currently parsed the same as:

/**
 * Prerequisites: - Foo - Bar
 */

Which loses important contextual information.

Hopefully that makes sense. Happy to provide more context or capture more of this with tests (if desired and if I can get some guidance as to where such tests should go).

@Josmithr

Copy link
Copy Markdown
Contributor Author

Ian Clanton-Thuon (@iclanton) Pete Gonzalez (@octogonz) Hoping to get some assistance getting this across the finish line.

…-strip-line-breaks

# Conflicts:
#	common/config/rush/command-line.json

@octogonz Pete Gonzalez (octogonz) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Joshua Smithrud (@Josmithr) 🙏 Sorry this took so long to get to!

@iclanton
Ian Clanton-Thuon (iclanton) merged commit 2dd8912 into microsoft:main Mar 31, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants