Skip to content

Commit b57830f

Browse files
TravCavmhegazy
authored andcommitted
enforcing curly braces (#16315)
1 parent 68122ea commit b57830f

File tree

10 files changed

+167
-118
lines changed

10 files changed

+167
-118
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16831,8 +16831,9 @@ namespace ts {
1683116831
(expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) {
1683216832
// Look for if this is the constructor for the class that `symbol` is a property of.
1683316833
const func = getContainingFunction(expr);
16834-
if (!(func && func.kind === SyntaxKind.Constructor))
16834+
if (!(func && func.kind === SyntaxKind.Constructor)) {
1683516835
return true;
16836+
}
1683616837
// If func.parent is a class and symbol is a (readonly) property of that class, or
1683716838
// if func is a constructor and symbol is a (readonly) parameter property declared in it,
1683816839
// then symbol is writeable here.

src/compiler/commandLineParser.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,10 +1626,12 @@ namespace ts {
16261626
}
16271627

16281628
// Remove any subpaths under an existing recursively watched directory.
1629-
for (const key in wildcardDirectories) if (hasProperty(wildcardDirectories, key)) {
1630-
for (const recursiveKey of recursiveKeys) {
1631-
if (key !== recursiveKey && containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) {
1632-
delete wildcardDirectories[key];
1629+
for (const key in wildcardDirectories) {
1630+
if (hasProperty(wildcardDirectories, key)) {
1631+
for (const recursiveKey of recursiveKeys) {
1632+
if (key !== recursiveKey && containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) {
1633+
delete wildcardDirectories[key];
1634+
}
16331635
}
16341636
}
16351637
}
@@ -1717,10 +1719,12 @@ namespace ts {
17171719
/* @internal */
17181720
export function convertCompilerOptionsForTelemetry(opts: ts.CompilerOptions): ts.CompilerOptions {
17191721
const out: ts.CompilerOptions = {};
1720-
for (const key in opts) if (opts.hasOwnProperty(key)) {
1721-
const type = getOptionFromName(key);
1722-
if (type !== undefined) { // Ignore unknown options
1723-
out[key] = getOptionValueWithEmptyStrings(opts[key], type);
1722+
for (const key in opts) {
1723+
if (opts.hasOwnProperty(key)) {
1724+
const type = getOptionFromName(key);
1725+
if (type !== undefined) { // Ignore unknown options
1726+
out[key] = getOptionValueWithEmptyStrings(opts[key], type);
1727+
}
17241728
}
17251729
}
17261730
return out;

src/compiler/core.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ namespace ts {
5151

5252
// Copies keys/values from template. Note that for..in will not throw if
5353
// template is undefined, and instead will just exit the loop.
54-
for (const key in template) if (hasOwnProperty.call(template, key)) {
55-
map.set(key, template[key]);
54+
for (const key in template) {
55+
if (hasOwnProperty.call(template, key)) {
56+
map.set(key, template[key]);
57+
}
5658
}
5759

5860
return map;
@@ -977,9 +979,12 @@ namespace ts {
977979
*/
978980
export function getOwnKeys<T>(map: MapLike<T>): string[] {
979981
const keys: string[] = [];
980-
for (const key in map) if (hasOwnProperty.call(map, key)) {
981-
keys.push(key);
982+
for (const key in map) {
983+
if (hasOwnProperty.call(map, key)) {
984+
keys.push(key);
985+
}
982986
}
987+
983988
return keys;
984989
}
985990

@@ -1042,8 +1047,10 @@ namespace ts {
10421047
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]): any;
10431048
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]) {
10441049
for (const arg of args) {
1045-
for (const p in arg) if (hasProperty(arg, p)) {
1046-
t[p] = arg[p];
1050+
for (const p in arg) {
1051+
if (hasProperty(arg, p)) {
1052+
t[p] = arg[p];
1053+
}
10471054
}
10481055
}
10491056
return t;
@@ -1058,13 +1065,19 @@ namespace ts {
10581065
export function equalOwnProperties<T>(left: MapLike<T>, right: MapLike<T>, equalityComparer?: (left: T, right: T) => boolean) {
10591066
if (left === right) return true;
10601067
if (!left || !right) return false;
1061-
for (const key in left) if (hasOwnProperty.call(left, key)) {
1062-
if (!hasOwnProperty.call(right, key) === undefined) return false;
1063-
if (equalityComparer ? !equalityComparer(left[key], right[key]) : left[key] !== right[key]) return false;
1068+
for (const key in left) {
1069+
if (hasOwnProperty.call(left, key)) {
1070+
if (!hasOwnProperty.call(right, key) === undefined) return false;
1071+
if (equalityComparer ? !equalityComparer(left[key], right[key]) : left[key] !== right[key]) return false;
1072+
}
10641073
}
1065-
for (const key in right) if (hasOwnProperty.call(right, key)) {
1066-
if (!hasOwnProperty.call(left, key)) return false;
1074+
1075+
for (const key in right) {
1076+
if (hasOwnProperty.call(right, key)) {
1077+
if (!hasOwnProperty.call(left, key)) return false;
1078+
}
10671079
}
1080+
10681081
return true;
10691082
}
10701083

@@ -1106,12 +1119,18 @@ namespace ts {
11061119

11071120
export function extend<T1, T2>(first: T1, second: T2): T1 & T2 {
11081121
const result: T1 & T2 = <any>{};
1109-
for (const id in second) if (hasOwnProperty.call(second, id)) {
1110-
(result as any)[id] = (second as any)[id];
1122+
for (const id in second) {
1123+
if (hasOwnProperty.call(second, id)) {
1124+
(result as any)[id] = (second as any)[id];
1125+
}
11111126
}
1112-
for (const id in first) if (hasOwnProperty.call(first, id)) {
1113-
(result as any)[id] = (first as any)[id];
1127+
1128+
for (const id in first) {
1129+
if (hasOwnProperty.call(first, id)) {
1130+
(result as any)[id] = (first as any)[id];
1131+
}
11141132
}
1133+
11151134
return result;
11161135
}
11171136

src/harness/fourslash.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,21 +1036,27 @@ namespace FourSlash {
10361036
fail(`Expected ${expected}, got ${actual}`);
10371037
}
10381038

1039-
for (const key in actual) if (ts.hasProperty(actual as any, key)) {
1040-
const ak = actual[key], ek = expected[key];
1041-
if (typeof ak === "object" && typeof ek === "object") {
1042-
recur(ak, ek, path ? path + "." + key : key);
1043-
}
1044-
else if (ak !== ek) {
1045-
fail(`Expected '${key}' to be '${ek}', got '${ak}'`);
1039+
for (const key in actual) {
1040+
if (ts.hasProperty(actual as any, key)) {
1041+
const ak = actual[key], ek = expected[key];
1042+
if (typeof ak === "object" && typeof ek === "object") {
1043+
recur(ak, ek, path ? path + "." + key : key);
1044+
}
1045+
else if (ak !== ek) {
1046+
fail(`Expected '${key}' to be '${ek}', got '${ak}'`);
1047+
}
10461048
}
10471049
}
1048-
for (const key in expected) if (ts.hasProperty(expected as any, key)) {
1049-
if (!ts.hasProperty(actual as any, key)) {
1050-
fail(`${msgPrefix}Missing property '${key}'`);
1050+
1051+
for (const key in expected) {
1052+
if (ts.hasProperty(expected as any, key)) {
1053+
if (!ts.hasProperty(actual as any, key)) {
1054+
fail(`${msgPrefix}Missing property '${key}'`);
1055+
}
10511056
}
10521057
}
10531058
};
1059+
10541060
if (fullActual === undefined || fullExpected === undefined) {
10551061
if (fullActual === fullExpected) {
10561062
return;
@@ -1132,15 +1138,17 @@ namespace FourSlash {
11321138
}
11331139

11341140
public verifyQuickInfos(namesAndTexts: { [name: string]: string | [string, string] }) {
1135-
for (const name in namesAndTexts) if (ts.hasProperty(namesAndTexts, name)) {
1136-
const text = namesAndTexts[name];
1137-
if (ts.isArray(text)) {
1138-
assert(text.length === 2);
1139-
const [expectedText, expectedDocumentation] = text;
1140-
this.verifyQuickInfoAt(name, expectedText, expectedDocumentation);
1141-
}
1142-
else {
1143-
this.verifyQuickInfoAt(name, text);
1141+
for (const name in namesAndTexts) {
1142+
if (ts.hasProperty(namesAndTexts, name)) {
1143+
const text = namesAndTexts[name];
1144+
if (ts.isArray(text)) {
1145+
assert(text.length === 2);
1146+
const [expectedText, expectedDocumentation] = text;
1147+
this.verifyQuickInfoAt(name, expectedText, expectedDocumentation);
1148+
}
1149+
else {
1150+
this.verifyQuickInfoAt(name, text);
1151+
}
11441152
}
11451153
}
11461154
}
@@ -1149,7 +1157,6 @@ namespace FourSlash {
11491157
if (expectedDocumentation === "") {
11501158
throw new Error("Use 'undefined' instead");
11511159
}
1152-
11531160
const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
11541161
const actualQuickInfoText = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.displayParts) : "";
11551162
const actualQuickInfoDocumentation = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.documentation) : "";

src/harness/harness.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ namespace Utils {
259259
return true;
260260
}
261261
else if ((f & v) > 0) {
262-
if (result.length)
262+
if (result.length) {
263263
result += " | ";
264+
}
264265
result += flags[v];
265266
return false;
266267
}

src/server/session.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,18 +1563,22 @@ namespace ts.server {
15631563
const normalizedFileName = toNormalizedPath(fileName);
15641564
const project = this.projectService.getDefaultProjectForFile(normalizedFileName, /*refreshInferredProjects*/ true);
15651565
for (const fileNameInProject of fileNamesInProject) {
1566-
if (this.getCanonicalFileName(fileNameInProject) === this.getCanonicalFileName(fileName))
1566+
if (this.getCanonicalFileName(fileNameInProject) === this.getCanonicalFileName(fileName)) {
15671567
highPriorityFiles.push(fileNameInProject);
1568+
}
15681569
else {
15691570
const info = this.projectService.getScriptInfo(fileNameInProject);
15701571
if (!info.isScriptOpen()) {
1571-
if (fileNameInProject.indexOf(".d.ts") > 0)
1572+
if (fileNameInProject.indexOf(".d.ts") > 0) {
15721573
veryLowPriorityFiles.push(fileNameInProject);
1573-
else
1574+
}
1575+
else {
15741576
lowPriorityFiles.push(fileNameInProject);
1577+
}
15751578
}
1576-
else
1579+
else {
15771580
mediumPriorityFiles.push(fileNameInProject);
1581+
}
15781582
}
15791583
}
15801584

0 commit comments

Comments
 (0)