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

Comments are not removed in build with Angular ESBuild #3586

Closed
mirobo opened this issue Jan 12, 2024 · 2 comments
Closed

Comments are not removed in build with Angular ESBuild #3586

mirobo opened this issue Jan 12, 2024 · 2 comments

Comments

@mirobo
Copy link

mirobo commented Jan 12, 2024

Hey there

I'm not sure if this is an issue in ESBuild or in Angular CLI, but the JS-bundles created end up still having comments like:

  /**
   * Check if the given MIME is a JSON MIME.
   * JSON MIME examples:
   *   application/json
   *   application/json; charset=UTF8
   *   APPLICATION/JSON
   *   application/vnd.company+json
   * @param mime - MIME (Multipurpose Internet Mail Extensions)
   * @return True if the given MIME is JSON, false otherwise.
   */

According to the docs and this comment, they should be removed by default?

   You are correct, esbuild does not preserve comments. It's not built to preserve comments. Preserving comments means it would operate more like a code formatter than a compiler. For example, you would probably want a token spanning tree instead of an AST. Doing this is currently a non-goal of esbuild. You should probably be using another tool for this.

Originally posted by @evanw in #516 (comment)

Also this comment doesn't contain @preserve , @license, //! or /*!.. so it should be a "normal" comment, that should be removed?

Versions:
Node: 20.10.0 (Windows 10)
ESbuild: 0.19.5
Angular: 17.0.8

@mirobo mirobo changed the title You are correct, esbuild does not preserve comments. It's not built to preserve comments. Preserving comments means it would operate more like a code formatter than a compiler. For example, you would probably want a token spanning tree instead of an AST. Doing this is currently a non-goal of esbuild. You should probably be using another tool for this. Comments are not removed in build with Angular ESBuild Jan 12, 2024
@evanw
Copy link
Owner

evanw commented Jan 12, 2024

Since then, comment preservation was added for more kinds of comments. See also #2721 and v0.16.14. There is still no guarantee that esbuild will preserve all comments but it does now make an attempt to preserve comments in certain AST locations that are important for the major tools that use esbuild as a TypeScript transformation step.

@evanw
Copy link
Owner

evanw commented Jan 23, 2024

I'm closing this as it's working as intended, for the reasons described above.

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 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

2 participants