diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ddd20c3b2c39d..d2810a857ad69 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2846,7 +2846,7 @@ namespace ts { && !options.noResolve && i < file.imports.length && !elideImport - && !(isJsFile && !options.allowJs) + && !(isJsFile && !getAllowJSCompilerOption(options)) && (isInJSFile(file.imports[i]) || !(file.imports[i].flags & NodeFlags.JSDoc)); if (elideImport) { @@ -3160,7 +3160,7 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_target_is_ES3, "useDefineForClassFields"); } - if (options.checkJs && !options.allowJs) { + if (options.checkJs && !getAllowJSCompilerOption(options)) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs")); } @@ -3774,7 +3774,7 @@ namespace ts { return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set; } function needAllowJs() { - return options.allowJs || !getStrictOptionValue(options, "noImplicitAny") ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type; + return getAllowJSCompilerOption(options) || !getStrictOptionValue(options, "noImplicitAny") ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type; } function needResolveJsonModule() { return options.resolveJsonModule ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_resolveJsonModule_is_not_used; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6b58a9aafd6d3..00564bddb016a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -5922,6 +5922,10 @@ namespace ts { return compilerOptions[flag] === undefined ? !!compilerOptions.strict : !!compilerOptions[flag]; } + export function getAllowJSCompilerOption(compilerOptions: CompilerOptions): boolean { + return compilerOptions.allowJs === undefined ? !!compilerOptions.checkJs : compilerOptions.allowJs; + } + export function compilerOptionsAffectSemanticDiagnostics(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean { return oldOptions !== newOptions && semanticDiagnosticsOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option))); @@ -6375,7 +6379,7 @@ namespace ts { export function getSupportedExtensions(options?: CompilerOptions): readonly Extension[]; export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[]; export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[] { - const needJsExtensions = options && options.allowJs; + const needJsExtensions = options && getAllowJSCompilerOption(options); if (!extraFileExtensions || extraFileExtensions.length === 0) { return needJsExtensions ? allSupportedExtensions : supportedTSExtensions; diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 61a35dc1857ad..590913fd34c5d 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -623,7 +623,7 @@ namespace FourSlash { ts.forEachKey(this.inputFiles, fileName => { if (!ts.isAnySupportedFileExtension(fileName) || Harness.getConfigNameFromFileName(fileName) - || !this.getProgram().getCompilerOptions().allowJs && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return; + || !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return; const errors = this.getDiagnostics(fileName).filter(e => e.category !== ts.DiagnosticCategory.Suggestion); if (errors.length) { this.printErrorLog(/*expectErrors*/ false, errors); diff --git a/src/harness/harnessIO.ts b/src/harness/harnessIO.ts index c7f04cf277d92..0c62fc78ec88d 100644 --- a/src/harness/harnessIO.ts +++ b/src/harness/harnessIO.ts @@ -469,7 +469,7 @@ namespace Harness { if (vpath.isDeclaration(file.unitName) || vpath.isJson(file.unitName)) { dtsFiles.push(file); } - else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && options.allowJs)) { + else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && ts.getAllowJSCompilerOption(options))) { const declFile = findResultCodeFile(file.unitName); if (declFile && !findUnit(declFile.file, declInputFiles) && !findUnit(declFile.file, declOtherFiles)) { dtsFiles.push({ unitName: declFile.file, content: Utils.removeByteOrderMark(declFile.text) }); diff --git a/src/server/project.ts b/src/server/project.ts index 0e4f937552ea8..510f1291d4375 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -274,7 +274,7 @@ namespace ts.server { this.compilerOptions.allowNonTsExtensions = true; this.compilerOptions.allowJs = true; } - else if (hasExplicitListOfFiles || this.compilerOptions.allowJs || this.projectService.hasDeferredExtension()) { + else if (hasExplicitListOfFiles || getAllowJSCompilerOption(this.compilerOptions) || this.projectService.hasDeferredExtension()) { // If files are listed explicitly or allowJs is specified, allow all extensions this.compilerOptions.allowNonTsExtensions = true; } diff --git a/src/server/typingsCache.ts b/src/server/typingsCache.ts index 1d63a6df6ae6f..a20346c2b2e87 100644 --- a/src/server/typingsCache.ts +++ b/src/server/typingsCache.ts @@ -71,7 +71,7 @@ namespace ts.server { function compilerOptionsChanged(opt1: CompilerOptions, opt2: CompilerOptions): boolean { // TODO: add more relevant properties - return opt1.allowJs !== opt2.allowJs; + return getAllowJSCompilerOption(opt1) !== getAllowJSCompilerOption(opt2); } function unresolvedImportsChanged(imports1: SortedReadonlyArray | undefined, imports2: SortedReadonlyArray | undefined): boolean { diff --git a/tests/cases/conformance/salsa/inferringClassMembersFromAssignments2.ts b/tests/cases/conformance/salsa/inferringClassMembersFromAssignments2.ts index ba7ea55b2a36f..29eee549fa023 100644 --- a/tests/cases/conformance/salsa/inferringClassMembersFromAssignments2.ts +++ b/tests/cases/conformance/salsa/inferringClassMembersFromAssignments2.ts @@ -1,4 +1,3 @@ -// @allowJs: true // @checkJs: true // @noEmit: true // @filename: a.js diff --git a/tests/cases/conformance/salsa/moduleExportAlias4.ts b/tests/cases/conformance/salsa/moduleExportAlias4.ts index 0572401b80209..5d4d7d780a97a 100644 --- a/tests/cases/conformance/salsa/moduleExportAlias4.ts +++ b/tests/cases/conformance/salsa/moduleExportAlias4.ts @@ -1,5 +1,4 @@ // @checkJs: true -// @allowJS: true // @noEmit: true // @Filename: bug24024.js // #24024