microsoft / microsoft/TypeScript

getTrailingCommentRanges returns comments at the start of the file

Open
#29,625 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: API In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: master

Code:

// one
// two

Expected behavior:

ts.getTrailingCommentRanges(text, 0) doesn't return a comment.
Both comments are parsed by ts.getLeadingCommentRanges(text, 0).

Actual behavior:

ts.getTrailingCommentRanges(text, 0) parses // one as a trailing comment.
ts.getLeadingCommentRanges(text, 0) parses both comments.

The special handling of position 0 should also affect trailing comments.
With the current behavior I have to remember to not parse trailing comment ranges at position 0 to avoid duplicates.

Related Issues:
This was part of https://github.com/Microsoft/TypeScript/pull/28489 where I first proposed changing this behavior.

/cc @rbuckton

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 TypeScript implementation of ts.getTrailingCommentRanges and ts.getLeadingCommentRanges, then review the related change in pull request #28489. Reproduce the behavior using the two-line comment example at position 0 and verify that trailing ranges no longer duplicate comments returned as leading ranges.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.