question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m trying to use attachComments functionality of escodegen, which gets tree,comments,tokens as arguments.

Unfortunately, it doesn’t preserve the comments using Meriayh and it looks like the tokens types and range are different than what escodegen expect to have.

I tried the following scenario:

`

const sourceCode = `
  //Comment1
  const test1 = 1;
  //Comment2
  const test2 = 2;
`;
let tokens = [];
let comments = [];
let tree = meriyah.parse(sourceCode, {
  ranges: true,
  globalReturn: true,
  onToken: function (type, start, end) {
    let value = this.tokenValue ? this.tokenValue.toString() : '';
    tokens.push({type: type, value: value, range: [start, end]});
  },
  onComment: function (type, value, start, end) {
    type = type === 'SingleLine' ? 'Line' : type;
    type = type === 'MultiLine' ? 'Block' : type;
    comments.push({type: type, value: value, range: [start, end]});
  }
});
replaceStartEndToRange(tree);

tree = escodegen.attachComments(tree, comments, tokens);
const res = escodegen.generate(tree, {
  sourceCode: sourceCode,
  format: {
    compact: false,
    preserveBlankLines: true
  },
  comment: true
});
expect(res).to.be.equal(sourceCode);

`

sourceCode: //Comment1 const test1 = 1; //Comment2 const test2 = 2;

res: const test1 = 1;

 const test2 = 2;

As you can see, the comments are missing.

I use “meriyah”: “1.9.12” “escodegen”: “1.14.1”

BTW, it works with Esprima.

Thanks, Niv

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mamanivcommented, May 27, 2020

Works now. Thank you!

1reaction
KFlashcommented, May 27, 2020

Released v. 1.9.14.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attach files to a comment - Document Manager
The file attachment is associated with a specific comment. If you attach a file, you must also enter text in the Text Comments...
Read more >
Adding comments & attachments to tasks - Asana
This section of the Asana Guide tells you how to add comments and attachments to tasks and explains how to use connected work...
Read more >
Attaching File as a Comment - Qoppa Software
When attaching a file as a comment an icon is added to the page letting the user know that a file has been...
Read more >
Insert or delete a comment - Microsoft Support
Insert or delete comments that appear in a document margin. ... Attaching your comments to specific parts of a document makes your feedback...
Read more >
Insert, delete, or change a comment - Microsoft Support
Insert a comment. Select the text you want to comment on, or click at the end of the text. On the Review tab,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found