Skip to content

Commit cc45adc

Browse files
committed
perf: do not type check if fileName doesn't match
1 parent dd37e9c commit cc45adc

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/compiler.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
101101
? configs.filterDiagnostics(result.diagnostics)
102102
: []
103103

104-
if (diagnosticList.length) throw configs.createTsError(diagnosticList)
104+
if (diagnosticList.length) {
105+
throw configs.createTsError(diagnosticList)
106+
}
105107

106108
return [result.outputText, result.sourceMapText as string]
107109
}
@@ -174,16 +176,18 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
174176

175177
const output = service.getEmitOutput(fileName)
176178

177-
// Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
178-
const diagnostics = service
179-
.getCompilerOptionsDiagnostics()
180-
.concat(service.getSyntacticDiagnostics(fileName))
181-
.concat(service.getSemanticDiagnostics(fileName))
179+
if (configs.shouldReportDiagnostic(fileName)) {
180+
// Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
181+
const diagnostics = service
182+
.getCompilerOptionsDiagnostics()
183+
.concat(service.getSyntacticDiagnostics(fileName))
184+
.concat(service.getSemanticDiagnostics(fileName))
182185

183-
const diagnosticList = configs.filterDiagnostics(diagnostics)
186+
const diagnosticList = configs.filterDiagnostics(diagnostics)
184187

185-
if (diagnosticList.length) {
186-
throw configs.createTsError(diagnosticList)
188+
if (diagnosticList.length) {
189+
throw configs.createTsError(diagnosticList)
190+
}
187191
}
188192

189193
if (output.emitSkipped) {

src/ts-jest-transformer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ export class TsJestTransformer implements jest.Transformer {
8989
const stringify = configs.shouldStringifyContent(filePath)
9090
const babelJest = stringify ? undefined : configs.babelJestTransformer
9191

92-
// get the compiler instance
93-
const compiler = configs.tsCompiler
94-
9592
// handles here what we should simply stringify
9693
if (stringify) {
9794
source = `module.exports=${JSON.stringify(source)}`
@@ -100,7 +97,7 @@ export class TsJestTransformer implements jest.Transformer {
10097
// transpile TS code (source maps are included)
10198
result = filePath.endsWith('.d.ts')
10299
? '' // do not try to compile declaration files
103-
: compiler.compile(source, filePath)
100+
: configs.tsCompiler.compile(source, filePath)
104101

105102
// calling babel-jest transformer
106103
if (babelJest) {

0 commit comments

Comments
 (0)