esprima
esprima copied to clipboard
Include Comment Style in LineComment and BlockComment Nodes
Multiple different Javascript snippets can result in a LineComment node:
// type1
<!-- type2
--> type3
From current Esprima's output there's no way to know which one of these 'styles' was used as a comment.
Since this is specific to LineComment nodes, it's possible to split the type of node from 'LineComment' into 3 node types (one for each style). But I assume that would completely break the API. I offer the solution of adding 'style' attribute to Comment nodes (both Block and Line). The values can be: ['//', '', '/*'].
I believe this API change is relatively minor since we're only adding an attribute without replacing any existing ones. We will have to change the Comment section in the Esprima API documentation. There shouldn't be any performance degradation since the comment style is known while parsing, it just wasn't exposed to the AST.