MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / updateWatchCompilationHost

Function updateWatchCompilationHost

src/tstl.ts:158–209  ·  view source on GitHub ↗
(
    host: ts.WatchCompilerHost<ts.SemanticDiagnosticsBuilderProgram>,
    optionsToExtend: tstl.CompilerOptions
)

Source from the content-addressed store, hash-verified

156}
157
158function 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
211function reportPerformance() {
212 if (performance.isMeasurementEnabled()) {

Callers 2

createWatchOfConfigFileFunction · 0.85

Calls 5

emitMethod · 0.95
createConfigFileUpdaterFunction · 0.90
isBundleEnabledFunction · 0.90
reportPerformanceFunction · 0.85
forEachMethod · 0.45

Tested by

no test coverage detected