-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments are not handled at all? #40
Comments
Finally, I found a way to extract all comments: var comments = new List<Comment>();
do
{
comments.AddRange(scanner.ScanComments());
token = scanner.Lex();
tokens.Add(token);
} while (token.Type != TokenType.EOF); But:
|
I think the issue is related to this PR that I seem to have skipped https://github.com/jquery/esprima/pull/1439/files Each node is passed to |
Checked and the following code works just as expected: var scanner = new Scanner(source, new ScannerOptions { Comments = true });
var comments = scanner.ScanComments(); For extracting all the comments, you can do what you invented here but please be aware that tokenization is not always possible. (For more details, see #44 (comment)) A reliable way to extract comments is the following: var parser = new JavaScriptParser(new ParserOptions { Comments = true });
var root = parser.ParseScript(source);
var comments = root.Comments; All the comments contained in the parsed code will be listed in the |
Consider the following javascript code:
// c
I'm trying to get all comments with the following code:
But getting an empty
comments
collection.The following code also does not work (from Esprima.Sample):
Returns only a single empty token:
How can I handle them?
The text was updated successfully, but these errors were encountered: