Skip to content

Commit 3480fcc

Browse files
committed
Always set allowNonTsExtensions for allowJs
1 parent 2fc634f commit 3480fcc

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
@@ -1650,6 +1650,115 @@ namespace ts.projectSystem {
16501650
assert(completions && completions.entries[0].name !== "hello", `unexpected hello entry in completion list`);
16511651
});
16521652

1653+
it("no tsconfig script block diagnostic errors", () => {
1654+
1655+
// #1. Ensure no diagnostic errors when allowJs is true
1656+
const file1 = {
1657+
path: "/a/b/f1.ts",
1658+
content: ` `
1659+
};
1660+
const file2 = {
1661+
path: "/a/b/f2.html",
1662+
content: `var hello = "hello";`
1663+
};
1664+
const config1 = {
1665+
path: "/a/b/tsconfig.json",
1666+
content: JSON.stringify({ compilerOptions: { allowJs: true } })
1667+
};
1668+
1669+
let host = createServerHost([file1, file2, config1, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1670+
let session = createSession(host);
1671+
1672+
// Specify .html extension as mixed content in a configure host request
1673+
const extraFileExtensions = [{ extension: ".html", scriptKind: ScriptKind.JS, isMixedContent: true }];
1674+
const configureHostRequest = makeSessionRequest<protocol.ConfigureRequestArguments>(CommandNames.Configure, { extraFileExtensions });
1675+
session.executeCommand(configureHostRequest).response;
1676+
1677+
openFilesForSession([file1], session);
1678+
let projectService = session.getProjectService();
1679+
1680+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1681+
1682+
let diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1683+
assert.deepEqual(diagnostics, []);
1684+
1685+
// #2. Ensure no errors when allowJs is false
1686+
const config2 = {
1687+
path: "/a/b/tsconfig.json",
1688+
content: JSON.stringify({ compilerOptions: { allowJs: false } })
1689+
};
1690+
1691+
host = createServerHost([file1, file2, config2, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1692+
session = createSession(host);
1693+
1694+
session.executeCommand(configureHostRequest).response;
1695+
1696+
openFilesForSession([file1], session);
1697+
projectService = session.getProjectService();
1698+
1699+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1700+
1701+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1702+
assert.deepEqual(diagnostics, []);
1703+
1704+
// #3. Ensure no errors when compiler options aren't specified
1705+
const config3 = {
1706+
path: "/a/b/tsconfig.json",
1707+
content: JSON.stringify({ })
1708+
};
1709+
1710+
host = createServerHost([file1, file2, config3, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1711+
session = createSession(host);
1712+
1713+
session.executeCommand(configureHostRequest).response;
1714+
1715+
openFilesForSession([file1], session);
1716+
projectService = session.getProjectService();
1717+
1718+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1719+
1720+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1721+
assert.deepEqual(diagnostics, []);
1722+
1723+
// #4. Ensure no errors when files are explicitly specified in tsconfig
1724+
const config4 = {
1725+
path: "/a/b/tsconfig.json",
1726+
content: JSON.stringify({ compilerOptions: { allowJs: true }, files: [file1.path, file2.path] })
1727+
};
1728+
1729+
host = createServerHost([file1, file2, config4, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1730+
session = createSession(host);
1731+
1732+
session.executeCommand(configureHostRequest).response;
1733+
1734+
openFilesForSession([file1], session);
1735+
projectService = session.getProjectService();
1736+
1737+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1738+
1739+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1740+
assert.deepEqual(diagnostics, []);
1741+
1742+
// #4. Ensure no errors when files are explicitly excluded in tsconfig
1743+
const config5 = {
1744+
path: "/a/b/tsconfig.json",
1745+
content: JSON.stringify({ compilerOptions: { allowJs: true }, exclude: [file2.path] })
1746+
};
1747+
1748+
host = createServerHost([file1, file2, config5, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
1749+
session = createSession(host);
1750+
1751+
session.executeCommand(configureHostRequest).response;
1752+
1753+
openFilesForSession([file1], session);
1754+
projectService = session.getProjectService();
1755+
1756+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
1757+
1758+
diagnostics = projectService.configuredProjects[0].getLanguageService().getCompilerOptionsDiagnostics();
1759+
assert.deepEqual(diagnostics, []);
1760+
});
1761+
16531762
it("project structure update is deferred if files are not added\removed", () => {
16541763
const file1 = {
16551764
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)