CommonJS plugin fails when strings contain comment markers
Versions
- node: 10.19.0
Reproduction
Attempt to import a minimized CommonJS module (I'm using zingchart-nodejs.min via @zingsoft/zingchart-svelte).
What is Expected?
It should be imported with no errors.
What is actually happening?
An error regarding an unterminated string is reported. The location given is for a comment marker // in the middle of a quoted string.
I took a look at the code (src/lib.ts). It looks as though you're stripping comments out without handling the case where the comment marker is inside a quoted string.
Perhaps the easiest way to fix this is to add an option to specify that the module you're importing is already minified and has no comments, and then don't call removeComments() if this option is enabled. Alternatively, you can just remove removeComments() completely, it doesn't matter if you convert a require into an import inside a comment.