Scan a dot in import identifiers. Matches '.' normally, but when the dot is followed by a newline and then the 'import' keyword, produces an AUTOMATIC_SEMICOLON (zero-width, before the dot) instead. This cleanly terminates the current import_header, preventing malformed imports (e.g. trailing dots) from bleeding into subsequent valid imports.
| 1440 | // terminates the current import_header, preventing malformed imports |
| 1441 | // (e.g. trailing dots) from bleeding into subsequent valid imports. |
| 1442 | static bool scan_import_dot(TSLexer *lexer) { |
| 1443 | if (lexer->lookahead != '.') return false; |
| 1444 | |
| 1445 | // Mark end BEFORE consuming the dot — this is where ASI would go |
| 1446 | lexer->mark_end(lexer); |
| 1447 | |
| 1448 | advance(lexer); |
| 1449 | |
| 1450 | // Peek ahead: skip horizontal whitespace, check for newline |
| 1451 | bool found_newline = false; |
| 1452 | while (iswspace(lexer->lookahead)) { |
| 1453 | if (lexer->lookahead == '\n' || lexer->lookahead == '\r') { |
| 1454 | found_newline = true; |
| 1455 | } |
| 1456 | skip(lexer); |
| 1457 | } |
| 1458 | |
| 1459 | if (found_newline && lexer->lookahead == 'i' && |
| 1460 | scan_for_word(lexer, "mport", 5)) { |
| 1461 | // Trailing dot followed by 'import' on next line — produce ASI |
| 1462 | // instead of the dot. mark_end was set before the dot, so the |
| 1463 | // semicolon is zero-width at that position. |
| 1464 | lexer->result_symbol = AUTOMATIC_SEMICOLON; |
| 1465 | return true; |
| 1466 | } |
| 1467 | |
| 1468 | // Normal dot — include it in the token |
| 1469 | lexer->result_symbol = IMPORT_DOT; |
| 1470 | lexer->mark_end(lexer); |
| 1471 | return true; |
| 1472 | } |
| 1473 | |
| 1474 | static bool scan_token(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) { |
| 1475 | // Pending work takes priority over constructor, ASI, string and |
no test coverage detected