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

Method ScanJsxIdentifier

internal/scanner/scanner.go:1321–1346  ·  view source on GitHub ↗

Scans a JSX identifier; these differ from normal identifiers in that they allow dashes

()

Source from the content-addressed store, hash-verified

1319
1320// Scans a JSX identifier; these differ from normal identifiers in that they allow dashes
1321func (s *Scanner) ScanJsxIdentifier() ast.Kind {
1322 if tokenIsIdentifierOrKeyword(s.token) {
1323 // An identifier or keyword has already been parsed - check for a `-` or a single instance of `:` and then append it and
1324 // everything after it to the token
1325 // Do note that this means that `scanJsxIdentifier` effectively _mutates_ the visible token without advancing to a new token
1326 // Any caller should be expecting this behavior and should only read the pos or token value after calling it.
1327 for {
1328 ch := s.char()
1329 if ch < 0 {
1330 break
1331 }
1332 if ch == '-' {
1333 s.tokenValue += "-"
1334 s.pos++
1335 continue
1336 }
1337 oldPos := s.pos
1338 s.tokenValue += s.scanIdentifierParts() // reuse `scanIdentifierParts` so unicode escapes are handled
1339 if s.pos == oldPos {
1340 break
1341 }
1342 }
1343 s.token = GetIdentifierToken(s.tokenValue)
1344 }
1345 return s.token
1346}
1347
1348func (s *Scanner) ScanJsxAttributeValue() ast.Kind {
1349 s.fullStartPos = s.pos

Callers 2

scanJsxIdentifierMethod · 0.80
getNextTokenMethod · 0.80

Calls 4

charMethod · 0.95
scanIdentifierPartsMethod · 0.95
GetIdentifierTokenFunction · 0.85

Tested by

no test coverage detected