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

Method ScanJsxTokenEx

internal/scanner/scanner.go:1253–1318  ·  view source on GitHub ↗
(allowMultilineJsxText bool)

Source from the content-addressed store, hash-verified

1251}
1252
1253func (s *Scanner) ScanJsxTokenEx(allowMultilineJsxText bool) ast.Kind {
1254 s.fullStartPos = s.pos
1255 s.tokenStart = s.pos
1256 ch := s.char()
1257 switch {
1258 case ch < 0:
1259 s.token = ast.KindEndOfFile
1260 case ch == '<':
1261 if s.charAt(1) == '/' {
1262 s.pos += 2
1263 s.token = ast.KindLessThanSlashToken
1264 } else {
1265 s.pos++
1266 s.token = ast.KindLessThanToken
1267 }
1268 case ch == '{':
1269 s.pos++
1270 s.token = ast.KindOpenBraceToken
1271 default:
1272 // First non-whitespace character on this line.
1273 firstNonWhitespace := 0
1274 // These initial values are special because the first line is:
1275 // firstNonWhitespace = 0 to indicate that we want leading whitespace
1276 for {
1277 ch, size := s.charAndSize()
1278 if size == 0 || ch == '{' {
1279 break
1280 }
1281 if ch == '<' {
1282 if isConflictMarkerTrivia(s.text, s.pos) {
1283 s.pos = scanConflictMarkerTrivia(s.text, s.pos, s.errorAt)
1284 s.token = ast.KindConflictMarkerTrivia
1285 return s.token
1286 }
1287 break
1288 }
1289 if ch == '>' {
1290 s.errorAt(diagnostics.Unexpected_token_Did_you_mean_or_gt, s.pos, 1)
1291 } else if ch == '}' {
1292 s.errorAt(diagnostics.Unexpected_token_Did_you_mean_or_rbrace, s.pos, 1)
1293 }
1294 // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
1295 // i.e (- : whitespace)
1296 // <div>----
1297 // </div> becomes <div></div>
1298 //
1299 // <div>----</div> becomes <div>----</div>
1300 if stringutil.IsLineBreak(ch) && firstNonWhitespace == 0 {
1301 firstNonWhitespace = -1
1302 } else if !allowMultilineJsxText && stringutil.IsLineBreak(ch) && firstNonWhitespace > 0 {
1303 // Stop JsxText on each line during formatting. This allows the formatter to
1304 // indent each line correctly.
1305 break
1306 } else if !stringutil.IsWhiteSpaceLike(ch) {
1307 firstNonWhitespace = s.pos
1308 }
1309 s.pos += size
1310 }

Callers 2

ReScanJsxTokenMethod · 0.95
ScanJsxTokenMethod · 0.95

Calls 8

charMethod · 0.95
charAtMethod · 0.95
charAndSizeMethod · 0.95
errorAtMethod · 0.95
IsLineBreakFunction · 0.92
IsWhiteSpaceLikeFunction · 0.92
isConflictMarkerTriviaFunction · 0.70
scanConflictMarkerTriviaFunction · 0.70

Tested by

no test coverage detected