TypeScript: TypeScript removing comments where it shouldn't
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?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Fix bug: keep comments unless --removeComments This is a straightforward fix for bug #2546. Keeps most or all TS comments in the output, unless the option --removeComments is enabled. — committed to staltz/TypeScript by deleted user 8 years ago
- Fix block comments (#2546, #6069, #6982) — committed to AntonTolmachev/TypeScript by deleted user 8 years ago
- Fix comments on else statement (Partial fix of #2546) — committed to AntonTolmachev/TypeScript by deleted user 8 years ago
- Fix block comments (#2546, #6069, #6982) — committed to AntonTolmachev/TypeScript by deleted user 8 years ago
- Fix comments on else statement (Partial fix of #2546) — committed to AntonTolmachev/TypeScript by deleted user 8 years ago
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:
The emitted javascript output is:
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
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.
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!
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:The comment on the first line is excluded meanwhile other comments in the file are kept.