Skip to content

Commit 22eef28

Browse files
forEach -> for-of, and other changes.
1 parent 8bb6313 commit 22eef28

1 file changed

Lines changed: 25 additions & 21 deletions

File tree

scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ const tscPath = path.join(tscRoot, "built", "instrumented", "tsc.js");
1717
const rwcTestPath = path.join(tscRoot, "tests", "cases", "rwc", "dt");
1818
const definitelyTypedRoot = process.argv[2];
1919

20-
function fileExtensionIs(path: string, extension: string): boolean {
20+
importDefinitelyTypedTests(definitelyTypedRoot);
21+
22+
function filePathEndsWith(path: string, endingString: string): boolean {
2123
const pathLen = path.length;
22-
const extLen = extension.length;
23-
return pathLen > extLen && path.substr(pathLen - extLen, extLen).toLocaleLowerCase() === extension.toLocaleLowerCase();
24+
const extLen = endingString.length;
25+
return pathLen > extLen && path.substr(pathLen - extLen, extLen).toLocaleLowerCase() === endingString.toLocaleLowerCase();
2426
}
2527

2628
function copyFileSync(source: string, destination: string) {
@@ -94,7 +96,7 @@ function importDefinitelyTypedTests(definitelyTypedRoot: string): void {
9496
.filter(i => i.indexOf("sipml") >=0 )
9597
.filter(i => fs.statSync(path.join(definitelyTypedRoot, i)).isDirectory())
9698
.forEach(d => {
97-
let directoryPath = path.join(definitelyTypedRoot, d);
99+
const directoryPath = path.join(definitelyTypedRoot, d);
98100
fs.readdir(directoryPath, function (err, files) {
99101
if (err) {
100102
throw err;
@@ -104,35 +106,37 @@ function importDefinitelyTypedTests(definitelyTypedRoot: string): void {
104106
let testFiles: string[] = [];
105107
let paramFile: string;
106108

107-
files
108-
.map(f => path.join(directoryPath, f))
109-
.forEach(f => {
110-
if (fileExtensionIs(f, ".ts")) tsFiles.push(f);
111-
else if (fileExtensionIs(f, ".tscparams")) paramFile = f;
109+
for (const filePath of files.map(f => path.join(directoryPath, f))) {
110+
if (filePathEndsWith(filePath, ".ts")) {
111+
tsFiles.push(filePath);
112112

113-
if (fileExtensionIs(f, "-tests.ts")) testFiles.push(f);
114-
});
113+
if (filePathEndsWith(filePath, "-tests.ts")) {
114+
testFiles.push(filePath);
115+
}
116+
}
117+
else if (filePathEndsWith(filePath, ".tscparams")) {
118+
paramFile = filePath;
119+
}
120+
}
115121

116122
if (testFiles.length === 0) {
117123
// no test files but multiple d.ts's, e.g. winjs
118124
let regexp = new RegExp(d + "(([-][0-9])|([\.]d[\.]ts))");
119-
if (tsFiles.length > 1 && tsFiles.every(t => fileExtensionIs(t, ".d.ts") && regexp.test(t))) {
120-
tsFiles.forEach(filename => {
121-
importDefinitelyTypedTest(path.basename(filename, ".d.ts"), [filename], paramFile);
122-
});
125+
if (tsFiles.length > 1 && tsFiles.every(t => filePathEndsWith(t, ".d.ts") && regexp.test(t))) {
126+
for (const fileName of tsFiles) {
127+
importDefinitelyTypedTest(path.basename(fileName, ".d.ts"), [fileName], paramFile);
128+
}
123129
}
124130
else {
125131
importDefinitelyTypedTest(d, tsFiles, paramFile);
126132
}
127133
}
128134
else {
129-
testFiles.forEach(filename => {
130-
importDefinitelyTypedTest(path.basename(filename, "-tests.ts"), [filename], paramFile);
131-
});
135+
for (const fileName of tsFiles) {
136+
importDefinitelyTypedTest(path.basename(fileName, "-tests.ts"), [fileName], paramFile);
137+
}
132138
}
133139
});
134140
})
135141
});
136-
}
137-
138-
importDefinitelyTypedTests(definitelyTypedRoot);
142+
}

0 commit comments

Comments
 (0)