• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, softwareP
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import type * as ts from 'typescript';
17import { ArkTSLinterTimePrinter, TimePhase } from '../ArkTSTimePrinter';
18import type { TSCCompiledProgram } from '../../lib/ts-diagnostics/TSCCompiledProgram';
19import { getStrictDiagnostics } from './SdkTypeScriptDiagnosticsExtractor';
20
21export class SdkTSCCompiledProgram implements TSCCompiledProgram {
22  private readonly builerProgram: ts.BuilderProgram;
23
24  constructor(builerProgram: ts.BuilderProgram) {
25    this.builerProgram = builerProgram;
26  }
27
28  getProgram(): ts.Program {
29    return this.builerProgram.getProgram();
30  }
31
32  getBuilderProgram(): ts.BuilderProgram {
33    return this.builerProgram;
34  }
35
36  getStrictDiagnostics(fileName: string): ts.Diagnostic[] {
37    return getStrictDiagnostics(this.getBuilderProgram(), fileName);
38  }
39
40  /**
41   * Updates all diagnostics in TSC compilation program after the incremental build.
42   */
43  updateCompilationDiagnostics(): void {
44    this.builerProgram.getSemanticDiagnostics();
45    const timePrinterInstance = ArkTSLinterTimePrinter.getInstance();
46    timePrinterInstance.appendTime(TimePhase.NON_STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS);
47    this.builerProgram.getSyntacticDiagnostics();
48    timePrinterInstance.appendTime(TimePhase.NON_STRICT_PROGRAM_GET_SYNTACTIC_DIAGNOSTICS);
49    this.builerProgram.builderProgramForLinter?.getSemanticDiagnostics();
50    timePrinterInstance.appendTime(TimePhase.STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS);
51  }
52}
53