Skip to content

Commit 83ef026

Browse files
authored
Merge pull request #13996 from Microsoft/UnsupportedExtensionsFix
Fix #13951: VS 2017 complains about unsupported extensions
2 parents ae02db4 + 3480fcc commit 83ef026

File tree

2 files changed

+111
-2
lines changed

2 files changed

+111
-2
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,115 @@ namespace ts.projectSystem {
17131713
assert(completions && completions.entries[0].name !== "hello", `unexpected hello entry in completion list`);
17141714
});
17151715

1716+
it("no tsconfig script block diagnostic errors", () => {
1717+
1718+
// #1. Ensure no diagnostic errors when allowJs is true
1719+
const file1 = {
1720+
path: "/a/b/f1.ts",
1721+
content: ` `
1722+
};
1723+
const file2 = {
1724+
path: "/a/b/f2.html",
1725+
content: `var hello = "hello";`
1726+
};
1727+
const config1 = {
1728+
path: "/a/b/tsconfig.json",
1729+
content: JSON.stringify({ compilerOptions: { allowJs: true } })
1730+
};
1731+
1732+
let host = createServerHost([file1, file2, config1, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1733+
let session = createSession(host);
1734+
1735+
// Specify .html extension as mixed content in a configure host request
1736+
const extraFileExtensions = [{ extension: ".html", scriptKind: ScriptKind.JS, isMixedContent: true }];
1737+
const configureHostRequest = makeSessionRequest<protocol.ConfigureRequestArguments>(CommandNames.Configure, { extraFileExtensions });
1738+
session.executeCommand(configureHostRequest).response;
1739+
1740+
openFilesForSession([file1], session);
1741+
let projectService = session.getProjectService();
1742+
1743+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1744+
1745+
let diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1746+
assert.deepEqual(diagnostics, []);
1747+
1748+
// #2. Ensure no errors when allowJs is false
1749+
const config2 = {
1750+
path: "/a/b/tsconfig.json",
1751+
content: JSON.stringify({ compilerOptions: { allowJs: false } })
1752+
};
1753+
1754+
host = createServerHost([file1, file2, config2, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1755+
session = createSession(host);
1756+
1757+
session.executeCommand(configureHostRequest).response;
1758+
1759+
openFilesForSession([file1], session);
1760+
projectService = session.getProjectService();
1761+
1762+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1763+
1764+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1765+
assert.deepEqual(diagnostics, []);
1766+
1767+
// #3. Ensure no errors when compiler options aren't specified
1768+
const config3 = {
1769+
path: "/a/b/tsconfig.json",
1770+
content: JSON.stringify({ })
1771+
};
1772+
1773+
host = createServerHost([file1, file2, config3, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1774+
session = createSession(host);
1775+
1776+
session.executeCommand(configureHostRequest).response;
1777+
1778+
openFilesForSession([file1], session);
1779+
projectService = session.getProjectService();
1780+
1781+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1782+
1783+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1784+
assert.deepEqual(diagnostics, []);
1785+
1786+
// #4. Ensure no errors when files are explicitly specified in tsconfig
1787+
const config4 = {
1788+
path: "/a/b/tsconfig.json",
1789+
content: JSON.stringify({ compilerOptions: { allowJs: true }, files: [file1.path, file2.path] })
1790+
};
1791+
1792+
host = createServerHost([file1, file2, config4, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1793+
session = createSession(host);
1794+
1795+
session.executeCommand(configureHostRequest).response;
1796+
1797+
openFilesForSession([file1], session);
1798+
projectService = session.getProjectService();
1799+
1800+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1801+
1802+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1803+
assert.deepEqual(diagnostics, []);
1804+
1805+
// #4. Ensure no errors when files are explicitly excluded in tsconfig
1806+
const config5 = {
1807+
path: "/a/b/tsconfig.json",
1808+
content: JSON.stringify({ compilerOptions: { allowJs: true }, exclude: [file2.path] })
1809+
};
1810+
1811+
host = createServerHost([file1, file2, config5, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1812+
session = createSession(host);
1813+
1814+
session.executeCommand(configureHostRequest).response;
1815+
1816+
openFilesForSession([file1], session);
1817+
projectService = session.getProjectService();
1818+
1819+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1820+
1821+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1822+
assert.deepEqual(diagnostics, []);
1823+
});
1824+
17161825
it("project structure update is deferred if files are not added\removed", () => {
17171826
const file1 = {
17181827
path: "/a/b/f1.ts",

src/server/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ namespace ts.server {
165165
this.compilerOptions.allowNonTsExtensions = true;
166166
this.compilerOptions.allowJs = true;
167167
}
168-
else if (hasExplicitListOfFiles) {
169-
// If files are listed explicitly, allow all extensions
168+
else if (hasExplicitListOfFiles || this.compilerOptions.allowJs) {
169+
// If files are listed explicitly or allowJs is specified, allow all extensions
170170
this.compilerOptions.allowNonTsExtensions = true;
171171
}
172172

0 commit comments

Comments
 (0)