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

Support traverse of comments #9

Closed
mamacdon opened this issue Jul 25, 2013 · 2 comments
Closed

Support traverse of comments #9

mamacdon opened this issue Jul 25, 2013 · 2 comments

Comments

@mamacdon
Copy link

Esprima can include source code comments in its AST. For example, when parsing this code with the comment:true flag:

function f(){
    /*hello*/
    //world
}

Esprima returns this AST:

{
    "type": "Program",
    "body": [ /* omitted to save space */ ],
    "comments": [
        {
            "type": "Block",
            "value": "hello"
        },
        {
            "type": "Line",
            "value": "world"
        },
    ]
}

It would be helpful for estraverse to visit the comment nodes. Currently it does not.

(I believe comments are an Esprima extension to the Spidermonkey API, so this may be non-standard. But it would be really useful for downstream projects. For example, I'm currently trying to write a linting rule for ESLint that deals with comments, and fixing this issue is a prerequisite.)

mamacdon added a commit to mamacdon/estraverse that referenced this issue Jul 25, 2013
@michaelficarra
Copy link
Member

Just use escodegen's attachComments and access the leadingComments member of the nodes as you visit them in a regular traversal. In your PR (#10), they are treated as regular nodes (not desirable) and just stuck on the end of the traversal (also not desirable).

@mamacdon
Copy link
Author

OK

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

No branches or pull requests

2 participants