* 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,
)
| 1277 | * an end to the interpolation before its normal closing marker. |
| 1278 | */ |
| 1279 | private _consumeInterpolation( |
| 1280 | interpolationTokenType: TokenType, |
| 1281 | interpolationStart: CharacterCursor, |
| 1282 | prematureEndPredicate: (() => boolean) | null, |
| 1283 | ): void { |
| 1284 | const parts: string[] = []; |
| 1285 | this._beginToken(interpolationTokenType, interpolationStart); |
| 1286 | parts.push(INTERPOLATION.start); |
| 1287 | |
| 1288 | // Find the end of the interpolation, ignoring content inside quotes. |
| 1289 | const expressionStart = this._cursor.clone(); |
| 1290 | let inQuote: number | null = null; |
| 1291 | let inComment = false; |
| 1292 | while ( |
| 1293 | this._cursor.peek() !== chars.$EOF && |
| 1294 | (prematureEndPredicate === null || !prematureEndPredicate()) |
| 1295 | ) { |
| 1296 | const current = this._cursor.clone(); |
| 1297 | |
| 1298 | if (this._isTagStart()) { |
| 1299 | // We are starting what looks like an HTML element in the middle of this interpolation. |
| 1300 | // Reset the cursor to before the `<` character and end the interpolation token. |
| 1301 | // (This is actually wrong but here for backward compatibility). |
| 1302 | this._cursor = current; |
| 1303 | parts.push(this._getProcessedChars(expressionStart, current)); |
| 1304 | this._endToken(parts); |
| 1305 | return; |
| 1306 | } |
| 1307 | |
| 1308 | if (inQuote === null) { |
| 1309 | if (this._attemptStr(INTERPOLATION.end)) { |
| 1310 | // We are not in a string, and we hit the end interpolation marker |
| 1311 | parts.push(this._getProcessedChars(expressionStart, current)); |
| 1312 | parts.push(INTERPOLATION.end); |
| 1313 | this._endToken(parts); |
| 1314 | return; |
| 1315 | } else if (this._attemptStr('//')) { |
| 1316 | // Once we are in a comment we ignore any quotes |
| 1317 | inComment = true; |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | const char = this._cursor.peek(); |
| 1322 | this._cursor.advance(); |
| 1323 | if (char === chars.$BACKSLASH) { |
| 1324 | // Skip the next character because it was escaped. |
| 1325 | this._cursor.advance(); |
| 1326 | } else if (char === inQuote) { |
| 1327 | // Exiting the current quoted string |
| 1328 | inQuote = null; |
| 1329 | } else if (!inComment && inQuote === null && chars.isQuote(char)) { |
| 1330 | // Entering a new quoted string |
| 1331 | inQuote = char; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | // We hit EOF without finding a closing interpolation marker |
| 1336 | parts.push(this._getProcessedChars(expressionStart, this._cursor)); |
no test coverage detected