gather_diagnostics.js 3.24 KB
Newer Older
jatuporn Tonggasem's avatar
jatuporn Tonggasem committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// @ignoreDep typescript
const ts = require("typescript");
const benchmark_1 = require("./benchmark");
class CancellationToken {
    constructor() {
        this._isCancelled = false;
    }
    requestCancellation() {
        this._isCancelled = true;
    }
    isCancellationRequested() {
        return this._isCancelled;
    }
    throwIfCancellationRequested() {
        if (this.isCancellationRequested()) {
            throw new ts.OperationCanceledException();
        }
    }
}
exports.CancellationToken = CancellationToken;
function hasErrors(diags) {
    return diags.some(d => d.category === ts.DiagnosticCategory.Error);
}
exports.hasErrors = hasErrors;
function gatherDiagnostics(program, jitMode, benchmarkLabel, cancellationToken) {
    const allDiagnostics = [];
    let checkOtherDiagnostics = true;
    function checkDiagnostics(diags) {
        if (diags) {
            allDiagnostics.push(...diags);
            return !hasErrors(diags);
        }
        return true;
    }
    if (jitMode) {
        const tsProgram = program;
        // Check syntactic diagnostics.
        benchmark_1.time(`${benchmarkLabel}.gatherDiagnostics.ts.getSyntacticDiagnostics`);
        checkOtherDiagnostics = checkOtherDiagnostics &&
            checkDiagnostics(tsProgram.getSyntacticDiagnostics(undefined, cancellationToken));
        benchmark_1.timeEnd(`${benchmarkLabel}.gatherDiagnostics.ts.getSyntacticDiagnostics`);
        // Check semantic diagnostics.
        benchmark_1.time(`${benchmarkLabel}.gatherDiagnostics.ts.getSemanticDiagnostics`);
        checkOtherDiagnostics = checkOtherDiagnostics &&
            checkDiagnostics(tsProgram.getSemanticDiagnostics(undefined, cancellationToken));
        benchmark_1.timeEnd(`${benchmarkLabel}.gatherDiagnostics.ts.getSemanticDiagnostics`);
    }
    else {
        const angularProgram = program;
        // Check TypeScript syntactic diagnostics.
        benchmark_1.time(`${benchmarkLabel}.gatherDiagnostics.ng.getTsSyntacticDiagnostics`);
        checkOtherDiagnostics = checkOtherDiagnostics &&
            checkDiagnostics(angularProgram.getTsSyntacticDiagnostics(undefined, cancellationToken));
        benchmark_1.timeEnd(`${benchmarkLabel}.gatherDiagnostics.ng.getTsSyntacticDiagnostics`);
        // Check TypeScript semantic and Angular structure diagnostics.
        benchmark_1.time(`${benchmarkLabel}.gatherDiagnostics.ng.getTsSemanticDiagnostics`);
        checkOtherDiagnostics = checkOtherDiagnostics &&
            checkDiagnostics(angularProgram.getTsSemanticDiagnostics(undefined, cancellationToken));
        benchmark_1.timeEnd(`${benchmarkLabel}.gatherDiagnostics.ng.getTsSemanticDiagnostics`);
        // Check Angular semantic diagnostics
        benchmark_1.time(`${benchmarkLabel}.gatherDiagnostics.ng.getNgSemanticDiagnostics`);
        checkOtherDiagnostics = checkOtherDiagnostics &&
            checkDiagnostics(angularProgram.getNgSemanticDiagnostics(undefined, cancellationToken));
        benchmark_1.timeEnd(`${benchmarkLabel}.gatherDiagnostics.ng.getNgSemanticDiagnostics`);
    }
    return allDiagnostics;
}
exports.gatherDiagnostics = gatherDiagnostics;
//# sourceMappingURL=/users/hansl/sources/hansl/angular-cli/src/gather_diagnostics.js.map