Skip to content

Commit d9178cc

Browse files
authored
Port "Fixed crash when adding unreachable code diagnostic in situations with missing nodes" (#2416)
1 parent 2437fa4 commit d9178cc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

internal/checker/checker.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,8 +2302,8 @@ func (c *Checker) checkSourceElementUnreachable(node *ast.Node) bool {
23022302

23032303
sourceFile := ast.GetSourceFileOfNode(node)
23042304

2305-
start := node.Pos()
2306-
end := node.End()
2305+
startNode := node
2306+
endNode := node
23072307

23082308
parent := node.Parent
23092309
if parent.CanHaveStatements() {
@@ -2333,14 +2333,14 @@ func (c *Checker) checkSourceElementUnreachable(node *ast.Node) bool {
23332333
c.reportedUnreachableNodes.Add(nextNode)
23342334
}
23352335

2336-
start = statements[first].Pos()
2337-
end = statements[last].End()
2336+
startNode = statements[first]
2337+
endNode = statements[last]
23382338
}
23392339
}
23402340

2341-
start = scanner.SkipTrivia(sourceFile.Text(), start)
2341+
start := scanner.GetTokenPosOfNode(startNode, sourceFile, false /*includeJSDoc*/)
23422342

2343-
diagnostic := ast.NewDiagnostic(sourceFile, core.NewTextRange(start, end), diagnostics.Unreachable_code_detected)
2343+
diagnostic := ast.NewDiagnostic(sourceFile, core.NewTextRange(start, endNode.End()), diagnostics.Unreachable_code_detected)
23442344
c.addErrorOrSuggestion(c.compilerOptions.AllowUnreachableCode == core.TSFalse, diagnostic)
23452345

23462346
return true

0 commit comments

Comments
 (0)