Skip to content

Commit

Permalink
perf: do not type check if fileName doesn't match
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Aug 22, 2018
1 parent dd37e9c commit cc45adc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 13 additions & 9 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
? configs.filterDiagnostics(result.diagnostics)
: []

if (diagnosticList.length) throw configs.createTsError(diagnosticList)
if (diagnosticList.length) {
throw configs.createTsError(diagnosticList)
}

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

const output = service.getEmitOutput(fileName)

// Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
const diagnostics = service
.getCompilerOptionsDiagnostics()
.concat(service.getSyntacticDiagnostics(fileName))
.concat(service.getSemanticDiagnostics(fileName))
if (configs.shouldReportDiagnostic(fileName)) {
// Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
const diagnostics = service
.getCompilerOptionsDiagnostics()
.concat(service.getSyntacticDiagnostics(fileName))
.concat(service.getSemanticDiagnostics(fileName))

const diagnosticList = configs.filterDiagnostics(diagnostics)
const diagnosticList = configs.filterDiagnostics(diagnostics)

if (diagnosticList.length) {
throw configs.createTsError(diagnosticList)
if (diagnosticList.length) {
throw configs.createTsError(diagnosticList)
}
}

if (output.emitSkipped) {
Expand Down
5 changes: 1 addition & 4 deletions src/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ export class TsJestTransformer implements jest.Transformer {
const stringify = configs.shouldStringifyContent(filePath)
const babelJest = stringify ? undefined : configs.babelJestTransformer

// get the compiler instance
const compiler = configs.tsCompiler

// handles here what we should simply stringify
if (stringify) {
source = `module.exports=${JSON.stringify(source)}`
Expand All @@ -100,7 +97,7 @@ export class TsJestTransformer implements jest.Transformer {
// transpile TS code (source maps are included)
result = filePath.endsWith('.d.ts')
? '' // do not try to compile declaration files
: compiler.compile(source, filePath)
: configs.tsCompiler.compile(source, filePath)

// calling babel-jest transformer
if (babelJest) {
Expand Down

0 comments on commit cc45adc

Please sign in to comment.