Skip to content

Commit 9f0c5ce

Browse files
committed
Add support for //@check directives
1 parent 0b1fff7 commit 9f0c5ce

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

src/compiler/parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5817,6 +5817,7 @@ namespace ts {
58175817
const typeReferenceDirectives: FileReference[] = [];
58185818
const amdDependencies: { path: string; name: string }[] = [];
58195819
let amdModuleName: string;
5820+
let hasCheckDirective = false;
58205821

58215822
// Keep scanning all the leading trivia in the file until we get to something that
58225823
// isn't trivia. Any single line comment will be analyzed to see if it is a
@@ -5878,13 +5879,17 @@ namespace ts {
58785879
amdDependencies.push(amdDependency);
58795880
}
58805881
}
5882+
5883+
const checkDirectiveRegEx = /^\/\/\s*@check\s*/gim;
5884+
hasCheckDirective = hasCheckDirective || !!checkDirectiveRegEx.exec(comment);
58815885
}
58825886
}
58835887

58845888
sourceFile.referencedFiles = referencedFiles;
58855889
sourceFile.typeReferenceDirectives = typeReferenceDirectives;
58865890
sourceFile.amdDependencies = amdDependencies;
58875891
sourceFile.moduleName = amdModuleName;
5892+
sourceFile.hasCheckDirective = hasCheckDirective;
58885893
}
58895894

58905895
function setExternalModuleIndicator(sourceFile: SourceFile) {

src/compiler/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ namespace ts {
907907
// For JavaScript files, we don't want to report semantic errors.
908908
// Instead, we'll report errors for using TypeScript-only constructs from within a
909909
// JavaScript file when we get syntactic diagnostics for the file.
910-
const checkDiagnostics = !options.checkJsFiles && isSourceFileJavaScript(sourceFile) ? [] : typeChecker.getDiagnostics(sourceFile, cancellationToken);
910+
const includeCheckDiagnostics = options.checkJsFiles || sourceFile.hasCheckDirective || !isSourceFileJavaScript(sourceFile);
911+
const checkDiagnostics = includeCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : [];
911912
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
912913
const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName);
913914

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,7 @@
22722272
/* @internal */ moduleAugmentations: LiteralExpression[];
22732273
/* @internal */ patternAmbientModules?: PatternAmbientModule[];
22742274
/* @internal */ ambientModuleNames: string[];
2275+
/* @internal */ hasCheckDirective: boolean;
22752276
}
22762277

22772278
export interface Bundle extends Node {

src/services/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ namespace ts {
473473
public moduleAugmentations: LiteralExpression[];
474474
private namedDeclarations: Map<Declaration[]>;
475475
public ambientModuleNames: string[];
476+
public hasCheckDirective: boolean;
476477

477478
constructor(kind: SyntaxKind, pos: number, end: number) {
478479
super(kind, pos, end);

0 commit comments

Comments
 (0)