TypeScript: removeComments compiler option seems to be ignored when using typescript 1.5.0-beta
Specifying the argument ($ tsc --removeComments) or option in (tsconfig.json) for removing comments is not honoured.
Normal comments are removed, but special comments, like references and amd dependencies, are preserved.
/// <reference path="../Interfaces/IView" />
/// <reference path="./BaseView" />
/// <amd-dependency path="/js/libs/hgn.js!app/templates/home" name="compiler"/>
I don’t know if this new behaviour is intended but this wasn’t the case in the previous release and I wouldn’t expect these special comments to be required in the output files.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 27 (12 by maintainers)
Hi I’m using version 1.8.10 and if you don’t leave a new line between the header and the first line of code the header is not preserved…
Also If you don’t declare a constructor like the one below the header is not preserved in .d.ts files. constructor(public el:ElementRef) { console.log(‘constructor’, el); }
@magemello the whitespace does indeed seem to be a problem. I’ll look into it.
There are a lot of things being conflated here. Let’s run down the list of special constructs that TS knows about:
/// <and have some well know name after the open angle (likereferenceoramd-module./*!./*or//).Currently, thanks to the work by @yuit,
--removeCommentsshould only affect the last comment type. In other words, the presence of this flag only affects if we emit ‘Normal’ comments. These are the general comments that make up the majority of comments in a project, and which add the most to output size. They also have no meaning except to the developer, and thus can be removed safely, and have no meaning to other tools.Currently
--removeCommentsdoes not remove the first three comment types, and we will attempt to preserve them regardless of this flag. These reason for this is as follows:referencedirective in later parts of their JS processing pipeline. So we’re also keeping those by default.Now, we recognize that some users may want further comment removal. Specifically removal of ‘Detached’ or ‘Directive’ comments (again, we will always try to preserve ‘Pinned’ comments**). When @yuit did this work we discussed this need and speculated that we would have further options to the compiler to allow customization here. We’ll be keeping the
--removeCommentsflag and keeping the new default behavior. However, we are also considering adding things like (final name/form TBD):With such an option you can opt out of our default behavior and trim your files even further. We did not do this originally because we weren’t even certain there would be anyone who would want/need this. And investing in this work based on speculative need seemed unnecessary. Now that it’s clearer that there are some people who might want this, we will revisit and potentially reconsider this decision.
** Currently pinned comments are not emitted in some cases. However, i consider that a bug. We should always be emitting pinned comments in all circumstances. That’s the point of the construct in the first place. Fortunately, this bug doesn’t seem to have that much impact. The places where people use pinned comments do not seem to the be the same as the places where we accidentally do not emit them.
Another (possibly related) bug: multiline comments are always removed if they are the only thing in thing in the body of a function:
tsconfig.json
index.ts
Generated index.js
If I add a statement to the body of
foo, then I do not see this problem.This breaks code that uses the multiline module.