@@ -206,7 +206,17 @@ module.exports.transform = function(src, filename, options) {
206
206
; ( { src, filename, options } = src )
207
207
}
208
208
209
- if ( filename . endsWith ( '.ts' ) || filename . endsWith ( '.tsx' ) ) {
209
+ if ( filename . endsWith ( '.ts' ) || filename . endsWith ( '.tsx' ) ) {
210
+ if ( compilerOptions . noEmitOnError ) {
211
+ const program = ts . createProgram ( [ filename ] , compilerOptions )
212
+
213
+ const preErrors = ts
214
+ . getPreEmitDiagnostics ( program )
215
+ . filter ( ( { category } ) => category === ts . DiagnosticCategory . Error )
216
+
217
+ reportErrors ( preErrors )
218
+ }
219
+
210
220
const tsCompileResult = ts . transpileModule ( src , {
211
221
compilerOptions,
212
222
fileName : filename ,
@@ -217,28 +227,7 @@ module.exports.transform = function(src, filename, options) {
217
227
( { category } ) => category === ts . DiagnosticCategory . Error
218
228
)
219
229
220
- if ( errors . length ) {
221
- // report first error
222
- const error = errors [ 0 ]
223
- const message = ts . flattenDiagnosticMessageText ( error . messageText , '\n' )
224
- if ( error . file ) {
225
- let { line, character } = error . file . getLineAndCharacterOfPosition (
226
- error . start
227
- )
228
- if ( error . file . fileName === 'module.ts' ) {
229
- console . error ( {
230
- error,
231
- filename,
232
- options,
233
- } )
234
- }
235
- throw new Error (
236
- `${ error . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } `
237
- )
238
- } else {
239
- throw new Error ( message )
240
- }
241
- }
230
+ reportErrors ( errors )
242
231
243
232
const babelCompileResult = upstreamTransformer . transform ( {
244
233
src : tsCompileResult . outputText ,
@@ -275,3 +264,28 @@ module.exports.transform = function(src, filename, options) {
275
264
} )
276
265
}
277
266
}
267
+
268
+ function reportErrors ( errors ) {
269
+ if ( errors . length ) {
270
+ // report first error
271
+ const error = errors [ 0 ]
272
+ const message = ts . flattenDiagnosticMessageText ( error . messageText , '\n' )
273
+ if ( error . file ) {
274
+ let { line, character } = error . file . getLineAndCharacterOfPosition (
275
+ error . start
276
+ )
277
+ if ( error . file . fileName === 'module.ts' ) {
278
+ console . error ( {
279
+ error,
280
+ filename,
281
+ options,
282
+ } )
283
+ }
284
+ throw new Error (
285
+ `${ error . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } `
286
+ )
287
+ } else {
288
+ throw new Error ( message )
289
+ }
290
+ }
291
+ }
0 commit comments