microsoft / microsoft/TypeScript

tsc looses trailing comments in the produced js files

Open
#60,811 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Comment Emit Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms

"missing comments", "missing comments in .js output", "trailing comments"

🕗 Version & Regression Information

Happens in every version available in the playground (3.3.3 to v5.8.0-dev.20241218)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.2#code/MYGwhgzhAECC0G8CwAoa7oHpPQNYFN8AHAWggHsAnAF3wBNoJqwbUNoBbfagC3LtgAKAJSI27DMHIA7CiHwA6EOQDmggEQUa9dcIDc49AF9DWHAWJkqtBvml1URoA

💻 Code
class A {
    // keep-sorted start
    methodA() {
        console.log("sorted");
    }
    // keep-sorted end
}
🙁 Actual behavior

// keep-sorted end is missing in the .js output.

🙂 Expected behavior

// keep-sorted end is retained in the .js output.

Additional information about the issue

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground reproduction and compare the emitted JavaScript with the expected output. Trace the compiler path responsible for preserving trailing comments, then add or update a regression test so the // keep-sorted end comment remains in the generated file.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.