Skip to content

How to make this work with Espree #3

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

Closed
aminya opened this issue Apr 25, 2021 · 8 comments
Closed

How to make this work with Espree #3

aminya opened this issue Apr 25, 2021 · 8 comments

Comments

@aminya
Copy link
Contributor

aminya commented Apr 25, 2021

Espree doesn't have onComment like acorn. How can I make this work with Espree?

@wooorm
Copy link
Member

wooorm commented Apr 25, 2021

That’s described in the readme of espree https://github.com/eslint/espree#options.

@wooorm wooorm closed this as completed Apr 25, 2021
@aminya
Copy link
Contributor Author

aminya commented Apr 25, 2021

It doesn't work. Passing true to comments doesn't create an array.

@wooorm
Copy link
Member

wooorm commented Apr 25, 2021

at the top of the resulting node, as it says, did you try that?

@aminya
Copy link
Contributor Author

aminya commented Apr 25, 2021

Yes.

Parsing this file:

const espree = require("espree")
const { attachComments } = require('./vendor/estree-util-attach-comments.cjs')

code = `
        /**
         * @callback MyCallback
         * @param {number} arg1
         */
        const cb = (arg) => 1;
        `
ast = espree.parse(code, {comments: true, ecmaVersion: 2021})
console.log(ast)

Gives:

Node {
  type: 'Program',
  start: 0,
  end: 128,
  body: [
    Node {
      type: 'VariableDeclaration',
      start: 97,
      end: 119,
      declarations: [Array],
      kind: 'const'
    }
  ],
  sourceType: 'script'
}

There is nothing to pass to attachComments

I want the original attach comment behavior. Not sure if this package helps
eslint/js#405

@wooorm
Copy link
Member

wooorm commented Apr 25, 2021

The readme says comment, not comments: https://runkit.com/embed/z582pgdkpvzx

@aminya
Copy link
Contributor Author

aminya commented Apr 25, 2021

Ah, thanks! I am going to make a PR adding the example to the readme.

@wooorm
Copy link
Member

wooorm commented Apr 25, 2021

Thanks, appreciate it — but: I’m not interested in a list of examples for every JS parser, because there are so many. Maybe something small?
Although a typo can happen to everyone, the docs of acorn and espree are pretty clear, wouldn’t you say?

@aminya
Copy link
Contributor Author

aminya commented Apr 25, 2021

Created one: #4

Feel free to merge.

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

No branches or pull requests

2 participants