sourceMappingURL inside string literal
Hi :wave: We have been using this package mostly succesfully in Babel for a long time (thank you for maintaining it!), but we have received some bug reports about "fake" source map comments being removed from strings.
For example,
const comment = `
//# sourceMappingURL=${path.basename(
sourceMapFilename
)}`
is removed by the removeMapFileComments method.
I tried to fix this problem by implementing some logic to skip strings and template literals (you can find it at https://github.com/nicolo-ribaudo/convert-source-map/tree/comments-strings). Then, I realized that regular expressions make it impossible to know if something is a comment or not without fully parsing the whole JavaScript file.
For example, this file has a source map comment:
function* f() {
yield /a`/g //
}
//#sourceMappingURL=file.map
// ` } /*
/*/ // */
While this one doesn't: (I only replaced function* with function)
function f() {
yield /a`/g //
}
//#sourceMappingURL=file.map
// ` } /*
/*/ // */
(Don't trust GitHub's syntax highlighter; it's wrong)
For this reasons, I don't think that this problem can be fixed in this package, but I'm opening this issue to let you know about this limitation (maybe you could write in the readme that "fake" comments inside strings don't work?).
I'm working around this problem in Babel by first parsing the file with @babel/parser, and then analyzing the comments and using fromComment/fromMapFileComment to convert them.
Babel issues: https://github.com/babel/babel/issues/9790, https://github.com/babel/babel/issues/9956, https://github.com/babel/website/pull/2020/commits/d24c80ebd37708c7d50b335dae1e26c88da5ad8a