fix(compiler-cli): merge @fileoverview comments. (#20870)

Previously, this code would unconditionally add a @fileoverview
comment to generated files, and only if the contained any code at all.

However often existing fileoverview comments should be copied from the
file the generated file was originally based off of. This allows users
to e.g. include Closure Compiler directives in their original
`component.ts` file, which will then automaticallly also apply to code
generated from it.

This special cases `@license` comments, as Closure disregards directives
in comments containing `@license`.

PR Close #20870
This commit is contained in:
Martin Probst
2017-12-07 17:52:16 +01:00
committed by Jason Aden
parent add3589451
commit 8c52088346
5 changed files with 157 additions and 27 deletions

View File

@ -399,7 +399,7 @@ class AngularCompilerProgram implements Program {
if (!this.options.disableExpressionLowering) {
beforeTs.push(getExpressionLoweringTransformFactory(this.metadataCache, this.tsProgram));
}
beforeTs.push(getAngularEmitterTransformFactory(genFiles));
beforeTs.push(getAngularEmitterTransformFactory(genFiles, this.getTsProgram()));
if (customTransformers && customTransformers.beforeTs) {
beforeTs.push(...customTransformers.beforeTs);
}
@ -628,15 +628,12 @@ class AngularCompilerProgram implements Program {
// Filter out generated files for which we didn't generate code.
// This can happen as the stub caclulation is not completely exact.
// Note: sourceFile refers to the .ngfactory.ts / .ngsummary.ts file
// node_emitter_transform already set the file contents to be empty,
// so this code only needs to skip the file if !allowEmptyCodegenFiles.
const isGenerated = GENERATED_FILES.test(outFileName);
if (isGenerated) {
if (!genFile || !genFile.stmts || genFile.stmts.length === 0) {
if (this.options.allowEmptyCodegenFiles) {
outData = '';
} else {
return;
}
}
if (isGenerated && !this.options.allowEmptyCodegenFiles &&
(!genFile || !genFile.stmts || genFile.stmts.length === 0)) {
return;
}
if (baseFile) {
sourceFiles = sourceFiles ? [...sourceFiles, baseFile] : [baseFile];