From 61bc61fc59ef9f5b2f7aa9736bb2cbd8aa153ca7 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Thu, 10 Jan 2019 10:40:24 -0800 Subject: [PATCH] fix(ivy): ensure @nocollapse is added to static fields (#28050) ngtsc has a hack to add @nocollapse jsdoc annotations to generated static fields. This hack is currently broken (likely due to a TypeScript change in the way writeFile() works). This commit fixes the hack and introduces an ngtsc_spec test to ensure it does not regress again. PR Close #28050 --- packages/compiler-cli/src/ngtsc/program.ts | 2 +- .../compiler-cli/test/ngtsc/ngtsc_spec.ts | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/program.ts b/packages/compiler-cli/src/ngtsc/program.ts index 177b7df1e6..f87e880d4c 100644 --- a/packages/compiler-cli/src/ngtsc/program.ts +++ b/packages/compiler-cli/src/ngtsc/program.ts @@ -227,7 +227,7 @@ export class NgtscProgram implements api.Program { if (fileName.endsWith('.d.ts')) { data = sourceFiles.reduce( (data, sf) => this.compilation !.transformedDtsFor(sf.fileName, data), data); - } else if (this.closureCompilerEnabled && fileName.endsWith('.ts')) { + } else if (this.closureCompilerEnabled && fileName.endsWith('.js')) { data = nocollapseHack(data); } this.host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index 945051348e..49bdf8380e 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -109,6 +109,27 @@ describe('ngtsc behavioral tests', () => { expect(jsContents).toContain('Hello World'); }); + it('should add @nocollapse to static fields when closure annotations are requested', () => { + env.tsconfig({ + 'annotateForClosureCompiler': true, + }); + env.write('test.ts', ` + import {Component} from '@angular/core'; + + @Component({ + selector: 'test-cmp', + templateUrl: './dir/test.html', + }) + export class TestCmp {} + `); + env.write('dir/test.html', '

Hello World

'); + + env.driveMain(); + + const jsContents = env.getContents('test.js'); + expect(jsContents).toContain('/** @nocollapse */ TestCmp.ngComponentDef'); + }); + it('should compile Components with a templateUrl in a different rootDir', () => { env.tsconfig({}, ['./extraRootDir']); env.write('extraRootDir/test.html', '

Hello World

');