@@ -52,6 +52,26 @@ export function check(diags: ts.Diagnostic[]) {
5252 }
5353}
5454
55+ export function validateAngularCompilerOptions ( options : AngularCompilerOptions ) : ts . Diagnostic [ ] {
56+ if ( options . annotationsAs ) {
57+ switch ( options . annotationsAs ) {
58+ case 'decorators' :
59+ case 'static fields' :
60+ break ;
61+ default :
62+ return [ {
63+ file : null ,
64+ start : null ,
65+ length : null ,
66+ messageText :
67+ 'Angular compiler options "annotationsAs" only supports "static fields" and "decorators"' ,
68+ category : ts . DiagnosticCategory . Error ,
69+ code : 0
70+ } ] ;
71+ }
72+ }
73+ }
74+
5575export class Tsc implements CompilerInterface {
5676 public ngOptions : AngularCompilerOptions ;
5777 public parsed : ts . ParsedCommandLine ;
@@ -96,6 +116,8 @@ export class Tsc implements CompilerInterface {
96116 for ( const key of Object . keys ( this . parsed . options ) ) {
97117 this . ngOptions [ key ] = this . parsed . options [ key ] ;
98118 }
119+ check ( validateAngularCompilerOptions ( this . ngOptions ) ) ;
120+
99121 return { parsed : this . parsed , ngOptions : this . ngOptions } ;
100122 }
101123
@@ -113,8 +135,10 @@ export class Tsc implements CompilerInterface {
113135 }
114136
115137 emit ( compilerHost : TsickleHost , oldProgram : ts . Program ) : number {
116- // Create a new program since the host may be different from the old program.
117- const program = ts . createProgram ( this . parsed . fileNames , this . parsed . options , compilerHost ) ;
138+ // Create a program if we are lowering annotations with tsickle.
139+ const program = this . ngOptions . annotationsAs === 'static fields' ?
140+ ts . createProgram ( this . parsed . fileNames , this . parsed . options , compilerHost ) :
141+ oldProgram ;
118142 debug ( 'Emitting outputs...' ) ;
119143 const emitResult = program . emit ( ) ;
120144 const diagnostics : ts . Diagnostic [ ] = [ ] ;
0 commit comments