* Perform a binding operation on the given `Target` and return a `BoundTarget` which contains * metadata about the types referenced in the template.
(target: Target<DirectiveT>)
| 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( |
| 231 | target.template, |
| 232 | scope, |
| 233 | expressions, |
| 234 | symbols, |
| 235 | nestingLevel, |
| 236 | usedPipes, |
| 237 | eagerPipes, |
| 238 | deferBlocks, |
| 239 | pipes, |
| 240 | ); |
no test coverage detected