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

Method _consumeText

packages/compiler/src/ml_parser/parser.ts:326–373  ·  view source on GitHub ↗
(token: InterpolatedTextToken)

Source from the content-addressed store, hash-verified

324 }
325
326 private _consumeText(token: InterpolatedTextToken) {
327 const tokens = [token];
328 const startSpan = token.sourceSpan;
329 let text = token.parts[0];
330 if (text.length > 0 && text[0] === '\n') {
331 const parent = this._getContainer();
332
333 if (
334 parent != null &&
335 parent.children.length === 0 &&
336 this._getTagDefinition(parent)?.ignoreFirstLf
337 ) {
338 text = text.substring(1);
339 tokens[0] = {type: token.type, sourceSpan: token.sourceSpan, parts: [text]} as typeof token;
340 }
341 }
342
343 while (
344 this._peek.type === TokenType.INTERPOLATION ||
345 this._peek.type === TokenType.TEXT ||
346 this._peek.type === TokenType.ENCODED_ENTITY
347 ) {
348 token = this._advance();
349 tokens.push(token);
350 if (token.type === TokenType.INTERPOLATION) {
351 // For backward compatibility we decode HTML entities that appear in interpolation
352 // expressions. This is arguably a bug, but it could be a considerable breaking change to
353 // fix it. It should be addressed in a larger project to refactor the entire parser/lexer
354 // chain after View Engine has been removed.
355 text += token.parts.join('').replace(/&([^;]+);/g, decodeEntity);
356 } else if (token.type === TokenType.ENCODED_ENTITY) {
357 text += token.parts[0];
358 } else {
359 text += token.parts.join('');
360 }
361 }
362
363 if (text.length > 0) {
364 const endSpan = token.sourceSpan;
365 this._addToParent(
366 new html.Text(
367 text,
368 new ParseSourceSpan(startSpan.start, endSpan.end, startSpan.fullStart, startSpan.details),
369 tokens,
370 ),
371 );
372 }
373 }
374
375 private _closeVoidElement(): void {
376 const el = this._getContainer();

Callers 2

buildMethod · 0.95
_consumeCdataMethod · 0.95

Calls 7

_getContainerMethod · 0.95
_getTagDefinitionMethod · 0.95
_advanceMethod · 0.95
_addToParentMethod · 0.95
joinMethod · 0.65
pushMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected