* 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,
)
| 1161 | * an end to the interpolation before its normal closing marker. |
| 1162 | */ |
| 1163 | private _consumeInterpolation( |
| 1164 | interpolationTokenType: TokenType, |
| 1165 | interpolationStart: CharacterCursor, |
| 1166 | prematureEndPredicate: (() => boolean) | null, |
| 1167 | ): void { |
| 1168 | const parts: string[] = []; |
| 1169 | this._beginToken(interpolationTokenType, interpolationStart); |
| 1170 | parts.push(INTERPOLATION.start); |
| 1171 | |
| 1172 | // Find the end of the interpolation, ignoring content inside quotes. |
| 1173 | const expressionStart = this._cursor.clone(); |
| 1174 | let inQuote: number | null = null; |
| 1175 | let inComment = false; |
| 1176 | while ( |
| 1177 | this._cursor.peek() !== chars.$EOF && |
| 1178 | (prematureEndPredicate === null || !prematureEndPredicate()) |
| 1179 | ) { |
| 1180 | const current = this._cursor.clone(); |
| 1181 | |
| 1182 | if (this._isTagStart()) { |
| 1183 | // We are starting what looks like an HTML element in the middle of this interpolation. |
| 1184 | // Reset the cursor to before the `<` character and end the interpolation token. |
| 1185 | // (This is actually wrong but here for backward compatibility). |
| 1186 | this._cursor = current; |
| 1187 | parts.push(this._getProcessedChars(expressionStart, current)); |
| 1188 | this._endToken(parts); |
| 1189 | return; |
| 1190 | } |
| 1191 | |
| 1192 | if (inQuote === null) { |
| 1193 | if (this._attemptStr(INTERPOLATION.end)) { |
| 1194 | // We are not in a string, and we hit the end interpolation marker |
| 1195 | parts.push(this._getProcessedChars(expressionStart, current)); |
| 1196 | parts.push(INTERPOLATION.end); |
| 1197 | this._endToken(parts); |
| 1198 | return; |
| 1199 | } else if (this._attemptStr('//')) { |
| 1200 | // Once we are in a comment we ignore any quotes |
| 1201 | inComment = true; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | const char = this._cursor.peek(); |
| 1206 | this._cursor.advance(); |
| 1207 | if (char === chars.$BACKSLASH) { |
| 1208 | // Skip the next character because it was escaped. |
| 1209 | this._cursor.advance(); |
| 1210 | } else if (char === inQuote) { |
| 1211 | // Exiting the current quoted string |
| 1212 | inQuote = null; |
| 1213 | } else if (!inComment && inQuote === null && chars.isQuote(char)) { |
| 1214 | // Entering a new quoted string |
| 1215 | inQuote = char; |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | // We hit EOF without finding a closing interpolation marker |
| 1220 | parts.push(this._getProcessedChars(expressionStart, this._cursor)); |
no test coverage detected