This shows use cases where a simple regex like the one on StackOverflow cannot be relied upon for 100% accuracy in detecting comments in code.
var foo = "There's no way to tell that this /* is not the beginning of a comment";
var bar = "There's no way to tell that this */ is not the end of a comment";
var baz = "There's no way to tell that this // is not a single line comment";
var buz = "Matters get much worse when there are escaped \" quotes /* inside the string. Definitely need a parser.";
var fiz = `And there is
really no way to // detect that these are
/* not real comments */
within a JS template literal.
`;
var foo = {
bar:// regex cannot distinguish "bar://" from "http://"
"the value for bar is dangling down here - this is valid"
};
{
include: [
"src/**/*.js
],
exclude: [
"src/**/*.test..js
]
}
It deleted a needed closing brace that wasn't part of a comment, immediately preceding a double-slashed comment. In fact, looking at the demo link provided on SO, it also incorrectly removes a comma preceding a double-slashed quote, within the original poster's own test data. And in my own code, it's removing preceding line breaks. It looks like it indiscriminately removes the character before a // comment.