microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.38k stars 12.4k forks source link

Magic Comments #47955

Closed last-Programmer closed 2 years ago

last-Programmer commented 2 years ago

Pardon me for not using the existing form.

Feature Request:

if the typescript file contains

/ magic comments / / webpackChunkName: "VendorSmartWebComponentsCharts" / / magic comments /

It would be helpful if tsc compiler keeps this magic comments when removecomments in tsconfig.json is set to true.

RyanCavanaugh commented 2 years ago

The leading comment in a file will be preserved if it starts with /*!. Also if you're passing tsc's output to a downstream bundler, why not just have the downstream bundler remove the comments instead?

I'm legitimately curious why you ignored the template - why do you think we have it?

last-Programmer commented 2 years ago

The leading comment in a file will be preserved if it starts with /*!.

read about this in stackoverflow Also if you're passing tsc's output to a downstream bundler, why not just have the downstream bundler remove the comments instead?

This will make us to think why typescript and we would have stayed with javascript.

I'm legitimately curious why you ignored the template - why do you think we have it? Honestly, spent some time on reading the template and filling it and could not follow/understand it.Lost patience and posted this issue.

Workaround used: The magic comments file ended as javascriipt and .js mixing up with typescript project is not satisfactory.

Would be happy if the problem is instead taken care at the origin.

last-Programmer commented 2 years ago

All of us cant read the down voters thoughts and understand why they did so. So thumbs down voters please come forward and be explicit. So that the typescript team can analyse the nature of the issue and take action. Thanks in advance.

Retsam commented 2 years ago

A lot of the downvotes are probably from skipping the template - Typescript gets a lot of issues filed, and filling out the template helps the team manage them - it doesn't come across as very respectful of the team's time when you skip it.


It's also not really clear what you're suggesting. You're saying "TS should keep magic comments" - how is TS supposed to know what comments are "magic comments"? That's the point of the /*! syntax, to mark what comments TS should preserve. (Though I think it's more commonly used for comments that must be maintained for legal reasons - like Ryan said, if you're using a bundler, it probably makes more sense to let the bundler strip out the comments)

MartinJohns commented 2 years ago

That's the point of the /*! syntax, to mark what comments TS should preserve.

Worth pointing out that this only works for the first comment at the top of the file. It's not a syntax to generally preserve comments.

last-Programmer commented 2 years ago

With the current typescript comment syntax, only first line comment with /*! is passed on to javascript. Its like who comes first 🍏 find the way to javascript 🌍 and the rest 🍎stuck in typescript 🌐. this is not a fair rule/design.

typescript is unique with its feature set. it may have thought about having different commenting system syntax like /@---------------------@/ and with the use of tsconfig if the typescript programmer wants to keep the comments in compiled javscript files it can transform typescript comment syntax to javascript comment syntax or strips the typescript syntax comments if the typescript programmer wants.

This way if typescript finds javascript syntax comments it can safely pass them to javascript untouched.

typesript may have thought about this. but there may not be need for that at time. but now typescript world needs it.

typescript should think about this and it should change and improve its world. so that rest 🍏 can also exit to javascript 🌍so that the justice is served. typescript programmer can find million alternate ways to do this. that is not the change the world want to see. even typescript would think so if it wants to improve.

Typescript can think of this possible solutions and many more.

  1. all the comments inside /*! can exit to javascript 🌍 with the destination world comment syntax.
  2. none of comments inside /*! can exit to javascript 🌍
  3. create a unique comment syntax system for typescript and leave the javascript 🌍 in peace.

Come on typescipt change yourself and have some fun.

typescript-bot commented 2 years ago

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community.

last-Programmer commented 2 years ago

@typescript-bot @RyanCavanaugh this is not a question. it can be actionable in code.

RyanCavanaugh commented 2 years ago

@last-Programmer You requested a way to retain some comments in emit. I provided two of them, one of which is basically what you asked for, and one of which seems like the more logical solution for the scenario. Combined with not using a template that describes what you're looking for, this is not further actionable.