( tNode: TNode, tView: TView, token: ProviderToken<T> | string, canAccessViewProviders: boolean, isHostSpecialCase: boolean | number, )
| 683 | * @returns Index of a found directive or provider, or null when none found. |
| 684 | */ |
| 685 | export function locateDirectiveOrProvider<T>( |
| 686 | tNode: TNode, |
| 687 | tView: TView, |
| 688 | token: ProviderToken<T> | string, |
| 689 | canAccessViewProviders: boolean, |
| 690 | isHostSpecialCase: boolean | number, |
| 691 | ): number | null { |
| 692 | const nodeProviderIndexes = tNode.providerIndexes; |
| 693 | const tInjectables = tView.data; |
| 694 | |
| 695 | const injectablesStart = nodeProviderIndexes & TNodeProviderIndexes.ProvidersStartIndexMask; |
| 696 | const directivesStart = tNode.directiveStart; |
| 697 | const directiveEnd = tNode.directiveEnd; |
| 698 | const cptViewProvidersCount = |
| 699 | nodeProviderIndexes >> TNodeProviderIndexes.CptViewProvidersCountShift; |
| 700 | const startingIndex = canAccessViewProviders |
| 701 | ? injectablesStart |
| 702 | : injectablesStart + cptViewProvidersCount; |
| 703 | // When the host special case applies, only the viewProviders and the component are visible |
| 704 | const endIndex = isHostSpecialCase ? injectablesStart + cptViewProvidersCount : directiveEnd; |
| 705 | for (let i = startingIndex; i < endIndex; i++) { |
| 706 | const providerTokenOrDef = tInjectables[i] as ProviderToken<any> | DirectiveDef<any> | string; |
| 707 | if ( |
| 708 | (i < directivesStart && token === providerTokenOrDef) || |
| 709 | (i >= directivesStart && (providerTokenOrDef as DirectiveDef<any>).type === token) |
| 710 | ) { |
| 711 | return i; |
| 712 | } |
| 713 | } |
| 714 | if (isHostSpecialCase) { |
| 715 | const dirDef = tInjectables[directivesStart] as DirectiveDef<any>; |
| 716 | if (dirDef && isComponentDef(dirDef) && dirDef.type === token) { |
| 717 | return directivesStart; |
| 718 | } |
| 719 | } |
| 720 | return null; |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * Used in ngDevMode to keep the injection path in case of cycles in DI. |
no test coverage detected
searching dependent graphs…