Skip to content

Commit 3b57b5d

Browse files
committed
Refactor checking for checkJs value in a common helper
1 parent 0dac29f commit 3b57b5d

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/compiler/core.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="types.ts"/>
1+
/// <reference path="types.ts"/>
22
/// <reference path="performance.ts" />
33

44
namespace ts {
@@ -2360,4 +2360,8 @@ namespace ts {
23602360
return Extension.Jsx;
23612361
}
23622362
}
2363+
2364+
export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) {
2365+
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
2366+
}
23632367
}

src/compiler/program.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="sys.ts" />
1+
/// <reference path="sys.ts" />
22
/// <reference path="emitter.ts" />
33
/// <reference path="core.ts" />
44

@@ -918,8 +918,7 @@ namespace ts {
918918
Debug.assert(!!sourceFile.bindDiagnostics);
919919
const bindDiagnostics = sourceFile.bindDiagnostics;
920920
// For JavaScript files, we don't want to report semantic errors unless explicitly requested.
921-
const includeCheckDiagnostics = !isSourceFileJavaScript(sourceFile) ||
922-
(sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : options.checkJs);
921+
const includeCheckDiagnostics = !isSourceFileJavaScript(sourceFile) || isCheckJsEnabledForFile(sourceFile, options);
923922
const checkDiagnostics = includeCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : [];
924923
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
925924
const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName);

src/services/codefixes/disableJsDiagnostics.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* @internal */
1+
/* @internal */
22
namespace ts.codefix {
33
registerCodeFix({
44
errorCodes: getApplicableDiagnosticCodes(),
@@ -12,10 +12,6 @@ namespace ts.codefix {
1212
.map(d => allDiagnostcs[d].code);
1313
}
1414

15-
function shouldCheckJsFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) {
16-
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
17-
}
18-
1915
function getSuppressCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string) {
2016
let { line } = getLineAndCharacterOfPosition(sourceFile, position);
2117
const lineStartPosition = getStartPositionOfLine(line, sourceFile);
@@ -46,7 +42,7 @@ namespace ts.codefix {
4642
function getDisableJsDiagnosticsCodeActions(context: CodeFixContext): CodeAction[] | undefined {
4743
const { sourceFile, program, newLineCharacter, span } = context;
4844

49-
if (!isInJavaScriptFile(sourceFile) || !shouldCheckJsFile(sourceFile, program.getCompilerOptions())) {
45+
if (!isInJavaScriptFile(sourceFile) || !isCheckJsEnabledForFile(sourceFile, program.getCompilerOptions())) {
5046
return undefined;
5147
}
5248

0 commit comments

Comments
 (0)