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

Method parsePipe

packages/compiler/src/expression_parser/parser.ts:839–892  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

837 }
838
839 private parsePipe(): AST {
840 const start = this.inputIndex;
841 let result = this.parseExpression();
842 if (this.consumeOptionalOperator('|')) {
843 if (this.parseFlags & ParseFlags.Action) {
844 this.error(`Cannot have a pipe in an action expression`);
845 }
846
847 do {
848 const nameStart = this.inputIndex;
849 let nameId = this.expectIdentifierOrKeyword();
850 let nameSpan: AbsoluteSourceSpan;
851 let fullSpanEnd: number | undefined = undefined;
852 if (nameId !== null) {
853 nameSpan = this.sourceSpan(nameStart);
854 } else {
855 // No valid identifier was found, so we'll assume an empty pipe name ('').
856 nameId = '';
857
858 // However, there may have been whitespace present between the pipe character and the next
859 // token in the sequence (or the end of input). We want to track this whitespace so that
860 // the `BindingPipe` we produce covers not just the pipe character, but any trailing
861 // whitespace beyond it. Another way of thinking about this is that the zero-length name
862 // is assumed to be at the end of any whitespace beyond the pipe character.
863 //
864 // Therefore, we push the end of the `ParseSpan` for this pipe all the way up to the
865 // beginning of the next token, or until the end of input if the next token is EOF.
866 fullSpanEnd = this.next.index !== -1 ? this.next.index : this.input.length + this.offset;
867
868 // The `nameSpan` for an empty pipe name is zero-length at the end of any whitespace
869 // beyond the pipe character.
870 nameSpan = new ParseSpan(fullSpanEnd, fullSpanEnd).toAbsolute(this.absoluteOffset);
871 }
872
873 const args: AST[] = [];
874 while (this.consumeOptionalCharacter(chars.$COLON)) {
875 args.push(this.parseExpression());
876
877 // If there are additional expressions beyond the name, then the artificial end for the
878 // name is no longer relevant.
879 }
880 result = new BindingPipe(
881 this.span(start),
882 this.sourceSpan(start, fullSpanEnd),
883 result,
884 nameId,
885 args,
886 nameSpan,
887 );
888 } while (this.consumeOptionalOperator('|'));
889 }
890
891 return result;
892 }
893
894 private parseExpression(): AST {
895 return this.parseConditional();

Callers 10

parseChainMethod · 0.95
parseConditionalMethod · 0.95
parsePrimaryMethod · 0.95
parseLiteralArrayMethod · 0.95
parseLiteralMapMethod · 0.95
parseCallArgumentsMethod · 0.95
parseSpreadElementMethod · 0.95
parseKeyedReadOrWriteMethod · 0.95
parseTemplateLiteralMethod · 0.95

Calls 9

parseExpressionMethod · 0.95
errorMethod · 0.95
sourceSpanMethod · 0.95
spanMethod · 0.95
toAbsoluteMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected