55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- import { ConstantPool , Expression , Statement , WrappedNodeExpr , WritePropExpr } from '@angular/compiler' ;
8+ import { CommentStmt , ConstantPool , Expression , Statement , WrappedNodeExpr , WritePropExpr } from '@angular/compiler' ;
99import MagicString from 'magic-string' ;
1010import * as ts from 'typescript' ;
1111
1212import { FileSystem } from '../../../src/ngtsc/file_system' ;
1313import { ImportManager } from '../../../src/ngtsc/translator' ;
14+ import { ParsedConfiguration } from '../../../src/perform_compile' ;
1415import { PrivateDeclarationsAnalyses } from '../analysis/private_declarations_analyzer' ;
1516import { SwitchMarkerAnalyses , SwitchMarkerAnalysis } from '../analysis/switch_marker_analyzer' ;
1617import { CompiledClass , CompiledFile , DecorationAnalyses } from '../analysis/types' ;
@@ -32,7 +33,8 @@ import {FileToWrite, getImportRewriter, stripExtension} from './utils';
3233export class Renderer {
3334 constructor (
3435 private host : NgccReflectionHost , private srcFormatter : RenderingFormatter ,
35- private fs : FileSystem , private logger : Logger , private bundle : EntryPointBundle ) { }
36+ private fs : FileSystem , private logger : Logger , private bundle : EntryPointBundle ,
37+ private tsConfig : ParsedConfiguration | null = null ) { }
3638
3739 renderProgram (
3840 decorationAnalyses : DecorationAnalyses , switchMarkerAnalyses : SwitchMarkerAnalyses ,
@@ -82,8 +84,9 @@ export class Renderer {
8284 this . srcFormatter . removeDecorators ( outputText , decoratorsToRemove ) ;
8385
8486 compiledFile . compiledClasses . forEach ( clazz => {
85- const renderedDefinition =
86- this . renderDefinitions ( compiledFile . sourceFile , clazz , importManager ) ;
87+ const renderedDefinition = this . renderDefinitions (
88+ compiledFile . sourceFile , clazz , importManager ,
89+ ! ! this . tsConfig ?. options . annotateForClosureCompiler ) ;
8790 this . srcFormatter . addDefinitions ( outputText , clazz , renderedDefinition ) ;
8891
8992 const renderedStatements =
@@ -160,12 +163,14 @@ export class Renderer {
160163 * @param imports An object that tracks the imports that are needed by the rendered definitions.
161164 */
162165 private renderDefinitions (
163- sourceFile : ts . SourceFile , compiledClass : CompiledClass , imports : ImportManager ) : string {
166+ sourceFile : ts . SourceFile , compiledClass : CompiledClass , imports : ImportManager ,
167+ annotateForClosureCompiler : boolean ) : string {
164168 const name = this . host . getInternalNameOfClass ( compiledClass . declaration ) ;
165- const statements : Statement [ ] = compiledClass . compilation . map ( c => {
166- return createAssignmentStatement ( name , c . name , c . initializer ) ;
169+ const statements : Statement [ ] [ ] = compiledClass . compilation . map ( c => {
170+ return createAssignmentStatements (
171+ name , c . name , c . initializer , annotateForClosureCompiler ? '* @nocollapse ' : undefined ) ;
167172 } ) ;
168- return this . renderStatements ( sourceFile , statements , imports ) ;
173+ return this . renderStatements ( sourceFile , Array . prototype . concat . apply ( [ ] , statements ) , imports ) ;
169174 }
170175
171176 /**
@@ -208,8 +213,16 @@ export function renderConstantPool(
208213 * compiled decorator to be applied to the class.
209214 * @param analyzedClass The info about the class whose statement we want to create.
210215 */
211- function createAssignmentStatement (
212- receiverName : ts . DeclarationName , propName : string , initializer : Expression ) : Statement {
216+ function createAssignmentStatements (
217+ receiverName : ts . DeclarationName , propName : string , initializer : Expression ,
218+ leadingComment ?: string ) : Statement [ ] {
213219 const receiver = new WrappedNodeExpr ( receiverName ) ;
214- return new WritePropExpr ( receiver , propName , initializer ) . toStmt ( ) ;
220+ const statements =
221+ [ new WritePropExpr (
222+ receiver , propName , initializer , /* type */ undefined , /* sourceSpan */ undefined )
223+ . toStmt ( ) ] ;
224+ if ( leadingComment !== undefined ) {
225+ statements . unshift ( new CommentStmt ( leadingComment , true ) ) ;
226+ }
227+ return statements ;
215228}
0 commit comments