Skip to content

RFC - All Comment as Nodes [WIP] #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: latest
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More examples.
  • Loading branch information
dsherret committed Nov 15, 2019
commit 4b599c174e39bc34ba00bfea39b724e79795a94c
21 changes: 19 additions & 2 deletions rfcs/RFC-0002 - Comment Nodes For All Comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Comment nodes are any single line or multi-line comment in the file. They will w

## Comment Lists

Comment lists are a collection of comments located in the statements of a node or members of nodes like interfaces/classes/etc. that are on one line without any other tokens on that line.
Comment lists are a collection of comments located in the statements of a node or members of interfaces, class declarations & expressions, type elements, object literals, and enums. They must be on one line without any other tokens on that line. The exception is when a close brace token directly follows them and no token preceeds them. Additionally, comments that are between a jsdoc and the declaration it describes are children of the class declaration and therefore not comment lists.

They show up in methods like `#getStatementsWithComments()`, `#getChildren()`, and the new `#getChildrenWithComments()`. For example, the following is a comment list:

Expand All @@ -113,7 +113,21 @@ CommentListStatement
SingleLineCommentTrivia (//3)
```

...and the following lines are all not comment lists:
**Examples of comment lists**

There is one comment list per line with a comment:

```ts
// 1
/* 2 */ // 3
class Test {
// 4
prop;
// 5
/* 6 */ }
```

**Examples of comments that aren't comment lists**

```ts
/*1*/ a; // these two lines have tokens, so not comment lists
Expand All @@ -124,6 +138,9 @@ class test
{

}

/* not a comment list because it ends
on the same line as a token */ b;
```

As described in RFC-0001 about comment statements & members, this is done to allow inserting before and after certain comments.
Expand Down