@@ -34,9 +34,11 @@ module.exports = class IncrementalTypescriptCompiler {
3434
3535 this . _buildDeferred = RSVP . defer ( ) ;
3636 this . _isSynced = false ;
37+ this . _pendingErrors = [ ] ;
3738 this . _triggerDir = `${ this . outDir ( ) } /.rebuild` ;
3839 this . _pendingAutoresolve = null ;
3940 this . _didAutoresolve = false ;
41+ this . _watchProgram = null ;
4042 }
4143
4244 treeForHost ( ) {
@@ -108,7 +110,7 @@ module.exports = class IncrementalTypescriptCompiler {
108110 let project = this . project ;
109111 let outDir = this . outDir ( ) ;
110112
111- compile ( project , { outDir, watch : true } , {
113+ this . _watchProgram = compile ( project , { outDir, watch : true } , {
112114 reportWatchStatus : ( diagnostic ) => {
113115 let text = diagnostic . messageText ;
114116
@@ -135,11 +137,17 @@ module.exports = class IncrementalTypescriptCompiler {
135137
136138 reportDiagnostic : ( diagnostic ) => {
137139 if ( diagnostic . category !== 2 ) {
138- this . project . ui . write ( ts . formatDiagnostic ( diagnostic , {
140+ let message = ts . formatDiagnostic ( diagnostic , {
139141 getCanonicalFileName : path => path ,
140142 getCurrentDirectory : ts . sys . getCurrentDirectory ,
141143 getNewLine : ( ) => ts . sys . newLine ,
142- } ) ) ;
144+ } ) ;
145+
146+ if ( this . _shouldFailOnTypeError ( ) ) {
147+ this . didError ( message ) ;
148+ } else {
149+ this . project . ui . write ( message ) ;
150+ }
143151 }
144152 }
145153 } ) ;
@@ -163,9 +171,27 @@ module.exports = class IncrementalTypescriptCompiler {
163171 }
164172 }
165173
174+ didError ( message ) {
175+ this . _pendingErrors . push ( message ) ;
176+ }
177+
166178 didSync ( ) {
167179 this . _isSynced = true ;
168- this . _buildDeferred . resolve ( ) ;
180+ if ( this . _pendingErrors . length ) {
181+ this . _buildDeferred . reject ( new Error ( this . _pendingErrors . join ( '\n' ) ) ) ;
182+ this . _pendingErrors = [ ] ;
183+ } else {
184+ this . _buildDeferred . resolve ( ) ;
185+ }
186+ }
187+
188+ getProgram ( ) {
189+ return this . _watchProgram . getProgram ( ) ;
190+ }
191+
192+ _shouldFailOnTypeError ( ) {
193+ let options = this . getProgram ( ) . getCompilerOptions ( ) ;
194+ return ! ! options . noEmitOnError ;
169195 }
170196
171197 _mirageDirectory ( ) {
0 commit comments