CompileView constructor

CompileView(
  1. CompileDirectiveMetadata component,
  2. CompilerFlags genConfig,
  3. List<CompileTypedMetadata> directiveTypes,
  4. List<CompilePipeMetadata?> pipeMetas,
  5. Expression styles,
  6. int viewIndex,
  7. CompileElement declarationElement,
  8. List<VariableAst> templateVariables,
  9. bool enableDataDebugSource,
)

Implementation

CompileView(
  this.component,
  this.genConfig,
  this.directiveTypes,
  this.pipeMetas,
  this.styles,
  this.viewIndex,
  this.declarationElement,
  this.templateVariables,
  this.enableDataDebugSource,
) {
  nameResolver = ViewNameResolver(this);
  storage = CompileViewStorage();
  viewType = _getViewType(component, viewIndex);
  className = '${viewIndex == 0 && viewType != ViewType.host ? '' : '_'}'
      'View${component.type.name}$viewIndex';
  classType = o.importType(CompileIdentifierMetadata(name: className))!;
  viewFactoryName = getViewFactoryName(component, viewIndex);
  viewFactory = getViewFactory(component, viewFactoryName);
  switch (viewType) {
    case ViewType.host:
    case ViewType.component:
      componentView = this;
      break;
    default:
      // An embedded template uses it's declaration element's componentView.
      componentView = declarationElement.view!.componentView;
      break;
  }
  viewQueries = CompileTokenMap<List<CompileQuery>>();
  if (viewType == ViewType.component) {
    var directiveInstance = BuiltInSource(
        identifierToken(component.type), DetectChangesVars.cachedCtx);
    var queryIndex = -1;
    for (var metadata in component.viewQueries) {
      queryIndex++;
      final query = CompileQuery.viewQuery(
        metadata: metadata,
        storage: storage,
        queryRoot: this,
        boundDirective: directiveInstance,
        queryIndex: queryIndex,
      );
      addQueryToTokenMap(viewQueries, query);
    }
  }

  for (var variable in templateVariables) {
    nameResolver.addLocal(
      variable.name,
      o.ReadClassMemberExpr('locals').key(o.literal(variable.value)),
      variable.type, // NgFor locals are augmented with type information.
    );
  }
  if (declarationElement.parent != null) {
    declarationElement.setEmbeddedView(this);
  }
}