Skip to content

Commit 38d806d

Browse files
committed
More cleanup in program.ts
1 parent 77667b7 commit 38d806d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/compiler/program.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,22 +1917,24 @@ namespace ts {
19171917
Debug.assert(!!sourceFile.bindDiagnostics);
19181918

19191919
const isCheckJsTrue = isCheckJsEnabledForFile(sourceFile, options);
1920-
const isCheckJsUndefined = includeUncheckedJS && sourceFile.checkJsDirective === undefined && options.checkJs === undefined;
1920+
const isCheckJsUndefined = includeUncheckedJS
1921+
&& sourceFile.checkJsDirective === undefined && options.checkJs === undefined
1922+
&& (sourceFile.scriptKind === ScriptKind.JS || sourceFile.scriptKind === ScriptKind.JSX);
19211923
const isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
19221924
// By default, only type-check .ts, .tsx, 'Deferred' and 'External' files (external files are added by plugins)
19231925
const includeBindAndCheckDiagnostics = !isTsNoCheck &&
19241926
(sourceFile.scriptKind === ScriptKind.TS
19251927
|| sourceFile.scriptKind === ScriptKind.TSX
19261928
|| isCheckJsTrue
1927-
|| isCheckJsUndefined && (sourceFile.scriptKind === ScriptKind.JS || sourceFile.scriptKind === ScriptKind.JSX)
1929+
|| isCheckJsUndefined
19281930
|| sourceFile.scriptKind === ScriptKind.External
19291931
|| sourceFile.scriptKind === ScriptKind.Deferred);
1930-
let bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
1932+
const bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics && !isCheckJsUndefined ? sourceFile.bindDiagnostics : emptyArray;
19311933
let checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;
1932-
if (isCheckJsUndefined && (sourceFile.scriptKind === ScriptKind.JS || sourceFile.scriptKind === ScriptKind.JSX)) {
1933-
// TODO: It can just be checkDiagnostics srsly
1934-
bindDiagnostics = bindDiagnostics.filter(d => d.code === Diagnostics.Cannot_find_name_0_Did_you_mean_1.code || d.code === Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code);
1935-
checkDiagnostics = checkDiagnostics.filter(d => d.code === Diagnostics.Cannot_find_name_0_Did_you_mean_1.code || d.code === Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code);
1934+
if (isCheckJsUndefined) {
1935+
checkDiagnostics = checkDiagnostics.filter(d =>
1936+
d.code === Diagnostics.Cannot_find_name_0_Did_you_mean_1.code
1937+
|| d.code === Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code);
19361938
}
19371939
return getMergedBindAndCheckDiagnostics(sourceFile, includeBindAndCheckDiagnostics, bindDiagnostics, checkDiagnostics, isCheckJsTrue ? sourceFile.jsDocDiagnostics : undefined);
19381940
});

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6797,7 +6797,7 @@ namespace ts {
67976797
export function tryGetExtensionFromPath(path: string): Extension | undefined {
67986798
return find<Extension>(extensionsToRemove, e => fileExtensionIs(path, e));
67996799
}
6800-
// TODO: Callers of this function in services are probably what *actually* need to change
6800+
68016801
export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) {
68026802
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
68036803
}

0 commit comments

Comments
 (0)