feat(ivy): require 'token' for ngInjectableDef (#30855)
The compiler generates a 'token' field when it emits an ngInjectableDef, but this field was not required by defineInjectable or the InjectableDef interface, nor was it added by InjectionToken. This commit makes 'token' required and adds it where missing. PR Close #30855
This commit is contained in:

committed by
Andrew Kushnir

parent
b0866769b0
commit
a4b4f35533
@ -90,6 +90,7 @@ function render2CompileInjectable(
|
||||
options: {providedIn?: Type<any>| 'root' | null} & InjectableProvider): void {
|
||||
if (options && options.providedIn !== undefined && !getInjectableDef(injectableType)) {
|
||||
injectableType.ngInjectableDef = ɵɵdefineInjectable({
|
||||
token: injectableType,
|
||||
providedIn: options.providedIn,
|
||||
factory: convertInjectableProviderToFactory(injectableType, options),
|
||||
});
|
||||
|
@ -68,6 +68,7 @@ export class InjectionToken<T> {
|
||||
(this as any).__NG_ELEMENT_ID__ = options;
|
||||
} else if (options !== undefined) {
|
||||
this.ngInjectableDef = ɵɵdefineInjectable({
|
||||
token: this,
|
||||
providedIn: options.providedIn || 'root',
|
||||
factory: options.factory,
|
||||
});
|
||||
|
@ -89,6 +89,7 @@ export abstract class Injector {
|
||||
|
||||
/** @nocollapse */
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
token: Injector,
|
||||
providedIn: 'any' as any,
|
||||
factory: () => ɵɵinject(INJECTOR),
|
||||
});
|
||||
|
@ -37,6 +37,13 @@ export interface ɵɵInjectableDef<T> {
|
||||
*/
|
||||
providedIn: InjectorType<any>|'root'|'any'|null;
|
||||
|
||||
/**
|
||||
* The token to which this definition belongs.
|
||||
*
|
||||
* Note that this may not be the same as the type that the `factory` will create.
|
||||
*/
|
||||
token: unknown;
|
||||
|
||||
/**
|
||||
* Factory method to execute to create an instance of the injectable.
|
||||
*/
|
||||
@ -132,11 +139,13 @@ export interface InjectorTypeWithProviders<T> {
|
||||
* @codeGenApi
|
||||
*/
|
||||
export function ɵɵdefineInjectable<T>(opts: {
|
||||
token: unknown,
|
||||
providedIn?: Type<any>| 'root' | 'any' | null,
|
||||
factory: () => T,
|
||||
}): never {
|
||||
return ({
|
||||
providedIn: opts.providedIn as any || null, factory: opts.factory, value: undefined,
|
||||
token: opts.token, providedIn: opts.providedIn as any || null, factory: opts.factory,
|
||||
value: undefined,
|
||||
} as ɵɵInjectableDef<T>) as never;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user