Add support for //@check directives

This commit is contained in:
Mohamed Hegazy 2017-01-06 19:03:17 -08:00
parent 0b1fff7e66
commit 9f0c5ce141
4 changed files with 9 additions and 1 deletions

View File

@ -5817,6 +5817,7 @@ namespace ts {
const typeReferenceDirectives: FileReference[] = [];
const amdDependencies: { path: string; name: string }[] = [];
let amdModuleName: string;
let hasCheckDirective = false;
// Keep scanning all the leading trivia in the file until we get to something that
// isn't trivia. Any single line comment will be analyzed to see if it is a
@ -5878,6 +5879,9 @@ namespace ts {
amdDependencies.push(amdDependency);
}
}
const checkDirectiveRegEx = /^\/\/\s*@check\s*/gim;
hasCheckDirective = hasCheckDirective || !!checkDirectiveRegEx.exec(comment);
}
}
@ -5885,6 +5889,7 @@ namespace ts {
sourceFile.typeReferenceDirectives = typeReferenceDirectives;
sourceFile.amdDependencies = amdDependencies;
sourceFile.moduleName = amdModuleName;
sourceFile.hasCheckDirective = hasCheckDirective;
}
function setExternalModuleIndicator(sourceFile: SourceFile) {

View File

@ -907,7 +907,8 @@ namespace ts {
// For JavaScript files, we don't want to report semantic errors.
// Instead, we'll report errors for using TypeScript-only constructs from within a
// JavaScript file when we get syntactic diagnostics for the file.
const checkDiagnostics = !options.checkJsFiles && isSourceFileJavaScript(sourceFile) ? [] : typeChecker.getDiagnostics(sourceFile, cancellationToken);
const includeCheckDiagnostics = options.checkJsFiles || sourceFile.hasCheckDirective || !isSourceFileJavaScript(sourceFile);
const checkDiagnostics = includeCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : [];
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName);

View File

@ -2272,6 +2272,7 @@
/* @internal */ moduleAugmentations: LiteralExpression[];
/* @internal */ patternAmbientModules?: PatternAmbientModule[];
/* @internal */ ambientModuleNames: string[];
/* @internal */ hasCheckDirective: boolean;
}
export interface Bundle extends Node {

View File

@ -473,6 +473,7 @@ namespace ts {
public moduleAugmentations: LiteralExpression[];
private namedDeclarations: Map<Declaration[]>;
public ambientModuleNames: string[];
public hasCheckDirective: boolean;
constructor(kind: SyntaxKind, pos: number, end: number) {
super(kind, pos, end);