Attach comments
See original GitHub issueI’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:
- Created 3 years ago
- Comments:15 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Works now. Thank you!
Released v. 1.9.14.