Skip to content
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

Trailing comments are lost #52

Open
pd4d10 opened this issue Sep 24, 2018 · 2 comments
Open

Trailing comments are lost #52

pd4d10 opened this issue Sep 24, 2018 · 2 comments

Comments

@pd4d10
Copy link
Contributor

pd4d10 commented Sep 24, 2018

Like this:

namespace js test // trailing comment

Output:

{
  "type": "ThriftDocument",
  "body": [
    {
      "type": "NamespaceDefinition",
      "scope": {
        "type": "Identifier",
        "value": "js",
        "loc": {
          "start": {
            "line": 1,
            "column": 11,
            "index": 10
          },
          "end": {
            "line": 1,
            "column": 13,
            "index": 12
          }
        }
      },
      "name": {
        "type": "Identifier",
        "value": "test",
        "loc": {
          "start": {
            "line": 1,
            "column": 14,
            "index": 13
          },
          "end": {
            "line": 1,
            "column": 18,
            "index": 17
          }
        }
      },
      "comments": [],
      "loc": {
        "start": {
          "line": 1,
          "column": 1,
          "index": 0
        },
        "end": {
          "line": 1,
          "column": 18,
          "index": 17
        }
      }
    }
  ]
}
@pd4d10
Copy link
Contributor Author

pd4d10 commented Sep 24, 2018

Comment interface now has only type and value. How about adding a property called position, like this:

export interface CommentLine extends SyntaxNode {
  type: SyntaxType.CommentLine
  value: string
  position: 'leading' | 'trailing' // Added
}

Just a proposal. If OK, I could try to submit a PR to fix this

@kevin-greene-ck
Copy link
Contributor

This sounds good to me. I'm not personally using the parsed comments at the moment, but this certainly seems the least invasive way to add this information. If I was doing this from the start I would have added leadingComments and trailingComments properties to the nodes to mimic what Babylon/TSC does with JS.

A PR would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants