1

I am looking for a reliable, trusty way to extract all block comments from a javascript file that have loaded into memory as a string.

I see a ton of options online for using regular expressions, but I was looking for a more fail-proof solution.

Namely, using either esprima (http://esprima.org) or falafel(https://github.com/substack/node-falafel), is there a way to take in a string representing some javascript code, and extract all the block comments, and return an array where each entry in the array is a string representing a single block comment?

Also, in case it wasn't clear, I need the parsing to be done in javascript as well (javascript parsing javascript).

Thanks!

2
  • What does "a more fail-proof solution" mean? What's the problem with regular expressions? Commented Apr 16, 2014 at 17:39
  • They don't catch comments inside of strings, which shouldn't be considered comments Commented Apr 17, 2014 at 17:39

1 Answer 1

1

Esprima has a good solution:

http://esprima.org/demo/parse.html

Their "attach comments" option was exactly what I was looking for

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.