Skip to content

Commit b9a548c

Browse files
committed
Squash port of PR #19542
1 parent f2931a1 commit b9a548c

File tree

6 files changed

+59
-18
lines changed

6 files changed

+59
-18
lines changed

src/compiler/core.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ namespace ts {
7474
}
7575

7676
// The global Map object. This may not be available, so we must test for it.
77-
declare const Map: { new<T>(): Map<T> } | undefined;
77+
declare const Map: { new <T>(): Map<T> } | undefined;
7878
// Internet Explorer's Map doesn't support iteration, so don't use it.
7979
// tslint:disable-next-line:no-in-operator
8080
const MapCtr = typeof Map !== "undefined" && "entries" in Map.prototype ? Map : shimMap();
8181

8282
// Keep the class inside a function so it doesn't get compiled if it's not used.
83-
function shimMap(): { new<T>(): Map<T> } {
83+
function shimMap(): { new <T>(): Map<T> } {
8484

8585
class MapIterator<T, U extends (string | T | [string, T])> {
8686
private data: MapLike<T>;
@@ -103,7 +103,7 @@ namespace ts {
103103
}
104104
}
105105

106-
return class<T> implements Map<T> {
106+
return class <T> implements Map<T> {
107107
private data = createDictionaryObject<T>();
108108
public size = 0;
109109

@@ -166,8 +166,8 @@ namespace ts {
166166
}
167167

168168
export const enum Comparison {
169-
LessThan = -1,
170-
EqualTo = 0,
169+
LessThan = -1,
170+
EqualTo = 0,
171171
GreaterThan = 1
172172
}
173173

@@ -2626,7 +2626,7 @@ namespace ts {
26262626
return findBestPatternMatch(patterns, _ => _, candidate);
26272627
}
26282628

2629-
export function patternText({prefix, suffix}: Pattern): string {
2629+
export function patternText({ prefix, suffix }: Pattern): string {
26302630
return `${prefix}*${suffix}`;
26312631
}
26322632

@@ -2656,7 +2656,7 @@ namespace ts {
26562656
return matchedValue;
26572657
}
26582658

2659-
function isPatternMatch({prefix, suffix}: Pattern, candidate: string) {
2659+
function isPatternMatch({ prefix, suffix }: Pattern, candidate: string) {
26602660
return candidate.length >= prefix.length + suffix.length &&
26612661
startsWith(candidate, prefix) &&
26622662
endsWith(candidate, suffix);

src/harness/unittests/tsserverProjectSystem.ts

+36
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,42 @@ namespace ts.projectSystem {
15401540
}
15411541
});
15421542

1543+
it("removes version numbers correctly", () => {
1544+
const testData: [string, string][] = [
1545+
["jquery-max", "jquery-max"],
1546+
["jquery.min", "jquery"],
1547+
["jquery-min.4.2.3", "jquery"],
1548+
["jquery.min.4.2.1", "jquery"],
1549+
["minimum", "minimum"],
1550+
["min", "min"],
1551+
["min.3.2", "min"],
1552+
["jquery", "jquery"]
1553+
];
1554+
for (const t of testData) {
1555+
assert.equal(removeMinAndVersionNumbers(t[0]), t[1], t[0]);
1556+
}
1557+
});
1558+
1559+
it("ignores files excluded by a legacy safe type list", () => {
1560+
const file1 = {
1561+
path: "/a/b/bliss.js",
1562+
content: "let x = 5"
1563+
};
1564+
const file2 = {
1565+
path: "/a/b/foo.js",
1566+
content: ""
1567+
};
1568+
const host = createServerHost([file1, file2, customTypesMap]);
1569+
const projectService = createProjectService(host);
1570+
try {
1571+
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, file2.path]), typeAcquisition: { enable: true } });
1572+
const proj = projectService.externalProjects[0];
1573+
assert.deepEqual(proj.getFileNames(), [file2.path]);
1574+
} finally {
1575+
projectService.resetSafeList();
1576+
}
1577+
});
1578+
15431579
it("open file become a part of configured project if it is referenced from root file", () => {
15441580
const file1 = {
15451581
path: "/a/b/f1.ts",

src/harness/unittests/typingsInstaller.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,9 @@ namespace ts.projectSystem {
521521
// Commander: Existed as a JS file
522522
// JQuery: Specified in 'include'
523523
// Moment: Specified in 'include'
524+
// Express: Specified in package.json
524525
// lodash: Excluded (not present)
525-
checkProjectActualFiles(p, [file3dts.path, commander.path, jquery.path, moment.path]);
526+
checkProjectActualFiles(p, [file3dts.path, commander.path, express.path, jquery.path, moment.path]);
526527
});
527528

528529
it("Throttle - delayed typings to install", () => {
@@ -601,7 +602,7 @@ namespace ts.projectSystem {
601602
}
602603
host.checkTimeoutQueueLengthAndRun(2);
603604
checkNumberOfProjects(projectService, { externalProjects: 1 });
604-
checkProjectActualFiles(p, [file3.path, commander.path, jquery.path, moment.path, lodash.path]);
605+
checkProjectActualFiles(p, [file3.path, commander.path, express.path, jquery.path, moment.path, lodash.path]);
605606
});
606607

607608
it("Throttle - delayed run install requests", () => {
@@ -1101,11 +1102,12 @@ namespace ts.projectSystem {
11011102
const host = createServerHost([app, jquery, chroma]);
11021103
const logger = trackingLogger();
11031104
const result = JsTyping.discoverTypings(host, logger.log, [app.path, jquery.path, chroma.path], getDirectoryPath(<Path>app.path), safeList, emptyMap, { enable: true }, emptyArray);
1104-
assert.deepEqual(logger.finish(), [
1105+
const finish = logger.finish();
1106+
assert.deepEqual(finish, [
11051107
'Inferred typings from file names: ["jquery","chroma-js"]',
11061108
"Inferred typings from unresolved imports: []",
11071109
'Result: {"cachedTypingPaths":[],"newTypingNames":["jquery","chroma-js"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}',
1108-
]);
1110+
], finish.join("\r\n"));
11091111
assert.deepEqual(result.newTypingNames, ["jquery", "chroma-js"]);
11101112
});
11111113

src/server/editorServices.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,12 @@ namespace ts.server {
431431
this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
432432
this.throttledOperations = new ThrottledOperations(this.host, this.logger);
433433

434-
if (opts.typesMapLocation) {
434+
if (this.typesMapLocation) {
435435
this.loadTypesMap();
436436
}
437+
else {
438+
this.logger.info("No types map provided; using the default");
439+
}
437440

438441
this.typingsInstaller.attach(this);
439442

@@ -1399,7 +1402,7 @@ namespace ts.server {
13991402
return false;
14001403
}
14011404

1402-
private createExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition) {
1405+
private createExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition, excludedFiles: NormalizedPath[]) {
14031406
const compilerOptions = convertCompilerOptions(options);
14041407
const project = new ExternalProject(
14051408
projectFileName,
@@ -1408,6 +1411,7 @@ namespace ts.server {
14081411
compilerOptions,
14091412
/*languageServiceEnabled*/ !this.exceededTotalSizeLimitForNonTsFiles(projectFileName, compilerOptions, files, externalFilePropertyReader),
14101413
options.compileOnSave === undefined ? true : options.compileOnSave);
1414+
project.excludedFiles = excludedFiles;
14111415

14121416
this.addFilesToNonInferredProjectAndUpdateGraph(project, files, externalFilePropertyReader, typeAcquisition);
14131417
this.externalProjects.push(project);
@@ -2178,7 +2182,7 @@ namespace ts.server {
21782182
const rule = this.safelist[name];
21792183
for (const root of normalizedNames) {
21802184
if (rule.match.test(root)) {
2181-
this.logger.info(`Excluding files based on rule ${name}`);
2185+
this.logger.info(`Excluding files based on rule ${name} matching file '${root}'`);
21822186

21832187
// If the file matches, collect its types packages and exclude rules
21842188
if (rule.types) {
@@ -2369,8 +2373,7 @@ namespace ts.server {
23692373
else {
23702374
// no config files - remove the item from the collection
23712375
this.externalProjectToConfiguredProjectMap.delete(proj.projectFileName);
2372-
const newProj = this.createExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition);
2373-
newProj.excludedFiles = excludedFiles;
2376+
this.createExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition, excludedFiles);
23742377
}
23752378
if (!suppressRefreshOfInferredProjects) {
23762379
this.ensureProjectStructuresUptoDate(/*refreshInferredProjects*/ true);

src/services/jsTyping.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ namespace ts.JsTyping {
180180
if (!hasJavaScriptFileExtension(j)) return undefined;
181181

182182
const inferredTypingName = removeFileExtension(getBaseFileName(j.toLowerCase()));
183-
const cleanedTypingName = inferredTypingName.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "");
183+
const cleanedTypingName = removeMinAndVersionNumbers(inferredTypingName);
184184
return safeList.get(cleanedTypingName);
185185
});
186186
if (fromFileNames.length) {

tests/baselines/reference/api/tsserverlibrary.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7616,7 +7616,7 @@ declare namespace ts.server {
76167616
private findExternalProjectByProjectName(projectFileName);
76177617
private convertConfigFileContentToProjectOptions(configFilename, cachedDirectoryStructureHost);
76187618
private exceededTotalSizeLimitForNonTsFiles<T>(name, options, fileNames, propertyReader);
7619-
private createExternalProject(projectFileName, files, options, typeAcquisition);
7619+
private createExternalProject(projectFileName, files, options, typeAcquisition, excludedFiles);
76207620
private sendProjectTelemetry(projectKey, project, projectOptions?);
76217621
private addFilesToNonInferredProjectAndUpdateGraph<T>(project, files, propertyReader, typeAcquisition);
76227622
private createConfiguredProject(configFileName);

0 commit comments

Comments
 (0)