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