Skip to content

Commit 68085fc

Browse files
author
Arthur Ozga
committed
Merge pull request microsoft#3529 from Microsoft/cleanupDoubleEquals
Cleanup double equals
2 parents 718dc5b + 1d5dcf0 commit 68085fc

24 files changed

+92
-84
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,7 +3523,7 @@ namespace ts {
35233523
// -> typeParameter and symbol.declaration originate from the same type parameter list
35243524
// -> illegal for all declarations in symbol
35253525
// forEach === exists
3526-
links.isIllegalTypeReferenceInConstraint = forEach(symbol.declarations, d => d.parent == typeParameter.parent);
3526+
links.isIllegalTypeReferenceInConstraint = forEach(symbol.declarations, d => d.parent === typeParameter.parent);
35273527
}
35283528
}
35293529
if (links.isIllegalTypeReferenceInConstraint) {
@@ -8432,7 +8432,7 @@ namespace ts {
84328432
// contextually typed function and arrow expressions in the initial phase.
84338433
function checkExpression(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type {
84348434
let type: Type;
8435-
if (node.kind == SyntaxKind.QualifiedName) {
8435+
if (node.kind === SyntaxKind.QualifiedName) {
84368436
type = checkQualifiedName(<QualifiedName>node);
84378437
}
84388438
else {
@@ -9871,7 +9871,7 @@ namespace ts {
98719871
function checkForStatement(node: ForStatement) {
98729872
// Grammar checking
98739873
if (!checkGrammarStatementInAmbientContext(node)) {
9874-
if (node.initializer && node.initializer.kind == SyntaxKind.VariableDeclarationList) {
9874+
if (node.initializer && node.initializer.kind === SyntaxKind.VariableDeclarationList) {
98759875
checkGrammarVariableDeclarationList(<VariableDeclarationList>node.initializer);
98769876
}
98779877
}
@@ -11751,7 +11751,7 @@ namespace ts {
1175111751
}
1175211752

1175311753
function isTypeDeclarationName(name: Node): boolean {
11754-
return name.kind == SyntaxKind.Identifier &&
11754+
return name.kind === SyntaxKind.Identifier &&
1175511755
isTypeDeclaration(name.parent) &&
1175611756
(<Declaration>name.parent).name === name;
1175711757
}
@@ -11920,7 +11920,7 @@ namespace ts {
1192011920
// Intentional fall-through
1192111921
case SyntaxKind.NumericLiteral:
1192211922
// index access
11923-
if (node.parent.kind == SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).argumentExpression === node) {
11923+
if (node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).argumentExpression === node) {
1192411924
let objectType = checkExpression((<ElementAccessExpression>node.parent).expression);
1192511925
if (objectType === unknownType) return undefined;
1192611926
let apparentType = getApparentType(objectType);

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ namespace ts {
572572
export function getNormalizedPathComponents(path: string, currentDirectory: string) {
573573
path = normalizeSlashes(path);
574574
let rootLength = getRootLength(path);
575-
if (rootLength == 0) {
575+
if (rootLength === 0) {
576576
// If the path is not rooted it is relative to current directory
577577
path = combinePaths(normalizeSlashes(currentDirectory), path);
578578
rootLength = getRootLength(path);

src/compiler/emitter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
320320

321321
let prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn;
322322
// Line/Comma delimiters
323-
if (lastEncodedSourceMapSpan.emittedLine == lastRecordedSourceMapSpan.emittedLine) {
323+
if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) {
324324
// Emit comma to separate the entry
325325
if (sourceMapData.sourceMapMappings) {
326326
sourceMapData.sourceMapMappings += ",";
@@ -403,8 +403,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
403403

404404
// If this location wasn't recorded or the location in source is going backwards, record the span
405405
if (!lastRecordedSourceMapSpan ||
406-
lastRecordedSourceMapSpan.emittedLine != emittedLine ||
407-
lastRecordedSourceMapSpan.emittedColumn != emittedColumn ||
406+
lastRecordedSourceMapSpan.emittedLine !== emittedLine ||
407+
lastRecordedSourceMapSpan.emittedColumn !== emittedColumn ||
408408
(lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex &&
409409
(lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line ||
410410
(lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) {
@@ -654,7 +654,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
654654
if (nodeIsSynthesized(node)) {
655655
return emitNodeWithoutSourceMap(node);
656656
}
657-
if (node.kind != SyntaxKind.SourceFile) {
657+
if (node.kind !== SyntaxKind.SourceFile) {
658658
recordEmitNodeStartSpan(node);
659659
emitNodeWithoutSourceMap(node);
660660
recordEmitNodeEndSpan(node);
@@ -1962,7 +1962,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
19621962

19631963
// Make sure we consider all nested cast expressions, e.g.:
19641964
// (<any><number><any>-A).x;
1965-
while (operand.kind == SyntaxKind.TypeAssertionExpression) {
1965+
while (operand.kind === SyntaxKind.TypeAssertionExpression) {
19661966
operand = (<TypeAssertion>operand).expression;
19671967
}
19681968

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ namespace ts {
934934
error(Diagnostics.Unexpected_end_of_text);
935935
isInvalidExtendedEscape = true;
936936
}
937-
else if (text.charCodeAt(pos) == CharacterCodes.closeBrace) {
937+
else if (text.charCodeAt(pos) === CharacterCodes.closeBrace) {
938938
// Only swallow the following character up if it's a '}'.
939939
pos++;
940940
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace ts {
4242
// Pool writers to avoid needing to allocate them for every symbol we write.
4343
let stringWriters: StringSymbolWriter[] = [];
4444
export function getSingleLineStringWriter(): StringSymbolWriter {
45-
if (stringWriters.length == 0) {
45+
if (stringWriters.length === 0) {
4646
let str = "";
4747

4848
let writeText: (text: string) => void = text => str += text;

src/harness/fourslash.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,15 @@ module FourSlash {
831831
if (expectedText !== undefined) {
832832
assert.notEqual(actualQuickInfoText, expectedText, this.messageAtLastKnownMarker("quick info text"));
833833
}
834+
// TODO: should be '==='?
834835
if (expectedDocumentation != undefined) {
835836
assert.notEqual(actualQuickInfoDocumentation, expectedDocumentation, this.messageAtLastKnownMarker("quick info doc comment"));
836837
}
837838
} else {
838839
if (expectedText !== undefined) {
839840
assert.equal(actualQuickInfoText, expectedText, this.messageAtLastKnownMarker("quick info text"));
840841
}
842+
// TODO: should be '==='?
841843
if (expectedDocumentation != undefined) {
842844
assert.equal(actualQuickInfoDocumentation, expectedDocumentation, assertionMessage("quick info doc"));
843845
}
@@ -1820,7 +1822,7 @@ module FourSlash {
18201822
}
18211823

18221824
private verifyProjectInfo(expected: string[]) {
1823-
if (this.testType == FourSlashTestType.Server) {
1825+
if (this.testType === FourSlashTestType.Server) {
18241826
let actual = (<ts.server.SessionClient>this.languageService).getProjectInfo(
18251827
this.activeFile.fileName,
18261828
/* needFileNameList */ true
@@ -1937,7 +1939,7 @@ module FourSlash {
19371939
}
19381940
}
19391941

1940-
if (expected != actual) {
1942+
if (expected !== actual) {
19411943
this.raiseError('verifyNavigationItemsCount failed - found: ' + actual + ' navigation items, expected: ' + expected + '.');
19421944
}
19431945
}
@@ -1984,7 +1986,7 @@ module FourSlash {
19841986
var items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
19851987
var actual = this.getNavigationBarItemsCount(items);
19861988

1987-
if (expected != actual) {
1989+
if (expected !== actual) {
19881990
this.raiseError('verifyGetScriptLexicalStructureListCount failed - found: ' + actual + ' navigation items, expected: ' + expected + '.');
19891991
}
19901992
}
@@ -2402,6 +2404,7 @@ module FourSlash {
24022404
globalOptions[match[1]] = match[2];
24032405
}
24042406
}
2407+
// TODO: should be '==='?
24052408
} else if (line == '' || lineLength === 0) {
24062409
// Previously blank lines between fourslash content caused it to be considered as 2 files,
24072410
// Remove this behavior since it just causes errors now

src/harness/projectsRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ProjectRunner extends RunnerBase {
110110
else if (url.indexOf(diskProjectPath) === 0) {
111111
// Replace the disk specific path into the project root path
112112
url = url.substr(diskProjectPath.length);
113+
// TODO: should be '!=='?
113114
if (url.charCodeAt(0) != ts.CharacterCodes.slash) {
114115
url = "/" + url;
115116
}
@@ -240,7 +241,7 @@ class ProjectRunner extends RunnerBase {
240241
if (Harness.Compiler.isJS(fileName)) {
241242
// Make sure if there is URl we have it cleaned up
242243
var indexOfSourceMapUrl = data.lastIndexOf("//# sourceMappingURL=");
243-
if (indexOfSourceMapUrl != -1) {
244+
if (indexOfSourceMapUrl !== -1) {
244245
data = data.substring(0, indexOfSourceMapUrl + 21) + cleanProjectUrl(data.substring(indexOfSourceMapUrl + 21));
245246
}
246247
}

src/harness/sourceMapRecorder.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module Harness.SourceMapRecoder {
4646
}
4747

4848
function isSourceMappingSegmentEnd() {
49-
if (decodingIndex == sourceMapMappings.length) {
49+
if (decodingIndex === sourceMapMappings.length) {
5050
return true;
5151
}
5252

@@ -95,15 +95,15 @@ module Harness.SourceMapRecoder {
9595
var currentByte = base64FormatDecode();
9696

9797
// If msb is set, we still have more bits to continue
98-
moreDigits = (currentByte & 32) != 0;
98+
moreDigits = (currentByte & 32) !== 0;
9999

100100
// least significant 5 bits are the next msbs in the final value.
101101
value = value | ((currentByte & 31) << shiftCount);
102102
shiftCount += 5;
103103
}
104104

105105
// Least significant bit if 1 represents negative and rest of the msb is actual absolute value
106-
if ((value & 1) == 0) {
106+
if ((value & 1) === 0) {
107107
// + number
108108
value = value >> 1;
109109
}
@@ -182,7 +182,7 @@ module Harness.SourceMapRecoder {
182182
}
183183
}
184184
// Dont support reading mappings that dont have information about original source and its line numbers
185-
if (createErrorIfCondition(!isSourceMappingSegmentEnd(), "Unsupported Error Format: There are more entries after " + (decodeOfEncodedMapping.nameIndex == -1 ? "sourceColumn" : "nameIndex"))) {
185+
if (createErrorIfCondition(!isSourceMappingSegmentEnd(), "Unsupported Error Format: There are more entries after " + (decodeOfEncodedMapping.nameIndex === -1 ? "sourceColumn" : "nameIndex"))) {
186186
return { error: errorDecodeOfEncodedMapping, sourceMapSpan: decodeOfEncodedMapping };
187187
}
188188

@@ -249,7 +249,7 @@ module Harness.SourceMapRecoder {
249249
mapString += " name (" + sourceMapNames[mapEntry.nameIndex] + ")";
250250
}
251251
else {
252-
if (mapEntry.nameIndex != -1 || getAbsentNameIndex) {
252+
if (mapEntry.nameIndex !== -1 || getAbsentNameIndex) {
253253
mapString += " nameIndex (" + mapEntry.nameIndex + ")";
254254
}
255255
}
@@ -262,12 +262,12 @@ module Harness.SourceMapRecoder {
262262
var decodeResult = SourceMapDecoder.decodeNextEncodedSourceMapSpan();
263263
var decodedErrors: string[];
264264
if (decodeResult.error
265-
|| decodeResult.sourceMapSpan.emittedLine != sourceMapSpan.emittedLine
266-
|| decodeResult.sourceMapSpan.emittedColumn != sourceMapSpan.emittedColumn
267-
|| decodeResult.sourceMapSpan.sourceLine != sourceMapSpan.sourceLine
268-
|| decodeResult.sourceMapSpan.sourceColumn != sourceMapSpan.sourceColumn
269-
|| decodeResult.sourceMapSpan.sourceIndex != sourceMapSpan.sourceIndex
270-
|| decodeResult.sourceMapSpan.nameIndex != sourceMapSpan.nameIndex) {
265+
|| decodeResult.sourceMapSpan.emittedLine !== sourceMapSpan.emittedLine
266+
|| decodeResult.sourceMapSpan.emittedColumn !== sourceMapSpan.emittedColumn
267+
|| decodeResult.sourceMapSpan.sourceLine !== sourceMapSpan.sourceLine
268+
|| decodeResult.sourceMapSpan.sourceColumn !== sourceMapSpan.sourceColumn
269+
|| decodeResult.sourceMapSpan.sourceIndex !== sourceMapSpan.sourceIndex
270+
|| decodeResult.sourceMapSpan.nameIndex !== sourceMapSpan.nameIndex) {
271271
if (decodeResult.error) {
272272
decodedErrors = ["!!^^ !!^^ There was decoding error in the sourcemap at this location: " + decodeResult.error];
273273
}
@@ -288,7 +288,7 @@ module Harness.SourceMapRecoder {
288288
}
289289

290290
export function recordNewSourceFileSpan(sourceMapSpan: ts.SourceMapSpan, newSourceFileCode: string) {
291-
assert.isTrue(spansOnSingleLine.length == 0 || spansOnSingleLine[0].sourceMapSpan.emittedLine !== sourceMapSpan.emittedLine, "new file source map span should be on new line. We currently handle only that scenario");
291+
assert.isTrue(spansOnSingleLine.length === 0 || spansOnSingleLine[0].sourceMapSpan.emittedLine !== sourceMapSpan.emittedLine, "new file source map span should be on new line. We currently handle only that scenario");
292292
recordSourceMapSpan(sourceMapSpan);
293293

294294
assert.isTrue(spansOnSingleLine.length === 1);
@@ -395,9 +395,9 @@ module Harness.SourceMapRecoder {
395395

396396
var tsCodeLineMap = ts.computeLineStarts(sourceText);
397397
for (var i = 0; i < tsCodeLineMap.length; i++) {
398-
writeSourceMapIndent(prevEmittedCol, i == 0 ? markerIds[index] : " >");
398+
writeSourceMapIndent(prevEmittedCol, i === 0 ? markerIds[index] : " >");
399399
sourceMapRecoder.Write(getTextOfLine(i, tsCodeLineMap, sourceText));
400-
if (i == tsCodeLineMap.length - 1) {
400+
if (i === tsCodeLineMap.length - 1) {
401401
sourceMapRecoder.WriteLine("");
402402
}
403403
}
@@ -447,7 +447,7 @@ module Harness.SourceMapRecoder {
447447
for (var j = 0; j < sourceMapData.sourceMapDecodedMappings.length; j++) {
448448
var decodedSourceMapping = sourceMapData.sourceMapDecodedMappings[j];
449449
var currentSourceFile = program.getSourceFile(sourceMapData.inputSourceFileNames[decodedSourceMapping.sourceIndex]);
450-
if (currentSourceFile != prevSourceFile) {
450+
if (currentSourceFile !== prevSourceFile) {
451451
SourceMapSpanWriter.recordNewSourceFileSpan(decodedSourceMapping, currentSourceFile.text);
452452
prevSourceFile = currentSourceFile;
453453
}

src/server/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ namespace ts.server {
219219

220220
var request = this.processRequest<protocol.CompletionDetailsRequest>(CommandNames.CompletionDetails, args);
221221
var response = this.processResponse<protocol.CompletionDetailsResponse>(request);
222-
Debug.assert(response.body.length == 1, "Unexpected length of completion details response body.");
222+
Debug.assert(response.body.length === 1, "Unexpected length of completion details response body.");
223223
return response.body[0];
224224
}
225225

@@ -429,8 +429,8 @@ namespace ts.server {
429429
if (!this.lastRenameEntry ||
430430
this.lastRenameEntry.fileName !== fileName ||
431431
this.lastRenameEntry.position !== position ||
432-
this.lastRenameEntry.findInStrings != findInStrings ||
433-
this.lastRenameEntry.findInComments != findInComments) {
432+
this.lastRenameEntry.findInStrings !== findInStrings ||
433+
this.lastRenameEntry.findInComments !== findInComments) {
434434
this.getRenameInfo(fileName, position, findInStrings, findInComments);
435435
}
436436

0 commit comments

Comments
 (0)