Skip to content

Commit b0011fe

Browse files
authored
Checkjs implies allowjs (microsoft#40275)
* Passing --checkJs always sets --allowJS Even if you have `"allowJs": false`. This is not a useful combination. Changing this makes the compiler more friendly and easier to describe. * only set allowjs if not explicitly set * remove stray newline * restore bad config error * use an accessor function instead
1 parent d572dcb commit b0011fe

File tree

8 files changed

+12
-10
lines changed

8 files changed

+12
-10
lines changed

src/compiler/program.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ namespace ts {
28462846
&& !options.noResolve
28472847
&& i < file.imports.length
28482848
&& !elideImport
2849-
&& !(isJsFile && !options.allowJs)
2849+
&& !(isJsFile && !getAllowJSCompilerOption(options))
28502850
&& (isInJSFile(file.imports[i]) || !(file.imports[i].flags & NodeFlags.JSDoc));
28512851

28522852
if (elideImport) {
@@ -3160,7 +3160,7 @@ namespace ts {
31603160
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_target_is_ES3, "useDefineForClassFields");
31613161
}
31623162

3163-
if (options.checkJs && !options.allowJs) {
3163+
if (options.checkJs && !getAllowJSCompilerOption(options)) {
31643164
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs"));
31653165
}
31663166

@@ -3774,7 +3774,7 @@ namespace ts {
37743774
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
37753775
}
37763776
function needAllowJs() {
3777-
return options.allowJs || !getStrictOptionValue(options, "noImplicitAny") ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type;
3777+
return getAllowJSCompilerOption(options) || !getStrictOptionValue(options, "noImplicitAny") ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type;
37783778
}
37793779
function needResolveJsonModule() {
37803780
return options.resolveJsonModule ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_resolveJsonModule_is_not_used;

src/compiler/utilities.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5933,6 +5933,10 @@ namespace ts {
59335933
return compilerOptions[flag] === undefined ? !!compilerOptions.strict : !!compilerOptions[flag];
59345934
}
59355935

5936+
export function getAllowJSCompilerOption(compilerOptions: CompilerOptions): boolean {
5937+
return compilerOptions.allowJs === undefined ? !!compilerOptions.checkJs : compilerOptions.allowJs;
5938+
}
5939+
59365940
export function compilerOptionsAffectSemanticDiagnostics(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean {
59375941
return oldOptions !== newOptions &&
59385942
semanticDiagnosticsOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
@@ -6386,7 +6390,7 @@ namespace ts {
63866390
export function getSupportedExtensions(options?: CompilerOptions): readonly Extension[];
63876391
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[];
63886392
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[] {
6389-
const needJsExtensions = options && options.allowJs;
6393+
const needJsExtensions = options && getAllowJSCompilerOption(options);
63906394

63916395
if (!extraFileExtensions || extraFileExtensions.length === 0) {
63926396
return needJsExtensions ? allSupportedExtensions : supportedTSExtensions;

src/harness/fourslashImpl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ namespace FourSlash {
623623
ts.forEachKey(this.inputFiles, fileName => {
624624
if (!ts.isAnySupportedFileExtension(fileName)
625625
|| Harness.getConfigNameFromFileName(fileName)
626-
|| !this.getProgram().getCompilerOptions().allowJs && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return;
626+
|| !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return;
627627
const errors = this.getDiagnostics(fileName).filter(e => e.category !== ts.DiagnosticCategory.Suggestion);
628628
if (errors.length) {
629629
this.printErrorLog(/*expectErrors*/ false, errors);

src/harness/harnessIO.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ namespace Harness {
469469
if (vpath.isDeclaration(file.unitName) || vpath.isJson(file.unitName)) {
470470
dtsFiles.push(file);
471471
}
472-
else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && options.allowJs)) {
472+
else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && ts.getAllowJSCompilerOption(options))) {
473473
const declFile = findResultCodeFile(file.unitName);
474474
if (declFile && !findUnit(declFile.file, declInputFiles) && !findUnit(declFile.file, declOtherFiles)) {
475475
dtsFiles.push({ unitName: declFile.file, content: Utils.removeByteOrderMark(declFile.text) });

src/server/project.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ namespace ts.server {
274274
this.compilerOptions.allowNonTsExtensions = true;
275275
this.compilerOptions.allowJs = true;
276276
}
277-
else if (hasExplicitListOfFiles || this.compilerOptions.allowJs || this.projectService.hasDeferredExtension()) {
277+
else if (hasExplicitListOfFiles || getAllowJSCompilerOption(this.compilerOptions) || this.projectService.hasDeferredExtension()) {
278278
// If files are listed explicitly or allowJs is specified, allow all extensions
279279
this.compilerOptions.allowNonTsExtensions = true;
280280
}

src/server/typingsCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace ts.server {
7171

7272
function compilerOptionsChanged(opt1: CompilerOptions, opt2: CompilerOptions): boolean {
7373
// TODO: add more relevant properties
74-
return opt1.allowJs !== opt2.allowJs;
74+
return getAllowJSCompilerOption(opt1) !== getAllowJSCompilerOption(opt2);
7575
}
7676

7777
function unresolvedImportsChanged(imports1: SortedReadonlyArray<string> | undefined, imports2: SortedReadonlyArray<string> | undefined): boolean {

tests/cases/conformance/salsa/inferringClassMembersFromAssignments2.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @allowJs: true
21
// @checkJs: true
32
// @noEmit: true
43
// @filename: a.js

tests/cases/conformance/salsa/moduleExportAlias4.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// @checkJs: true
2-
// @allowJS: true
32
// @noEmit: true
43
// @Filename: bug24024.js
54
// #24024

0 commit comments

Comments
 (0)