Merge pull request #13996 from Microsoft/UnsupportedExtensionsFix

Fix #13951: VS 2017 complains about unsupported extensions
This commit is contained in:
Mohamed Hegazy 2017-02-14 13:42:13 -08:00 committed by GitHub
commit 83ef026613
2 changed files with 111 additions and 2 deletions

View file

@ -1713,6 +1713,115 @@ namespace ts.projectSystem {
assert(completions && completions.entries[0].name !== "hello", `unexpected hello entry in completion list`);
});
it("no tsconfig script block diagnostic errors", () => {
// #1. Ensure no diagnostic errors when allowJs is true
const file1 = {
path: "/a/b/f1.ts",
content: ` `
};
const file2 = {
path: "/a/b/f2.html",
content: `var hello = "hello";`
};
const config1 = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ compilerOptions: { allowJs: true } })
};
let host = createServerHost([file1, file2, config1, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
let session = createSession(host);
// Specify .html extension as mixed content in a configure host request
const extraFileExtensions = [{ extension: ".html", scriptKind: ScriptKind.JS, isMixedContent: true }];
const configureHostRequest = makeSessionRequest<protocol.ConfigureRequestArguments>(CommandNames.Configure, { extraFileExtensions });
session.executeCommand(configureHostRequest).response;
openFilesForSession([file1], session);
let projectService = session.getProjectService();
checkNumberOfProjects(projectService, { configuredProjects: 1 });
let diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
assert.deepEqual(diagnostics, []);
// #2. Ensure no errors when allowJs is false
const config2 = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ compilerOptions: { allowJs: false } })
};
host = createServerHost([file1, file2, config2, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);
session.executeCommand(configureHostRequest).response;
openFilesForSession([file1], session);
projectService = session.getProjectService();
checkNumberOfProjects(projectService, { configuredProjects: 1 });
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
assert.deepEqual(diagnostics, []);
// #3. Ensure no errors when compiler options aren't specified
const config3 = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ })
};
host = createServerHost([file1, file2, config3, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);
session.executeCommand(configureHostRequest).response;
openFilesForSession([file1], session);
projectService = session.getProjectService();
checkNumberOfProjects(projectService, { configuredProjects: 1 });
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
assert.deepEqual(diagnostics, []);
// #4. Ensure no errors when files are explicitly specified in tsconfig
const config4 = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ compilerOptions: { allowJs: true }, files: [file1.path, file2.path] })
};
host = createServerHost([file1, file2, config4, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);
session.executeCommand(configureHostRequest).response;
openFilesForSession([file1], session);
projectService = session.getProjectService();
checkNumberOfProjects(projectService, { configuredProjects: 1 });
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
assert.deepEqual(diagnostics, []);
// #4. Ensure no errors when files are explicitly excluded in tsconfig
const config5 = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ compilerOptions: { allowJs: true }, exclude: [file2.path] })
};
host = createServerHost([file1, file2, config5, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);
session.executeCommand(configureHostRequest).response;
openFilesForSession([file1], session);
projectService = session.getProjectService();
checkNumberOfProjects(projectService, { configuredProjects: 1 });
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
assert.deepEqual(diagnostics, []);
});
it("project structure update is deferred if files are not added\removed", () => {
const file1 = {
path: "/a/b/f1.ts",

View file

@ -165,8 +165,8 @@ namespace ts.server {
this.compilerOptions.allowNonTsExtensions = true;
this.compilerOptions.allowJs = true;
}
else if (hasExplicitListOfFiles) {
// If files are listed explicitly, allow all extensions
else if (hasExplicitListOfFiles || this.compilerOptions.allowJs) {
// If files are listed explicitly or allowJs is specified, allow all extensions
this.compilerOptions.allowNonTsExtensions = true;
}