@@ -57,26 +57,32 @@ export function getDependenciesFromInjectable<T>(
57
57
const resolutionPath = getInjectorResolutionPath ( injector ) ;
58
58
59
59
const dependencies = unformattedDependencies . map ( dep => {
60
+ // injectedIn contains private fields, so we omit it from the response
61
+ const formattedDependency : Omit < InjectedService , 'injectedIn' > = {
62
+ value : dep . value ,
63
+ } ;
64
+
60
65
// convert injection flags to booleans
61
66
const flags = dep . flags as InternalInjectFlags ;
62
- dep . flags = {
67
+ formattedDependency . flags = {
63
68
optional : ( InternalInjectFlags . Optional & flags ) === InternalInjectFlags . Optional ,
64
69
host : ( InternalInjectFlags . Host & flags ) === InternalInjectFlags . Host ,
65
70
self : ( InternalInjectFlags . Self & flags ) === InternalInjectFlags . Self ,
66
71
skipSelf : ( InternalInjectFlags . SkipSelf & flags ) === InternalInjectFlags . SkipSelf ,
67
72
} ;
68
73
74
+
69
75
// find the injector that provided the dependency
70
76
for ( let i = 0 ; i < resolutionPath . length ; i ++ ) {
71
77
const injectorToCheck = resolutionPath [ i ] ;
72
78
73
79
// if skipSelf is true we skip the first injector
74
- if ( i === 0 && dep . flags . skipSelf ) {
80
+ if ( i === 0 && formattedDependency . flags . skipSelf ) {
75
81
continue ;
76
82
}
77
83
78
84
// host only applies to NodeInjectors
79
- if ( dep . flags . host && injectorToCheck instanceof EnvironmentInjector ) {
85
+ if ( formattedDependency . flags . host && injectorToCheck instanceof EnvironmentInjector ) {
80
86
break ;
81
87
}
82
88
@@ -88,36 +94,29 @@ export function getDependenciesFromInjectable<T>(
88
94
// in the resolution path by using the host flag. This is done to make sure that we've found
89
95
// the correct providing injector, and not a node injector that is connected to our path via
90
96
// a router outlet.
91
- if ( dep . flags . host ) {
97
+ if ( formattedDependency . flags . host ) {
92
98
const firstInjector = resolutionPath [ 0 ] ;
93
- const lookupFromFirstInjector =
94
- firstInjector . get ( dep . token as Type < unknown > , null , { ...dep . flags , optional : true } ) ;
99
+ const lookupFromFirstInjector = firstInjector . get (
100
+ dep . token as Type < unknown > , null , { ...formattedDependency . flags , optional : true } ) ;
95
101
96
102
if ( lookupFromFirstInjector !== null ) {
97
- dep . providedIn = injectorToCheck ;
103
+ formattedDependency . providedIn = injectorToCheck ;
98
104
}
99
105
100
106
break ;
101
107
}
102
108
103
- dep . providedIn = injectorToCheck ;
109
+ formattedDependency . providedIn = injectorToCheck ;
104
110
break ;
105
111
}
106
112
107
113
// if self is true we stop after the first injector
108
- if ( i === 0 && dep . flags . self ) {
114
+ if ( i === 0 && formattedDependency . flags . self ) {
109
115
break ;
110
116
}
111
117
}
112
118
113
- // injectedIn contains private fields, so we omit it from the response
114
- const formattedDependency : Omit < InjectedService , 'injectedIn' > = {
115
- value : dep . value ,
116
- } ;
117
-
118
119
if ( dep . token ) formattedDependency . token = dep . token ;
119
- if ( dep . flags ) formattedDependency . flags = dep . flags ;
120
- if ( dep . providedIn ) formattedDependency . providedIn = dep . providedIn ;
121
120
122
121
return formattedDependency ;
123
122
} ) ;
0 commit comments