MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getScanStartPosition

Function getScanStartPosition

internal/format/span.go:51–71  ·  view source on GitHub ↗

** * Start of the original range might fall inside the comment - scanner will not yield appropriate results * This function will look for token that is located before the start of target range * and return its end as start position for the scanner. */

(enclosingNode *ast.Node, originalRange core.TextRange, sourceFile *ast.SourceFile)

Source from the content-addressed store, hash-verified

49 * and return its end as start position for the scanner.
50 */
51func getScanStartPosition(enclosingNode *ast.Node, originalRange core.TextRange, sourceFile *ast.SourceFile) int {
52 adjusted := withTokenStart(enclosingNode, sourceFile)
53 start := adjusted.Pos()
54 if start == originalRange.Pos() && enclosingNode.End() == originalRange.End() {
55 return start
56 }
57
58 precedingToken := astnav.FindPrecedingToken(sourceFile, originalRange.Pos())
59 if precedingToken == nil {
60 // no preceding token found - start from the beginning of enclosing node
61 return enclosingNode.Pos()
62 }
63
64 // preceding token ends after the start of original range (i.e when originalRange.pos falls in the middle of literal)
65 // start from the beginning of enclosingNode to handle the entire 'originalRange'
66 if precedingToken.End() >= originalRange.Pos() {
67 return enclosingNode.Pos()
68 }
69
70 return precedingToken.End()
71}
72
73/*
74 * For cases like

Callers 1

FormatSpanFunction · 0.85

Calls 4

FindPrecedingTokenFunction · 0.92
withTokenStartFunction · 0.85
PosMethod · 0.65
EndMethod · 0.65

Tested by

no test coverage detected