(jsxAttributeString bool)
| 1584 | } |
| 1585 | |
| 1586 | func (s *Scanner) scanString(jsxAttributeString bool) string { |
| 1587 | quote := s.char() |
| 1588 | if quote == '\'' { |
| 1589 | s.tokenFlags |= ast.TokenFlagsSingleQuote |
| 1590 | } |
| 1591 | s.pos++ |
| 1592 | // Fast path for simple strings without escape sequences. |
| 1593 | strLen := strings.IndexByte(s.text[s.pos:], byte(quote)) |
| 1594 | if strLen == 0 { |
| 1595 | s.pos++ |
| 1596 | return "" |
| 1597 | } |
| 1598 | if strLen > 0 { |
| 1599 | str := s.text[s.pos : s.pos+strLen] |
| 1600 | if jsxAttributeString || |
| 1601 | strings.IndexByte(str, '\\') < 0 && strings.IndexByte(str, '\r') < 0 && strings.IndexByte(str, '\n') < 0 { |
| 1602 | s.pos += strLen + 1 |
| 1603 | return str |
| 1604 | } |
| 1605 | } |
| 1606 | var sb strings.Builder |
| 1607 | start := s.pos |
| 1608 | for { |
| 1609 | ch := s.char() |
| 1610 | if ch < 0 { |
| 1611 | sb.WriteString(s.text[start:s.pos]) |
| 1612 | s.tokenFlags |= ast.TokenFlagsUnterminated |
| 1613 | s.error(diagnostics.Unterminated_string_literal) |
| 1614 | break |
| 1615 | } |
| 1616 | if ch == quote { |
| 1617 | sb.WriteString(s.text[start:s.pos]) |
| 1618 | s.pos++ |
| 1619 | break |
| 1620 | } |
| 1621 | if ch == '\\' && !jsxAttributeString { |
| 1622 | sb.WriteString(s.text[start:s.pos]) |
| 1623 | sb.WriteString(s.scanEscapeSequence(EscapeSequenceScanningFlagsString | EscapeSequenceScanningFlagsReportErrors)) |
| 1624 | start = s.pos |
| 1625 | continue |
| 1626 | } |
| 1627 | if (ch == '\n' || ch == '\r') && !jsxAttributeString { |
| 1628 | sb.WriteString(s.text[start:s.pos]) |
| 1629 | s.tokenFlags |= ast.TokenFlagsUnterminated |
| 1630 | s.error(diagnostics.Unterminated_string_literal) |
| 1631 | break |
| 1632 | } |
| 1633 | s.pos++ |
| 1634 | } |
| 1635 | return sb.String() |
| 1636 | } |
| 1637 | |
| 1638 | func (s *Scanner) scanTemplateAndSetTokenValue(shouldEmitInvalidEscapeError bool) ast.Kind { |
| 1639 | startedWithBacktick := s.char() == '`' |
no test coverage detected