esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Single-line, non-license comment preserved in output

Open bbrk24 opened this issue 1 year ago • 2 comments

Current reproducer (haven't tried to minimize it): https://github.com/bbrk24/template-qdeql/tree/2d25c18334d914c15b3932baac03db60c849d3ef

The output index.mjs includes one single-line comment:

    // output is always UTF-8

Either this is a bug because that comment is emitted when it shouldn't be, or because no other single-line comment is emitted and they all should.

bbrk24 avatar Oct 12 '24 01:10 bbrk24

esbuild intentionally keeps some comments because there're maybe other tools relying on them to work properly. For example vite supports /* vite-ignore */, some coverage tools may read /* istanbul ignore */ etc. However, esbuild is not designed to keep all comments.

If you want to remove all comments, you can enable --minify-whitespace.

Example.

hyrious avatar Oct 12 '24 02:10 hyrious

Why would it keep that comment in particular though? What makes that comment different from the other comments in the file or the rest of the project?

bbrk24 avatar Oct 12 '24 02:10 bbrk24

Comments in expression position are sometimes preserved because some tools that use esbuild to transform code make use of them. These comments are intended for machines, not for humans, and were added due to specific requests (for example: https://github.com/evanw/esbuild/issues/2721). This behavior is deliberate, and is not a bug.

Comments in statement position aren't currently preserved unless they contain special pragmas. Legal comments are used by library authors to encourage users of their libraries to embed notices about copyright or similar things. This is described in the documentation here: https://esbuild.github.io/api/#legal-comments. This behavior is also deliberate, and is also not a bug.

evanw avatar Oct 16 '24 21:10 evanw