-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(build): Fix regex in multiline-comment-removal Rollup plugin #5783
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
fix(build): Fix regex in multiline-comment-removal Rollup plugin #5783
Conversation
Why are we only removing multiline comments? If we were to remove all comments we could simply use a library to do this for us (eg terser), and avoid reinventing the wheel and running into issues that have already been solved. Something like the following maybe? terser({
// remove all comments
format: {
comments: false
},
// prevent any compression
compress: false
}) |
Both reasonable questions. Mostly what you're seeing is that I originally just wanted a super-fast hack to clean up the generated templates, and it didn't feel worth it to involve as much machinery as As for why only multi-line comments... that just happens to be the ones I wanted to get rid of. 🙂 And in the particular case of the templates, I do think there's some small utility in keeping the one So... keep the hack? Don't keep the hack (which means getting rid of all comments)? As much as it is admittedly a tiny bit uglier, I lean ever-so-slightly towards keeping the hack, and perhaps changing the note to label it as such and point to a library rather than give the fuller regex. It would mean that the one useful comment can stay, and it would also save the time of debugging a new plugin. Open to being swayed on that score, though. UPDATE: I was torn, so I checked it out. Terser is definitely more than what we want (with default settings on, it makes all sorts of other changes to the code I'm not interested in), and |
26c2635
to
07411ac
Compare
Writing from my phone so no fancy formatting: Can you try adding the "extensions" option with "ts" to the cleanup plugin? It would calm my nerves knowing that a dedicated library is taking care of this. Sorry if this is annoying. |
I also quickly discussed this with @AbhiPrasad and we are both of the opinion that attempting to remove comments with a regex is a bit dangerous and that the upside of only having single-line comments is not entirely clear. In order to reduce review/discussion cycles I decided to open a PR that implements |
Since this only affects three files, and we're still discussing the best long-term solution here, I'd like to merge this so that I can unblock other PRs. Can we do that and continue the conversation offline, please? |
Sounds good! |
The existing regex, when presented with code like this:
matches everything between the initial
/*
on the first line and the final*/
on the second-to-last line, and the plugin thus removes all but the last line of the file. This fixes the regex so that only the comments are removed.