Skip to content

Commit

Permalink
feat: Program - getSyntacticDiagnostics, getSemanticDiagnostics, getD…
Browse files Browse the repository at this point in the history
…eclarationDiagnostics, getPreEmitDiagnostics
  • Loading branch information
dsherret committed Dec 23, 2017
1 parent 8544414 commit 56b5f58
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/compiler/tools/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {GlobalContainer} from "./../../GlobalContainer";
import {Logger} from "./../../utils";
import {TypeChecker} from "./TypeChecker";
import {SourceFile} from "./../file";
import {EmitResult} from "./results";
import {EmitResult, Diagnostic} from "./results";

/**
* Options for emitting.
Expand Down Expand Up @@ -83,4 +83,40 @@ export class Program {
const emitResult = this.compilerObject.emit(targetSourceFile, undefined, cancellationToken, emitOnlyDtsFiles, customTransformers);
return new EmitResult(this.global, emitResult);
}

/**
* Gets the syntactic diagnostics.
* @param sourceFile - Optional source file.
*/
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
const compilerDiagnostics = this.compilerObject.getSyntacticDiagnostics(sourceFile == null ? undefined : sourceFile.compilerNode);
return compilerDiagnostics.map(d => this.global.compilerFactory.getDiagnostic(d));
}

/**
* Gets the semantic diagnostics.
* @param sourceFile - Optional source file.
*/
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
const compilerDiagnostics = this.compilerObject.getSemanticDiagnostics(sourceFile == null ? undefined : sourceFile.compilerNode);
return compilerDiagnostics.map(d => this.global.compilerFactory.getDiagnostic(d));
}

/**
* Gets the declaration diagnostics.
* @param sourceFile - Optional source file.
*/
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
const compilerDiagnostics = this.compilerObject.getDeclarationDiagnostics(sourceFile == null ? undefined : sourceFile.compilerNode);
return compilerDiagnostics.map(d => this.global.compilerFactory.getDiagnostic(d));
}

/**
* Gets the pre-emit diagnostics.
* @param sourceFile - Source file.
*/
getPreEmitDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
const compilerDiagnostics = ts.getPreEmitDiagnostics(this.compilerObject, sourceFile == null ? undefined : sourceFile.compilerNode);
return compilerDiagnostics.map(d => this.global.compilerFactory.getDiagnostic(d));
}
}

0 comments on commit 56b5f58

Please sign in to comment.