Skip to content

Commit c3a88d3

Browse files
committed
code cleanup: replace nulls with undefined
1 parent ace99ad commit c3a88d3

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

src/services/formatting/new/formattingContext.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,32 @@ module ts.formatting {
4545
this.nextTokenParent = nextTokenParent;
4646
this.contextNode = commonParent;
4747

48-
this.contextNodeAllOnSameLine = null;
49-
this.nextNodeAllOnSameLine = null;
50-
this.tokensAreOnSameLine = null;
51-
this.contextNodeBlockIsOnOneLine = null;
52-
this.nextNodeBlockIsOnOneLine = null;
48+
// drop cached results
49+
this.contextNodeAllOnSameLine = undefined;
50+
this.nextNodeAllOnSameLine = undefined;
51+
this.tokensAreOnSameLine = undefined;
52+
this.contextNodeBlockIsOnOneLine = undefined;
53+
this.nextNodeBlockIsOnOneLine = undefined;
5354
}
5455

5556
public ContextNodeAllOnSameLine(): boolean {
56-
if (this.contextNodeAllOnSameLine === null) {
57+
if (this.contextNodeAllOnSameLine === undefined) {
5758
this.contextNodeAllOnSameLine = this.NodeIsOnOneLine(this.contextNode);
5859
}
5960

6061
return this.contextNodeAllOnSameLine;
6162
}
6263

6364
public NextNodeAllOnSameLine(): boolean {
64-
if (this.nextNodeAllOnSameLine === null) {
65+
if (this.nextNodeAllOnSameLine === undefined) {
6566
this.nextNodeAllOnSameLine = this.NodeIsOnOneLine(this.nextTokenParent);
6667
}
6768

6869
return this.nextNodeAllOnSameLine;
6970
}
7071

7172
public TokensAreOnSameLine(): boolean {
72-
if (this.tokensAreOnSameLine === null) {
73-
74-
//var startLine = this.snapshot.getLineNumberFromPosition(this.currentTokenSpan.token.pos);
75-
//var endLine = this.snapshot.getLineNumberFromPosition(this.nextTokenSpan.token.pos);
76-
73+
if (this.tokensAreOnSameLine === undefined) {
7774
var startLine = this.sourceFile.getLineAndCharacterFromPosition(this.currentTokenSpan.pos).line;
7875
var endLine = this.sourceFile.getLineAndCharacterFromPosition(this.nextTokenSpan.pos).line;
7976
this.tokensAreOnSameLine = (startLine == endLine);
@@ -83,15 +80,15 @@ module ts.formatting {
8380
}
8481

8582
public ContextNodeBlockIsOnOneLine() {
86-
if (this.contextNodeBlockIsOnOneLine === null) {
83+
if (this.contextNodeBlockIsOnOneLine === undefined) {
8784
this.contextNodeBlockIsOnOneLine = this.BlockIsOnOneLine(this.contextNode);
8885
}
8986

9087
return this.contextNodeBlockIsOnOneLine;
9188
}
9289

9390
public NextNodeBlockIsOnOneLine() {
94-
if (this.nextNodeBlockIsOnOneLine === null) {
91+
if (this.nextNodeBlockIsOnOneLine === undefined) {
9592
this.nextNodeBlockIsOnOneLine = this.BlockIsOnOneLine(this.nextTokenParent);
9693
}
9794

@@ -101,14 +98,9 @@ module ts.formatting {
10198
private NodeIsOnOneLine(node: Node): boolean {
10299
var startLine = this.sourceFile.getLineAndCharacterFromPosition(node.getStart(this.sourceFile)).line;
103100
var endLine = this.sourceFile.getLineAndCharacterFromPosition(node.getEnd()).line;
104-
//var startLine = this.snapshot.getLineNumberFromPosition(node.start());
105-
//var endLine = this.snapshot.getLineNumberFromPosition(node.end());
106-
107101
return startLine == endLine;
108102
}
109103

110-
// Now we know we have a block (or a fake block represented by some other kind of node with an open and close brace as children).
111-
// IMPORTANT!!! This relies on the invariant that IsBlockContext must return true ONLY for nodes with open and close braces as immediate children
112104
private BlockIsOnOneLine(node: Node): boolean {
113105
var openBrace = findChildOfKind(node, SyntaxKind.OpenBraceToken, this.sourceFile);
114106
var closeBrace = findChildOfKind(node, SyntaxKind.CloseBraceToken, this.sourceFile);
@@ -117,12 +109,7 @@ module ts.formatting {
117109
var endLine = this.sourceFile.getLineAndCharacterFromPosition(closeBrace.getStart(this.sourceFile)).line;
118110
return startLine === endLine;
119111
}
120-
121-
//var block = <BlockSyntax>node.node();
122-
123-
//// Now check if they are on the same line
124-
//return this.snapshot.getLineNumberFromPosition(end(block.openBraceToken)) ===
125-
// this.snapshot.getLineNumberFromPosition(start(block.closeBraceToken));
112+
return false;
126113
}
127114
}
128115
}

0 commit comments

Comments
 (0)