MCPcopy Index your code
hub / github.com/angular/angular / _consumeInterpolation

Method _consumeInterpolation

packages/compiler/src/ml_parser/lexer.ts:1247–1306  ·  view source on GitHub ↗

* Consume a block of text that has been interpreted as an Angular interpolation. * * @param interpolationTokenType the type of the interpolation token to generate. * @param interpolationStart a cursor that points to the start of this interpolation. * @param prematureEndPredicate a functi

(
    interpolationTokenType: TokenType,
    interpolationStart: CharacterCursor,
    prematureEndPredicate: (() => boolean) | null,
  )

Source from the content-addressed store, hash-verified

1245 * an end to the interpolation before its normal closing marker.
1246 */
1247 private _consumeInterpolation(
1248 interpolationTokenType: TokenType,
1249 interpolationStart: CharacterCursor,
1250 prematureEndPredicate: (() => boolean) | null,
1251 ): void {
1252 const parts: string[] = [];
1253 this._beginToken(interpolationTokenType, interpolationStart);
1254 parts.push(INTERPOLATION.start);
1255
1256 // Find the end of the interpolation, ignoring content inside quotes.
1257 const expressionStart = this._cursor.clone();
1258 let inQuote: number | null = null;
1259 let inComment = false;
1260 while (
1261 this._cursor.peek() !== chars.$EOF &&
1262 (prematureEndPredicate === null || !prematureEndPredicate())
1263 ) {
1264 const current = this._cursor.clone();
1265
1266 if (this._isTagStart()) {
1267 // We are starting what looks like an HTML element in the middle of this interpolation.
1268 // Reset the cursor to before the `<` character and end the interpolation token.
1269 // (This is actually wrong but here for backward compatibility).
1270 this._cursor = current;
1271 parts.push(this._getProcessedChars(expressionStart, current));
1272 this._endToken(parts);
1273 return;
1274 }
1275
1276 if (inQuote === null) {
1277 if (this._attemptStr(INTERPOLATION.end)) {
1278 // We are not in a string, and we hit the end interpolation marker
1279 parts.push(this._getProcessedChars(expressionStart, current));
1280 parts.push(INTERPOLATION.end);
1281 this._endToken(parts);
1282 return;
1283 } else if (this._attemptStr('//')) {
1284 // Once we are in a comment we ignore any quotes
1285 inComment = true;
1286 }
1287 }
1288
1289 const char = this._cursor.peek();
1290 this._cursor.advance();
1291 if (char === chars.$BACKSLASH) {
1292 // Skip the next character because it was escaped.
1293 this._cursor.advance();
1294 } else if (char === inQuote) {
1295 // Exiting the current quoted string
1296 inQuote = null;
1297 } else if (!inComment && inQuote === null && chars.isQuote(char)) {
1298 // Entering a new quoted string
1299 inQuote = char;
1300 }
1301 }
1302
1303 // We hit EOF without finding a closing interpolation marker
1304 parts.push(this._getProcessedChars(expressionStart, this._cursor));

Callers 1

Calls 9

_beginTokenMethod · 0.95
_isTagStartMethod · 0.95
_getProcessedCharsMethod · 0.95
_endTokenMethod · 0.95
_attemptStrMethod · 0.95
cloneMethod · 0.65
peekMethod · 0.65
advanceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected