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

Method _popContainer

packages/compiler/src/ml_parser/parser.ts:516–545  ·  view source on GitHub ↗

* Closes the nearest element with the tag name `fullName` in the parse tree. * `endSourceSpan` is the span of the closing tag, or null if the element does * not have a closing tag (for example, this happens when an incomplete * opening tag is recovered).

(
    expectedName: string | null,
    expectedType: NodeContainerConstructor,
    endSourceSpan: ParseSourceSpan | null,
  )

Source from the content-addressed store, hash-verified

514 * opening tag is recovered).
515 */
516 private _popContainer(
517 expectedName: string | null,
518 expectedType: NodeContainerConstructor,
519 endSourceSpan: ParseSourceSpan | null,
520 ): boolean {
521 let unexpectedCloseTagDetected = false;
522 for (let stackIndex = this._containerStack.length - 1; stackIndex >= 0; stackIndex--) {
523 const node = this._containerStack[stackIndex];
524 const nodeName = node.name;
525
526 if ((nodeName === expectedName || expectedName === null) && node instanceof expectedType) {
527 // Record the parse span with the element that is being closed. Any elements that are
528 // removed from the element stack at this point are closed implicitly, so they won't get
529 // an end source span (as there is no explicit closing element).
530 node.endSourceSpan = endSourceSpan;
531 node.sourceSpan.end = endSourceSpan !== null ? endSourceSpan.end : node.sourceSpan.end;
532 this._containerStack.splice(stackIndex, this._containerStack.length - stackIndex);
533 return !unexpectedCloseTagDetected;
534 }
535
536 // Blocks and most elements are not self closing.
537 if (node instanceof html.Block || !this._getTagDefinition(node)?.closedByParent) {
538 // Note that we encountered an unexpected close tag but continue processing the element
539 // stack so we can assign an `endSourceSpan` if there is a corresponding start tag for this
540 // end tag in the stack.
541 unexpectedCloseTagDetected = true;
542 }
543 }
544 return false;
545 }
546
547 private _consumeAttr(attrName: AttributeNameToken): html.Attribute {
548 const fullName = mergeNsAndName(attrName.parts[0], attrName.parts[1]);

Callers 4

_consumeElementEndTagMethod · 0.95
_consumeBlockCloseMethod · 0.95

Calls 1

_getTagDefinitionMethod · 0.95

Tested by

no test coverage detected