visitEmbeddedTemplate method

  1. @override
void visitEmbeddedTemplate(
  1. EmbeddedTemplateAst ast,
  2. CompileElement parent
)
override

Implementation

@override
void visitEmbeddedTemplate(EmbeddedTemplateAst ast, CompileElement parent) {
  var nodeIndex = _view.nodes.length;
  var nodeReference = _view.createViewContainerAnchor(parent, nodeIndex, ast);
  var directives = _toCompileMetadata(ast.directives);
  var compileElement = CompileElement(
    parent,
    _view,
    nodeIndex,
    nodeReference,
    ast,
    null,
    directives,
    ast.providers,
    ast.hasViewContainer,
    true,
    ast.references,
    hasTemplateRefQuery: parent.hasTemplateRefQuery,
  );
  _view.nodes.add(compileElement);
  _nestedViewCount++;
  _addRootNodeAndProject(compileElement, ast.ngContentIndex, parent);

  var metadata = CompileDirectiveMetadata.from(_view.component,
      analyzedClass: AnalyzedClass.from(_view.component.analyzedClass!,
          additionalLocals: {
            for (var v in ast.variables) v.name: v.dartType,
          }));

  var embeddedView = CompileView(
    metadata,
    _view.genConfig,
    _view.directiveTypes,
    _view.pipeMetas,
    o.NULL_EXPR,
    _view.viewIndex + _nestedViewCount,
    compileElement,
    ast.variables,
    _view.genConfig.enableDataDebugSource,
  );

  _beforeChildren(compileElement);

  // Create a visitor for embedded view and visit all nodes.
  var embeddedViewVisitor = ViewBuilderVisitor(embeddedView);
  templateVisitAll(
      embeddedViewVisitor,
      ast.children,
      embeddedView.declarationElement.parent ??
          embeddedView.declarationElement);
  _nestedViewCount += embeddedViewVisitor._nestedViewCount;

  _afterChildren(compileElement);
  embeddedView.providers = embeddedViewVisitor.providers;
}