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

Single-line, non-license comment preserved in output #3943

Closed
bbrk24 opened this issue Oct 12, 2024 · 3 comments
Closed

Single-line, non-license comment preserved in output #3943

bbrk24 opened this issue Oct 12, 2024 · 3 comments

Comments

@bbrk24
Copy link

bbrk24 commented Oct 12, 2024

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.

@hyrious
Copy link

hyrious commented Oct 12, 2024

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.

@bbrk24
Copy link
Author

bbrk24 commented Oct 12, 2024

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?

@evanw
Copy link
Owner

evanw commented Oct 16, 2024

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: #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.

@bbrk24 bbrk24 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2024
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

3 participants