Comment ranges at wrong location
See original GitHub issueTry to run the following code in e.g. RunKit:
var meriyah = require("meriyah")
var escodegen = require("escodegen")
var esprima = require("esprima")
var code = `try{}//
finally{}
try{}
catch(e){}//
finally{}
{
try{}
catch(e){}//
finally{}
}
`;
var merComments = [];
var merTokens = [];
var merTree = meriyah.parse(code, {
ranges: true,
onComment: function(type, value, start, end) {
type = type === 'SingleLine' ? 'Line' : 'Block';
merComments.push({type: type, value: value, range: [start, end]});
},
onToken: function(type, start, end) {
merTokens.push({ type: type, range: [start, end]});
}
});
merTree = escodegen.attachComments(merTree, merComments, merTokens);
var merCode = escodegen.generate(merTree, { comment: true });
var espriTree = esprima.parse(code, { comment: true, range: true, tokens: true });
espriTree = escodegen.attachComments(espriTree, espriTree.comments, espriTree.tokens);
var espriCode = escodegen.generate(espriTree, { comment: true });
[merComments, espriTree.comments, merTree, espriTree, merCode, espriCode]
If you then compare the ranges in the comment array for both Meriyah and Esprima, then you will see the values are not the same (start is 2 under, end is 1 under). If you then look at the generated code, which are generated from the Meriyah and Esprima tree and compare them, then you will see the comments are placed at the wrong places from the Meriyah tree.
Generated code from Esprima tree
try {
} //
finally {
}
try {
} catch (e) {
} //
finally {
}
{
try {
} catch (e) {
} //
finally {
}
}
Generated code from Meriyah tree
try {
} finally
//
{
}
try {
} catch (e) {
} //
finally {
}
{
try {
} catch (e) {
} //
finally {
}
}
-Thomas
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Create comments from a selected range - vba
The following code will accept two range inputs from the user. One for the range that needs comments, and one for the range...
Read more >Range.Address property (Excel)
Returns a String value that represents the range reference in the language of ... The comments in the example are the addresses that...
Read more >The VBA Guide To Named Ranges
Creating a named range allows you to refer to a cell or group of cells with a custom name instead of the usual...
Read more >Referencing Pivot Table Ranges in VBA
AddComment Range("H6").Comment.Visible = False Range("H6").Comment.Text Text:="Jon Peltier:" & Chr(10) & "Low sales on this day" End Sub.
Read more >Commenting on a pull request
Optionally, to suggest a specific change to the line or lines, click , then edit the text within the suggestion block. Suggestion block....
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
That’s a weird spec, it’s different from comment in html format. Since the spec says
I will make the start of HTMClose comment before “\n–>”
HTML comment is part of the AnnexB extension. Same as other parsers. HTML comment skips either
<!--
or-->
and then parsed as a single line comment.