comment.ts
if (false) {
//I will be removed
}
//I will be removed
else {
//I will not be removed
var tmp;
//I will be removed
}
try{
//I will not be removed
var tmp;
//I will be removed
}
//I will be removed
catch(e){
//I will not be removed
var tmp;
//I will be removed
}
comment.js
if (false) {
}
else {
//I will not be removed
var tmp;
}
try {
//I will not be removed
var tmp;
}
catch (e) {
//I will not be removed
var tmp;
}
Are there any additional flags that can be set for TS to keep _all_ 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 /** Comment */ format for documentation purposes, and this is mostly working. The header comment is something like this:
/** Whatever JavaScript API v1.2.3.4 */
module whatever {
export class API { ... }
}
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 know comments at the top of file are kept, but this is not what I need.
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
TypeScript also appears to be removing comments in this fashion:
ts:
const foo: boolean = var1 || /* istanbul ignore next */ null;
js:
var foo = var1 || null;
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
https://github.com/Microsoft/TypeScript/issues/13602
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.
We have a company standard that requires copyright statements be added to all of our ts/js files.
Given the typescript file below:
#! /usr/bin/env node
/**
* @copyright <copyright goes here>
*/
export const foo: string = "bar";
The emitted javascript output is:
#! /usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = "bar";
//# sourceMappingURL=test.js.map
This is not a problem for non-executable javascript files and the header comment is emitted directly below the "use strict";
This is using typescript 2.3.x
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
for (const movieFile of fm.movieFiles) { // comment