(
host: ts.WatchCompilerHost<ts.SemanticDiagnosticsBuilderProgram>,
optionsToExtend: tstl.CompilerOptions
)
| 156 | } |
| 157 | |
| 158 | function updateWatchCompilationHost( |
| 159 | host: ts.WatchCompilerHost<ts.SemanticDiagnosticsBuilderProgram>, |
| 160 | optionsToExtend: tstl.CompilerOptions |
| 161 | ): void { |
| 162 | let hadErrorLastTime = true; |
| 163 | const updateConfigFile = createConfigFileUpdater(optionsToExtend); |
| 164 | |
| 165 | const transpiler = new tstl.Transpiler(); |
| 166 | host.afterProgramCreate = builderProgram => { |
| 167 | const program = builderProgram.getProgram(); |
| 168 | const options = builderProgram.getCompilerOptions() as tstl.CompilerOptions; |
| 169 | |
| 170 | if (options.measurePerformance) performance.enableMeasurement(); |
| 171 | |
| 172 | const configFileParsingDiagnostics: ts.Diagnostic[] = updateConfigFile(options); |
| 173 | |
| 174 | let sourceFiles: ts.SourceFile[] | undefined; |
| 175 | if (!isBundleEnabled(options) && !hadErrorLastTime) { |
| 176 | sourceFiles = []; |
| 177 | while (true) { |
| 178 | const currentFile = builderProgram.getSemanticDiagnosticsOfNextAffectedFile(); |
| 179 | if (!currentFile) break; |
| 180 | |
| 181 | if ("fileName" in currentFile.affected) { |
| 182 | sourceFiles.push(currentFile.affected); |
| 183 | } else { |
| 184 | sourceFiles.push(...currentFile.affected.getSourceFiles()); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | const { diagnostics: emitDiagnostics } = transpiler.emit({ program, sourceFiles }); |
| 190 | |
| 191 | const diagnostics = ts.sortAndDeduplicateDiagnostics([ |
| 192 | ...configFileParsingDiagnostics, |
| 193 | ...program.getOptionsDiagnostics(), |
| 194 | ...program.getSyntacticDiagnostics(), |
| 195 | ...program.getGlobalDiagnostics(), |
| 196 | ...program.getSemanticDiagnostics(), |
| 197 | ...emitDiagnostics, |
| 198 | ]); |
| 199 | |
| 200 | diagnostics.forEach(reportDiagnostic); |
| 201 | |
| 202 | if (options.measurePerformance) reportPerformance(); |
| 203 | |
| 204 | const errors = diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error); |
| 205 | hadErrorLastTime = errors.length > 0; |
| 206 | |
| 207 | host.onWatchStatusChange!(cliDiagnostics.watchErrorSummary(errors.length), host.getNewLine(), options); |
| 208 | }; |
| 209 | } |
| 210 | |
| 211 | function reportPerformance() { |
| 212 | if (performance.isMeasurementEnabled()) { |
no test coverage detected