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.

Comment ranges at wrong location

See original GitHub issue

Try 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
3cpcommented, Oct 14, 2020

That’s a weird spec, it’s different from comment in html format. Since the spec says

SingleLineHTMLCloseComment::
LineTerminatorSequenceHTMLCloseComment

I will make the start of HTMClose comment before “\n–>”

// For Single, start before "//",
// For HTMLOpen, start before "<!--",
// For HTMLClose, start before "\n-->"
0reactions
KFlashcommented, Oct 13, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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