(tokenStart: number)
| 705 | } |
| 706 | |
| 707 | private scanRegex(tokenStart: number): Token { |
| 708 | this.advance(); |
| 709 | const textStart = this.index; |
| 710 | let inEscape = false; |
| 711 | let inCharacterClass = false; |
| 712 | |
| 713 | while (true) { |
| 714 | const peek = this.peek; |
| 715 | |
| 716 | if (peek === chars.$EOF) { |
| 717 | return this.error('Unterminated regular expression', 0); |
| 718 | } |
| 719 | |
| 720 | if (inEscape) { |
| 721 | inEscape = false; |
| 722 | } else if (peek === chars.$BACKSLASH) { |
| 723 | inEscape = true; |
| 724 | } else if (peek === chars.$LBRACKET) { |
| 725 | inCharacterClass = true; |
| 726 | } else if (peek === chars.$RBRACKET) { |
| 727 | inCharacterClass = false; |
| 728 | } else if (peek === chars.$SLASH && !inCharacterClass) { |
| 729 | break; |
| 730 | } |
| 731 | this.advance(); |
| 732 | } |
| 733 | |
| 734 | // Note that we want the text without the slashes, |
| 735 | // but we still want the slashes to be part of the span. |
| 736 | const value = this.input.substring(textStart, this.index); |
| 737 | this.advance(); |
| 738 | const bodyToken = newRegExpBodyToken(tokenStart, this.index, value); |
| 739 | const flagsToken = this.scanRegexFlags(this.index); |
| 740 | |
| 741 | if (flagsToken !== null) { |
| 742 | this.tokens.push(bodyToken); |
| 743 | return flagsToken; |
| 744 | } |
| 745 | |
| 746 | return bodyToken; |
| 747 | } |
| 748 | |
| 749 | private scanRegexFlags(start: number): Token | null { |
| 750 | if (!chars.isAsciiLetter(this.peek)) { |
no test coverage detected