mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-25 05:29:07 -05:00
perf: replace String and Array indexOf method calls with includes method call (#55482)
This commit is contained in:
@@ -329,7 +329,7 @@ class CompilerTest {
|
||||
}
|
||||
|
||||
public verifyTypesAndSymbols() {
|
||||
if (this.fileName.indexOf("APISample") >= 0) {
|
||||
if (this.fileName.includes("APISample")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ function handleTestConfig() {
|
||||
const runnerConfig = testConfig.runners || testConfig.test;
|
||||
if (runnerConfig && runnerConfig.length > 0) {
|
||||
if (testConfig.runners) {
|
||||
runUnitTests = runnerConfig.indexOf("unittest") !== -1;
|
||||
runUnitTests = runnerConfig.includes("unittest");
|
||||
}
|
||||
for (const option of runnerConfig) {
|
||||
if (!option) {
|
||||
|
||||
@@ -60,7 +60,7 @@ export function replaceText(fs: vfs.FileSystem, path: string, oldText: string, n
|
||||
throw new Error(`File ${path} does not exist`);
|
||||
}
|
||||
const old = fs.readFileSync(path, "utf-8");
|
||||
if (old.indexOf(oldText) < 0) {
|
||||
if (!old.includes(oldText)) {
|
||||
throw new Error(`Text "${oldText}" does not exist in file ${path}`);
|
||||
}
|
||||
const newContent = old.replace(oldText, newText);
|
||||
|
||||
@@ -63,7 +63,7 @@ function runBaseline(scenario: string, baselines: readonly string[]) {
|
||||
describe("unittests:: moduleResolution:: Node module resolution - relative paths", () => {
|
||||
// node module resolution does _not_ implicitly append these extensions to an extensionless path (though will still attempt to load them if explicitly)
|
||||
const nonImplicitExtensions = [ts.Extension.Mts, ts.Extension.Dmts, ts.Extension.Mjs, ts.Extension.Cts, ts.Extension.Dcts, ts.Extension.Cjs];
|
||||
const autoExtensions = ts.filter(ts.supportedTSExtensionsFlat, e => nonImplicitExtensions.indexOf(e) === -1);
|
||||
const autoExtensions = ts.filter(ts.supportedTSExtensionsFlat, e => !nonImplicitExtensions.includes(e));
|
||||
|
||||
it("load as file", () => {
|
||||
const baselines: string[] = [];
|
||||
|
||||
@@ -59,7 +59,7 @@ describe("unittests:: tsbuild - graph-ordering", () => {
|
||||
if (!circular) {
|
||||
for (const dep of deps) {
|
||||
const child = getProjectFileName(dep[0]);
|
||||
if (buildQueue.indexOf(child) < 0) continue;
|
||||
if (!buildQueue.includes(child)) continue;
|
||||
const parent = getProjectFileName(dep[1]);
|
||||
assert.isAbove(buildQueue.indexOf(child), buildQueue.indexOf(parent), `Expecting child ${child} to be built after parent ${parent}`);
|
||||
}
|
||||
@@ -73,8 +73,8 @@ describe("unittests:: tsbuild - graph-ordering", () => {
|
||||
function writeProjects(fileSystem: vfs.FileSystem, projectNames: string[], deps: [string, string][]): string[] {
|
||||
const projFileNames: string[] = [];
|
||||
for (const dep of deps) {
|
||||
if (projectNames.indexOf(dep[0]) < 0) throw new Error(`Invalid dependency - project ${dep[0]} does not exist`);
|
||||
if (projectNames.indexOf(dep[1]) < 0) throw new Error(`Invalid dependency - project ${dep[1]} does not exist`);
|
||||
if (!projectNames.includes(dep[0])) throw new Error(`Invalid dependency - project ${dep[0]} does not exist`);
|
||||
if (!projectNames.includes(dep[1])) throw new Error(`Invalid dependency - project ${dep[1]} does not exist`);
|
||||
}
|
||||
for (const proj of projectNames) {
|
||||
fileSystem.mkdirpSync(`/project/${proj}`);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
@@ -131,7 +130,7 @@ describe("unittests:: tsc:: declarationEmit::", () => {
|
||||
{ path: `/user/username/projects/myproject/plugin-one/node_modules/plugin-two`, symLink: `/user/username/projects/myproject/plugin-two` },
|
||||
libFile,
|
||||
],
|
||||
changeCaseFileTestPath: str => ts.stringContains(str, "/plugin-two"),
|
||||
changeCaseFileTestPath: str => str.includes("/plugin-two"),
|
||||
});
|
||||
|
||||
verifyDeclarationEmit({
|
||||
@@ -161,7 +160,7 @@ ${pluginOneAction()}`,
|
||||
{ path: `/user/username/projects/myproject/plugin-one/node_modules/plugin-two`, symLink: `/temp/yarn/data/link/plugin-two` },
|
||||
libFile,
|
||||
],
|
||||
changeCaseFileTestPath: str => ts.stringContains(str, "/plugin-two"),
|
||||
changeCaseFileTestPath: str => str.includes("/plugin-two"),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -254,6 +253,6 @@ ${pluginOneAction()}`,
|
||||
},
|
||||
libFile,
|
||||
],
|
||||
changeCaseFileTestPath: str => ts.stringContains(str, "/pkg1"),
|
||||
changeCaseFileTestPath: str => str.includes("/pkg1"),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,7 +69,7 @@ describe("unittests:: tsc-watch:: resolutionCache:: tsc-watch module resolution
|
||||
return false;
|
||||
}
|
||||
fileExistsIsCalled = true;
|
||||
assert.isTrue(fileName.indexOf("/f2.") !== -1);
|
||||
assert.isTrue(fileName.includes("/f2."));
|
||||
return originalFileExists.call(host, fileName);
|
||||
};
|
||||
sys.writeFile(root.path, `import {x} from "f2"`);
|
||||
@@ -88,7 +88,7 @@ describe("unittests:: tsc-watch:: resolutionCache:: tsc-watch module resolution
|
||||
return false;
|
||||
}
|
||||
fileExistsIsCalled = true;
|
||||
assert.isTrue(fileName.indexOf("/f1.") !== -1);
|
||||
assert.isTrue(fileName.includes("/f1."));
|
||||
return originalFileExists.call(host, fileName);
|
||||
};
|
||||
sys.writeFile(root.path, `import {x} from "f1"`);
|
||||
@@ -129,7 +129,7 @@ describe("unittests:: tsc-watch:: resolutionCache:: tsc-watch module resolution
|
||||
return false;
|
||||
}
|
||||
if (!fileExistsCalledForBar) {
|
||||
fileExistsCalledForBar = fileName.indexOf("/bar.") !== -1;
|
||||
fileExistsCalledForBar = fileName.includes("/bar.");
|
||||
}
|
||||
|
||||
return originalFileExists.call(host, fileName);
|
||||
@@ -187,7 +187,7 @@ describe("unittests:: tsc-watch:: resolutionCache:: tsc-watch module resolution
|
||||
return false;
|
||||
}
|
||||
if (!fileExistsCalledForBar) {
|
||||
fileExistsCalledForBar = fileName.indexOf("/bar.") !== -1;
|
||||
fileExistsCalledForBar = fileName.includes("/bar.");
|
||||
}
|
||||
return originalFileExists.call(host, fileName);
|
||||
};
|
||||
|
||||
@@ -717,7 +717,7 @@ describe("unittests:: tsserver:: typingsInstaller:: General functionality", () =
|
||||
logger,
|
||||
(installer, requestId, packageNames, cb) => {
|
||||
let typingFiles: (File & { typings: string; })[] = [];
|
||||
if (packageNames.indexOf(ts.server.typingsInstaller.typingsName("commander")) >= 0) {
|
||||
if (packageNames.includes(ts.server.typingsInstaller.typingsName("commander"))) {
|
||||
typingFiles = [commander, jquery, lodash, cordova];
|
||||
}
|
||||
else {
|
||||
@@ -1243,7 +1243,7 @@ describe("unittests:: tsserver:: typingsInstaller:: General functionality", () =
|
||||
logger,
|
||||
(installer, requestId, packageNames, cb) => {
|
||||
let typingFiles: (File & { typings: string; })[] = [];
|
||||
if (packageNames.indexOf(ts.server.typingsInstaller.typingsName("commander")) >= 0) {
|
||||
if (packageNames.includes(ts.server.typingsInstaller.typingsName("commander"))) {
|
||||
typingFiles = [commander];
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user