MCPcopy Create free account
hub / github.com/angular/angular / isStartOfRegex

Method isStartOfRegex

packages/compiler/src/expression_parser/lexer.ts:672–705  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

670 }
671
672 private isStartOfRegex(): boolean {
673 if (this.tokens.length === 0) {
674 return true;
675 }
676
677 const prevToken = this.tokens[this.tokens.length - 1];
678
679 // If a slash is preceded by a `!` operator, we need to distinguish whether it's a
680 // negation or a non-null assertion. Regexes can only be precded by negations.
681 if (prevToken.isOperator('!')) {
682 const beforePrevToken = this.tokens.length > 1 ? this.tokens[this.tokens.length - 2] : null;
683 const isNegation =
684 beforePrevToken === null ||
685 (beforePrevToken.type !== TokenType.Identifier &&
686 !beforePrevToken.isCharacter(chars.$RPAREN) &&
687 !beforePrevToken.isCharacter(chars.$RBRACKET));
688
689 return isNegation;
690 }
691
692 // Only consider the slash a regex if it's preceded either by:
693 // - Any operator, aside from `!` which is special-cased above.
694 // - Opening paren (e.g. `(/a/)`).
695 // - Opening bracket (e.g. `[/a/]`).
696 // - A comma (e.g. `[1, /a/]`).
697 // - A colon (e.g. `{foo: /a/}`).
698 return (
699 prevToken.type === TokenType.Operator ||
700 prevToken.isCharacter(chars.$LPAREN) ||
701 prevToken.isCharacter(chars.$LBRACKET) ||
702 prevToken.isCharacter(chars.$COMMA) ||
703 prevToken.isCharacter(chars.$COLON)
704 );
705 }
706
707 private scanRegex(tokenStart: number): Token {
708 this.advance();

Callers 1

scanTokenMethod · 0.95

Calls 2

isOperatorMethod · 0.80
isCharacterMethod · 0.80

Tested by

no test coverage detected