Skip to content
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

[BUG] Comments not being removed in latest esbuild #3117

Closed
knaccc opened this issue May 12, 2023 · 3 comments
Closed

[BUG] Comments not being removed in latest esbuild #3117

knaccc opened this issue May 12, 2023 · 3 comments

Comments

@knaccc
Copy link

knaccc commented May 12, 2023

esbuild is not removing all comments. Simple test case:

input file (in.js) contents:

class MyClass {
  // first comment
  /* second comment */
}
// third comment
/* fourth comment */
esbuild --version
0.17.18
esbuild --outfile=out.js in.js

out.js contents:

class MyClass {
  // first comment
  /* second comment */
}

esbuild is removing the third and fourth comments, but not the first and second comments.

Curiously, using --minify does remove all 4 comments, but using --minify-identifiers leaves in the first and second comments.

@evanw
Copy link
Owner

evanw commented May 12, 2023

Comments are removed when minifying: https://esbuild.github.io/api/#minify. Specifically with --minify-whitespace, since comments are a form of whitespace.

@knaccc
Copy link
Author

knaccc commented May 12, 2023

@evanw thanks for your quick reply - perhaps it should be more of a feature request, then, for esbuild to always remove all comments? It caught me by surprise, because at first it seemed to be removing all of the comments when I used it in --minify-identifiers mode.

Then, luckily, I checked again and found that it was removing most of the comments instead of all of the comments.

It seems inconsistent to remove most rather than all, and it's also very useful to be able to use esbuild as a lightning-fast comment stripper instead of using a second tool for that. Thanks again for the incredible work you do.

@evanw
Copy link
Owner

evanw commented May 17, 2023

It seems inconsistent to remove most rather than all

Some comments have been preserved because particular tools have particular semantics associated with them (e.g. #2721). All comments have not been preserved because doing so is a lot of work and it's not currently needed by any third-party tools that I have decided to commit to supporting.

it's also very useful to be able to use esbuild as a lightning-fast comment stripper instead of using a second tool for that

Sorry, esbuild is not a comment stripper. Code formatting is not an intended use case for esbuild. Other tools exist for that.

I'm closing this issue because I do not consider it to be a bug with esbuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants