Skip to content

Commit 376cea6

Browse files
committed
Allow resetting so tests pass
1 parent a4c2f78 commit 376cea6

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,13 @@ namespace ts.projectSystem {
1717
})
1818
};
1919

20-
const typeMapList = {
20+
const customSafeList = {
2121
path: <Path>"/typeMapList.json",
2222
content: JSON.stringify({
23-
"jquery": {
24-
// jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
25-
"match": "/jquery(-(\\.?\\d+)+)?(\\.intellisense)?(\\.min)?\\.js$",
26-
"types": ["jquery"]
23+
"quack": {
24+
"match": "/duckquack-(\\d+)\\.min\\.js",
25+
"types": ["duck-types"]
2726
},
28-
"WinJS": {
29-
"match": "^(.*/winjs)/base\\.js$", // If the winjs/base.js file is found..
30-
"exclude": [["^", 1, "/.*"]], // ..then exclude all files under the winjs folder
31-
"types": ["winjs"] // And fetch the @types package for WinJS
32-
},
33-
"Office Nuget": {
34-
"match": "^(.*/1/office)/excel\\.debug\\.js$", // Office NuGet package is installed under a "1/office" folder
35-
"exclude": [["^", 1, "/.*"]], // Exclude that whole folder if the file indicated above is found in it
36-
"types": ["office"] // @types package to fetch instead
37-
},
38-
"Minified files": {
39-
"match": "^.*\\.min\\.js$" // Catch-all for minified files. Default exclude is the matched file.
40-
}
4127
})
4228
};
4329

@@ -1475,17 +1461,20 @@ namespace ts.projectSystem {
14751461
content: "export let x = 5"
14761462
};
14771463
const office = {
1478-
path: "lib/1/office/excel.debug.js",
1464+
path: "/lib/duckquack-3.min.js",
14791465
content: "whoa do @@ not parse me ok thanks!!!"
14801466
};
1481-
const host = createServerHost([typeMapList, file1, office]);
1467+
const host = createServerHost([customSafeList, file1, office]);
14821468
const projectService = createProjectService(host);
1483-
projectService.loadSafeList(typeMapList.path);
1484-
1485-
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) });
1486-
const proj = projectService.externalProjects[0];
1487-
assert.deepEqual(proj.getFileNames(true), [file1.path]);
1488-
assert.deepEqual(proj.getTypeAcquisition().include, ["office"]);
1469+
projectService.loadSafeList(customSafeList.path);
1470+
try {
1471+
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) });
1472+
const proj = projectService.externalProjects[0];
1473+
assert.deepEqual(proj.getFileNames(true), [file1.path]);
1474+
assert.deepEqual(proj.getTypeAcquisition().include, ["duck-types"]);
1475+
} finally {
1476+
projectService.resetSafeList();
1477+
}
14891478
});
14901479

14911480
it("open file become a part of configured project if it is referenced from root file", () => {

src/server/editorServices.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ namespace ts.server {
6161
"smart": IndentStyle.Smart
6262
});
6363

64+
const defaultTypeSafeList: SafeList = {
65+
"jquery": {
66+
// jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
67+
"match": /jquery(-(\.?\d+)+)?(\.intellisense)?(\.min)?\.js$/gi,
68+
"types": ["jquery"]
69+
},
70+
"WinJS": {
71+
"match": /^(.*\/winjs)\/base\.js$/gi, // If the winjs/base.js file is found..
72+
"exclude": [["^", 1, "/.*"]], // ..then exclude all files under the winjs folder
73+
"types": ["winjs"] // And fetch the @types package for WinJS
74+
},
75+
"Office Nuget": {
76+
"match": /^(.*\/1\/office)\/excel\.debug\.js$/gi, // Office NuGet package is installed under a "1/office" folder
77+
"exclude": [["^", 1, "/.*"]], // Exclude that whole folder if the file indicated above is found in it
78+
"types": ["office"] // @types package to fetch instead
79+
}
80+
};
81+
6482
export function convertFormatOptions(protocolOptions: protocol.FormatCodeSettings): FormatCodeSettings {
6583
if (typeof protocolOptions.indentStyle === "string") {
6684
protocolOptions.indentStyle = indentStyle.get(protocolOptions.indentStyle.toLowerCase());
@@ -263,7 +281,7 @@ namespace ts.server {
263281
private readonly throttledOperations: ThrottledOperations;
264282

265283
private readonly hostConfiguration: HostConfiguration;
266-
private static safelist: SafeList = {};
284+
private static safelist: SafeList = defaultTypeSafeList;
267285

268286
private changedFiles: ScriptInfo[];
269287

@@ -1408,6 +1426,10 @@ namespace ts.server {
14081426
return filename.replace(this.filenameEscapeRegexp, "\\$&");
14091427
}
14101428

1429+
resetSafeList(): void {
1430+
ProjectService.safelist = defaultTypeSafeList;
1431+
}
1432+
14111433
loadSafeList(fileName: string): void {
14121434
const raw: SafeList = JSON.parse(this.host.readFile(fileName, "utf-8"));
14131435
// Parse the regexps

0 commit comments

Comments
 (0)