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

Class R3TargetBinder

packages/compiler/src/render3/view/t2_binder.ts:173–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171 * target.
172 */
173export class R3TargetBinder<DirectiveT extends DirectiveMeta> implements TargetBinder<DirectiveT> {
174 constructor(
175 private directiveMatcher: DirectiveMatcher<DirectiveT> | null,
176 private foreignComponentMatcher: SelectorlessMatcher<ForeignComponentMeta> | null = null,
177 ) {}
178
179 /**
180 * Perform a binding operation on the given `Target` and return a `BoundTarget` which contains
181 * metadata about the types referenced in the template.
182 */
183 bind(target: Target<DirectiveT>): BoundTarget<DirectiveT> {
184 if (!target.template && !target.host) {
185 throw new Error('Empty bound targets are not supported');
186 }
187
188 const directives: MatchedDirectives<DirectiveT> = new Map();
189 const foreignComponents = new Map<Element, ForeignComponentMeta>();
190 const eagerDirectives: DirectiveT[] = [];
191 const bindings: BindingsMap<DirectiveT> = new Map();
192 const references: ReferenceMap<DirectiveT> = new Map();
193 const scopedNodeEntities: ScopedNodeEntities = new Map();
194 const expressions = new Map<AST, TemplateEntity>();
195 const symbols = new Map<TemplateEntity, ScopedNode>();
196 const nestingLevel = new Map<ScopedNode, number>();
197 const usedPipes = new Set<string>();
198 const eagerPipes = new Set<string>();
199 const deferBlocks: DeferBlockScopes = [];
200 const pipes = new Map<BindingPipe, DeferredBlock[]>();
201 const conflictingHostDirectiveBindings = new Map<
202 DirectiveOwner,
203 ConflictingHostDirectiveBinding<DirectiveT>[]
204 >();
205
206 if (target.template) {
207 // First, parse the template into a `Scope` structure. This operation captures the syntactic
208 // scopes in the template and makes them available for later use.
209 const scope = Scope.apply(target.template);
210
211 // Next, perform directive matching on the template using the `DirectiveBinder`. This returns:
212 // - directives: Map of nodes (elements & ng-templates) to the directives on them.
213 // - bindings: Map of inputs, outputs, and attributes to the directive/element that claims
214 // them. TODO(alxhub): handle multiple directives claiming an input/output/etc.
215 // - references: Map of #references to their targets.
216 DirectiveBinder.apply(
217 target.template,
218 this.directiveMatcher,
219 this.foreignComponentMatcher,
220 directives,
221 foreignComponents,
222 eagerDirectives,
223 bindings,
224 references,
225 conflictingHostDirectiveBindings,
226 );
227
228 // Next, run the TemplateBinder to bind references, variables, and other entities within the
229 // template. This extracts all the metadata that doesn't depend on directive matching.
230 TemplateBinder.applyWithScope(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected