Skip to content

Commit ba34b3c

Browse files
JeanMechekirjs
authored andcommitted
refactor(core): remove unused injection props (angular#59209)
Those were also properties that were kept to also support of old compiled targets. PR Close angular#59209
1 parent 4dadd90 commit ba34b3c

File tree

10 files changed

+6
-61
lines changed

10 files changed

+6
-61
lines changed

packages/compiler-cli/integrationtest/bazel/injectable_def/app/test/app_spec.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,33 +158,6 @@ describe('ngInjectableDef Bazel Integration', () => {
158158
expect(() => TestBed.inject(ChildService).value).toThrowError(/ChildService/);
159159
});
160160

161-
it('uses legacy `ngInjectable` property even if it inherits from a class that has `ɵprov` property', () => {
162-
@Injectable({
163-
providedIn: 'root',
164-
useValue: new ParentService('parent'),
165-
})
166-
class ParentService {
167-
constructor(public value: string) {}
168-
}
169-
170-
// ChildServices extends ParentService but does not have @Injectable
171-
class ChildService extends ParentService {
172-
constructor(value: string) {
173-
super(value);
174-
}
175-
static ngInjectableDef = {
176-
providedIn: 'root',
177-
factory: () => new ChildService('child'),
178-
token: ChildService,
179-
};
180-
}
181-
182-
TestBed.configureTestingModule({});
183-
// We are asserting that system throws an error, rather than taking the inherited
184-
// annotation.
185-
expect(TestBed.inject(ChildService).value).toEqual('child');
186-
});
187-
188161
it('NgModule injector understands requests for INJECTABLE', () => {
189162
TestBed.configureTestingModule({
190163
providers: [{provide: 'foo', useValue: 'bar'}],

packages/core/src/di/interface/defs.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export function ɵɵdefineInjector(options: {providers?: any[]; imports?: any[]}
212212
* @param type A type which may have its own (non-inherited) `ɵprov`.
213213
*/
214214
export function getInjectableDef<T>(type: any): ɵɵInjectableDeclaration<T> | null {
215-
return getOwnDefinition(type, NG_PROV_DEF) || getOwnDefinition(type, NG_INJECTABLE_DEF);
215+
return getOwnDefinition(type, NG_PROV_DEF);
216216
}
217217

218218
export function isInjectable(type: any): boolean {
@@ -224,7 +224,8 @@ export function isInjectable(type: any): boolean {
224224
* class of `type`.
225225
*/
226226
function getOwnDefinition<T>(type: any, field: string): ɵɵInjectableDeclaration<T> | null {
227-
return type.hasOwnProperty(field) ? type[field] : null;
227+
// if the ɵprov prop exist but is undefined we still want to return null
228+
return (type.hasOwnProperty(field) && type[field]) || null;
228229
}
229230

230231
/**
@@ -236,7 +237,8 @@ function getOwnDefinition<T>(type: any, field: string): ɵɵInjectableDeclaratio
236237
* scenario if we find the `ɵprov` on an ancestor only.
237238
*/
238239
export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDeclaration<T> | null {
239-
const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]);
240+
// if the ɵprov prop exist but is undefined we still want to return null
241+
const def = type?.[NG_PROV_DEF] ?? null;
240242

241243
if (def) {
242244
ngDevMode &&
@@ -256,14 +258,8 @@ export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDeclarati
256258
* @param type type which may have an injector def (`ɵinj`)
257259
*/
258260
export function getInjectorDef<T>(type: any): ɵɵInjectorDef<T> | null {
259-
return type && (type.hasOwnProperty(NG_INJ_DEF) || type.hasOwnProperty(NG_INJECTOR_DEF))
260-
? (type as any)[NG_INJ_DEF]
261-
: null;
261+
return type && type.hasOwnProperty(NG_INJ_DEF) ? (type as any)[NG_INJ_DEF] : null;
262262
}
263263

264264
export const NG_PROV_DEF = getClosureSafeProperty({ɵprov: getClosureSafeProperty});
265265
export const NG_INJ_DEF = getClosureSafeProperty({ɵinj: getClosureSafeProperty});
266-
267-
// We need to keep these around so we can read off old defs if new defs are unavailable
268-
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
269-
export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty});

packages/core/test/bundling/animations-standalone/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@
100100
"NG_ELEMENT_ID",
101101
"NG_ENV_ID",
102102
"NG_FACTORY_DEF",
103-
"NG_INJECTABLE_DEF",
104-
"NG_INJECTOR_DEF",
105103
"NG_INJ_DEF",
106104
"NG_PIPE_DEF",
107105
"NG_PROV_DEF",
@@ -324,7 +322,6 @@
324322
"getOrCreateInjectable",
325323
"getOrCreateNodeInjectorForNode",
326324
"getOrSetDefaultValue",
327-
"getOwnDefinition",
328325
"getParentElement",
329326
"getParentInjectorIndex",
330327
"getParentInjectorLocation",

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@
7575
"NG_ELEMENT_ID",
7676
"NG_ENV_ID",
7777
"NG_FACTORY_DEF",
78-
"NG_INJECTABLE_DEF",
79-
"NG_INJECTOR_DEF",
8078
"NG_INJ_DEF",
8179
"NG_MOD_DEF",
8280
"NG_PIPE_DEF",
@@ -273,7 +271,6 @@
273271
"getOrCreateInjectable",
274272
"getOrCreateNodeInjectorForNode",
275273
"getOrCreateTNode",
276-
"getOwnDefinition",
277274
"getParentInjectorIndex",
278275
"getParentInjectorLocation",
279276
"getParentInjectorView",

packages/core/test/bundling/defer/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@
102102
"NG_ELEMENT_ID",
103103
"NG_ENV_ID",
104104
"NG_FACTORY_DEF",
105-
"NG_INJECTABLE_DEF",
106-
"NG_INJECTOR_DEF",
107105
"NG_INJ_DEF",
108106
"NG_PIPE_DEF",
109107
"NG_PROV_DEF",
@@ -331,7 +329,6 @@
331329
"getOrCreateInjectable",
332330
"getOrCreateNodeInjectorForNode",
333331
"getOrCreateTNode",
334-
"getOwnDefinition",
335332
"getParentInjectorIndex",
336333
"getParentInjectorLocation",
337334
"getParentInjectorView",

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@
108108
"NG_ELEMENT_ID",
109109
"NG_ENV_ID",
110110
"NG_FACTORY_DEF",
111-
"NG_INJECTABLE_DEF",
112-
"NG_INJECTOR_DEF",
113111
"NG_INJ_DEF",
114112
"NG_MODEL_WITH_FORM_CONTROL_WARNING",
115113
"NG_MOD_DEF",
@@ -392,7 +390,6 @@
392390
"getOrCreateNodeInjectorForNode",
393391
"getOrCreateTNode",
394392
"getOrCreateViewRefs",
395-
"getOwnDefinition",
396393
"getParentInjectorIndex",
397394
"getParentInjectorLocation",
398395
"getParentInjectorView",

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@
101101
"NG_ELEMENT_ID",
102102
"NG_ENV_ID",
103103
"NG_FACTORY_DEF",
104-
"NG_INJECTABLE_DEF",
105-
"NG_INJECTOR_DEF",
106104
"NG_INJ_DEF",
107105
"NG_MOD_DEF",
108106
"NG_PIPE_DEF",
@@ -378,7 +376,6 @@
378376
"getOrCreateNodeInjectorForNode",
379377
"getOrCreateTNode",
380378
"getOrCreateViewRefs",
381-
"getOwnDefinition",
382379
"getParentInjectorIndex",
383380
"getParentInjectorLocation",
384381
"getParentInjectorView",

packages/core/test/bundling/hydration/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282
"NG_ELEMENT_ID",
8383
"NG_ENV_ID",
8484
"NG_FACTORY_DEF",
85-
"NG_INJECTABLE_DEF",
86-
"NG_INJECTOR_DEF",
8785
"NG_INJ_DEF",
8886
"NG_PIPE_DEF",
8987
"NG_PROV_DEF",
@@ -285,7 +283,6 @@
285283
"getOrCreateInjectable",
286284
"getOrCreateNodeInjectorForNode",
287285
"getOrCreateTNode",
288-
"getOwnDefinition",
289286
"getParentInjectorIndex",
290287
"getParentInjectorLocation",
291288
"getParentInjectorView",

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@
116116
"NG_ELEMENT_ID",
117117
"NG_ENV_ID",
118118
"NG_FACTORY_DEF",
119-
"NG_INJECTABLE_DEF",
120-
"NG_INJECTOR_DEF",
121119
"NG_INJ_DEF",
122120
"NG_MOD_DEF",
123121
"NG_PIPE_DEF",
@@ -468,7 +466,6 @@
468466
"getOrCreateTViewCleanup",
469467
"getOrCreateViewRefs",
470468
"getOutlet",
471-
"getOwnDefinition",
472469
"getParentInjectorIndex",
473470
"getParentInjectorLocation",
474471
"getParentInjectorView",

packages/core/test/bundling/standalone_bootstrap/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
"NG_ELEMENT_ID",
7171
"NG_ENV_ID",
7272
"NG_FACTORY_DEF",
73-
"NG_INJECTABLE_DEF",
74-
"NG_INJECTOR_DEF",
7573
"NG_INJ_DEF",
7674
"NG_PIPE_DEF",
7775
"NG_PROV_DEF",
@@ -247,7 +245,6 @@
247245
"getOrCreateInjectable",
248246
"getOrCreateNodeInjectorForNode",
249247
"getOrCreateTNode",
250-
"getOwnDefinition",
251248
"getParentInjectorIndex",
252249
"getParentInjectorLocation",
253250
"getParentInjectorView",

0 commit comments

Comments
 (0)