@@ -177,13 +177,19 @@ func deriveActualIndentationFromList(list *ast.NodeList, index int, sourceFile *
177177 debug .Assert (list != nil && index >= 0 && index < len (list .Nodes ))
178178
179179 node := list .Nodes [index ]
180+ if node == nil {
181+ return - 1
182+ }
180183
181184 // walk toward the start of the list starting from current node and check if the line is the same for all items.
182185 // if end line for item [i - 1] differs from the start line for item [i] - find column of the first non-whitespace character on the line of item [i]
183186
184187 line , char := getStartLineAndCharacterForNode (node , sourceFile )
185188
186189 for i := index ; i >= 0 ; i -- {
190+ if list .Nodes [i ] == nil {
191+ continue
192+ }
187193 if list .Nodes [i ].Kind == ast .KindCommaToken {
188194 continue
189195 }
@@ -242,9 +248,6 @@ func findFirstNonWhitespaceCharacterAndColumn(startPos int, endPos int, sourceFi
242248func childStartsOnTheSameLineWithElseInIfStatement (parent * ast.Node , child * ast.Node , childStartLine int , sourceFile * ast.SourceFile ) bool {
243249 if parent .Kind == ast .KindIfStatement && parent .AsIfStatement ().ElseStatement == child {
244250 elseKeyword := astnav .FindPrecedingToken (sourceFile , child .Pos ())
245- if elseKeyword == nil {
246- return false
247- }
248251 debug .AssertIsDefined (elseKeyword )
249252 elseKeywordStartLine , _ := getStartLineAndCharacterForNode (elseKeyword , sourceFile )
250253 return elseKeywordStartLine == childStartLine
@@ -253,9 +256,6 @@ func childStartsOnTheSameLineWithElseInIfStatement(parent *ast.Node, child *ast.
253256}
254257
255258func getStartLineAndCharacterForNode (n * ast.Node , sourceFile * ast.SourceFile ) (line int , character int ) {
256- if n == nil {
257- return 0 , 0
258- }
259259 return scanner .GetECMALineAndCharacterOfPosition (sourceFile , scanner .GetTokenPosOfNode (n , sourceFile , false ))
260260}
261261
@@ -536,12 +536,8 @@ func childIsUnindentedBranchOfConditionalExpression(parent *ast.Node, child *ast
536536 // ? 1 : ( L1: whenTrue indented because it's on a new line
537537 // 0 L2: indented two stops, one because whenTrue was indented
538538 // ); and one because of the parentheses spanning multiple lines
539- whenTrue := parent .AsConditionalExpression ().WhenTrue
540- if whenTrue == nil {
541- return false
542- }
543- trueStartLine , _ := getStartLineAndCharacterForNode (whenTrue , sourceFile )
544- trueEndLine , _ := scanner .GetECMALineAndCharacterOfPosition (sourceFile , whenTrue .End ())
539+ trueStartLine , _ := getStartLineAndCharacterForNode (parent .AsConditionalExpression ().WhenTrue , sourceFile )
540+ trueEndLine , _ := scanner .GetECMALineAndCharacterOfPosition (sourceFile , parent .AsConditionalExpression ().WhenTrue .End ())
545541 return conditionEndLine == trueStartLine && trueEndLine == childStartLine
546542 }
547543 }
0 commit comments