-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript removing comments where it shouldn't #2546
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
I have "Keep comments in JavaScript output" checked but my header comment, at the top of my TS is being ignored. Really, I only want to keep comments in the
The comment on the first line is excluded meanwhile other comments in the file are kept. |
@JoshMcCullough Block comments are also excluded at those locations (end of if/try statements). |
I wasn't suggesting a solution to your problem, I was suggesting that comments at the top of my TS file are being excluded from the JS. E.g., we're in the same boat - our comments are being stripped! |
+1 |
PRs are welcomed |
This is a straightforward fix for bug microsoft#2546. Keeps most or all TS comments in the output, unless the option --removeComments is enabled.
TypeScript also appears to be removing comments in this fashion: js: This is painful when trying to get code coverage and are setting ignore statements. |
3rd party hints within code? :-/ |
There are other places where it's been removed, I created this one last week without knowing it was a dup |
Still does not work |
This is a big issue for us as well. We are trying to use jsDoc with Typescript, and Typescript's habit of removing comments, even with removeComments=false, is making this very painful. Please provide some way to keep all comments in emitted JS. In our case, I am trying to document interfaces and other things that do not emit JS code, and this makes it very difficult. |
Comments on interfaces will not be emitted, since the interfaces themselves are not emited. For other issues please be specific on what declarations are not getting their comments emitted properly. |
Yes, I understand the rationale for removing the comments before interfaces. In many cases it is correct and understandable. But what I am saying is that there are significant reasons to include an option to not remove any comments, including those before interfaces. In fact, there is one very significant reason and use case - documentation with tools like jsDoc. Think of why we use interfaces. They explicitly define the shape of objects for clients of a package. This functionality is a major advantage of using Typescript. Having no option to allow comments about these structures to flow through to documentation is a major failing, in my view. Why would adding a compiler option to suppress all comment removal be a problem? It would be up to the author to use it correctly. |
I would like to add another to this list. Let me know if it deserves a separate issue. TypeScript removes top level comments when a file contains a shebang. Given the typescript file below:
The emitted javascript output is:
This is not a problem for non-executable javascript files and the header comment is emitted directly below the This is using |
I would like to add few more cases. All comments in the example below are removed when compiling the code: var a;
a
// comment
.b()
if (/*comment*/1) {
}
a(/*comment*/)
if /*comment*/(1) {
}
else /*comment*/{} |
Also removes
|
comment.ts
comment.js
Are there any additional flags that can be set for TS to keep all comments?
Same issue from CodePlex
The text was updated successfully, but these errors were encountered: