(n *ast.Node)
| 189 | } |
| 190 | |
| 191 | func (s *formattingScanner) readTokenInfo(n *ast.Node) tokenInfo { |
| 192 | debug.Assert(s.isOnToken()) |
| 193 | |
| 194 | // normally scanner returns the smallest available token |
| 195 | // check the kind of context node to determine if scanner should have more greedy behavior and consume more text. |
| 196 | |
| 197 | var expectedScanAction scanAction |
| 198 | if shouldRescanGreaterThanToken(n) { |
| 199 | expectedScanAction = actionRescanGreaterThanToken |
| 200 | } else if shouldRescanSlashToken(n) { |
| 201 | expectedScanAction = actionRescanSlashToken |
| 202 | } else if shouldRescanTemplateToken(n) { |
| 203 | expectedScanAction = actionRescanTemplateToken |
| 204 | } else if shouldRescanJsxIdentifier(n) { |
| 205 | expectedScanAction = actionRescanJsxIdentifier |
| 206 | } else if s.shouldRescanJsxText(n) { |
| 207 | expectedScanAction = actionRescanJsxText |
| 208 | } else if shouldRescanJsxAttributeValue(n) { |
| 209 | expectedScanAction = actionRescanJsxAttributeValue |
| 210 | } else { |
| 211 | expectedScanAction = actionScan |
| 212 | } |
| 213 | |
| 214 | if s.hasLastTokenInfo && expectedScanAction == s.lastScanAction { |
| 215 | // readTokenInfo was called before with the same expected scan action. |
| 216 | // No need to re-scan text, return existing 'lastTokenInfo' |
| 217 | // it is ok to call fixTokenKind here since it does not affect |
| 218 | // what portion of text is consumed. In contrast rescanning can change it, |
| 219 | // i.e. for '>=' when originally scanner eats just one character |
| 220 | // and rescanning forces it to consume more. |
| 221 | s.lastTokenInfo = fixTokenKind(s.lastTokenInfo, n) |
| 222 | return s.lastTokenInfo |
| 223 | } |
| 224 | |
| 225 | if s.s.TokenFullStart() != s.savedPos { |
| 226 | // readTokenInfo was called before but scan action differs - rescan text |
| 227 | s.s.ResetTokenState(s.savedPos) |
| 228 | s.s.Scan() |
| 229 | } |
| 230 | |
| 231 | currentToken := s.getNextToken(n, expectedScanAction) |
| 232 | |
| 233 | token := NewTextRangeWithKind( |
| 234 | s.s.TokenFullStart(), |
| 235 | s.s.TokenEnd(), |
| 236 | currentToken, |
| 237 | ) |
| 238 | |
| 239 | // consume trailing trivia |
| 240 | s.trailingTrivia = nil |
| 241 | for s.s.TokenFullStart() < s.endPos { |
| 242 | currentToken = s.s.Scan() |
| 243 | if !ast.IsTrivia(currentToken) { |
| 244 | break |
| 245 | } |
| 246 | trivia := NewTextRangeWithKind( |
| 247 | s.s.TokenFullStart(), |
| 248 | s.s.TokenEnd(), |
no test coverage detected