refactor(core): rename ngInjectableDef to ɵprov (#33151)
Injectable defs are not considered public API, so the property that contains them should be prefixed with Angular's marker for "private" ('ɵ') to discourage apps from relying on def APIs directly. This commit adds the prefix and shortens the name from ngInjectableDef to "prov" (for "provider", since injector defs are known as "inj"). This is because property names cannot be minified by Uglify without turning on property mangling (which most apps have turned off) and are thus size-sensitive. PR Close #33151
This commit is contained in:

committed by
Matias Niemelä

parent
cda9248b33
commit
86104b82b8
@ -143,7 +143,7 @@ export interface IterableDifferFactory {
|
||||
*/
|
||||
export class IterableDiffers {
|
||||
/** @nocollapse */
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: IterableDiffers,
|
||||
providedIn: 'root',
|
||||
factory: () => new IterableDiffers([new DefaultIterableDifferFactory()])
|
||||
|
@ -118,7 +118,7 @@ export interface KeyValueDifferFactory {
|
||||
*/
|
||||
export class KeyValueDiffers {
|
||||
/** @nocollapse */
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: KeyValueDiffers,
|
||||
providedIn: 'root',
|
||||
factory: () => new KeyValueDiffers([new DefaultKeyValueDifferFactory()])
|
||||
|
@ -229,7 +229,7 @@ export {
|
||||
} from './render3/fields';
|
||||
|
||||
export {
|
||||
NG_INJECTABLE_DEF as ɵNG_INJECTABLE_DEF,
|
||||
NG_PROV_DEF as ɵNG_PROV_DEF,
|
||||
NG_INJ_DEF as ɵNG_INJ_DEF,
|
||||
} from './di/interface/defs';
|
||||
|
||||
|
@ -91,7 +91,7 @@ export const Injectable: InjectableDecorator = makeDecorator(
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface InjectableType<T> extends Type<T> { ngInjectableDef: ɵɵInjectableDef<T>; }
|
||||
export interface InjectableType<T> extends Type<T> { ɵprov: ɵɵInjectableDef<T>; }
|
||||
|
||||
/**
|
||||
* Supports @Injectable() in JIT mode for Render2.
|
||||
@ -100,7 +100,7 @@ function render2CompileInjectable(injectableType: Type<any>, options?: {
|
||||
providedIn?: Type<any>| 'root' | 'platform' | 'any' | null
|
||||
} & InjectableProvider): void {
|
||||
if (options && options.providedIn !== undefined && !getInjectableDef(injectableType)) {
|
||||
(injectableType as InjectableType<any>).ngInjectableDef = ɵɵdefineInjectable({
|
||||
(injectableType as InjectableType<any>).ɵprov = ɵɵdefineInjectable({
|
||||
token: injectableType,
|
||||
providedIn: options.providedIn,
|
||||
factory: convertInjectableProviderToFactory(injectableType, options),
|
||||
|
@ -54,20 +54,20 @@ export class InjectionToken<T> {
|
||||
/** @internal */
|
||||
readonly ngMetadataName = 'InjectionToken';
|
||||
|
||||
readonly ngInjectableDef: never|undefined;
|
||||
readonly ɵprov: never|undefined;
|
||||
|
||||
constructor(protected _desc: string, options?: {
|
||||
providedIn?: Type<any>| 'root' | 'platform' | 'any' | null,
|
||||
factory: () => T
|
||||
}) {
|
||||
this.ngInjectableDef = undefined;
|
||||
this.ɵprov = undefined;
|
||||
if (typeof options == 'number') {
|
||||
// This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
|
||||
// __NG_ELEMENT_ID__ is Used by Ivy to determine bloom filter id.
|
||||
// We are using it to assign `-1` which is used to identify `Injector`.
|
||||
(this as any).__NG_ELEMENT_ID__ = options;
|
||||
} else if (options !== undefined) {
|
||||
this.ngInjectableDef = ɵɵdefineInjectable({
|
||||
this.ɵprov = ɵɵdefineInjectable({
|
||||
token: this,
|
||||
providedIn: options.providedIn || 'root',
|
||||
factory: options.factory,
|
||||
@ -78,4 +78,4 @@ export class InjectionToken<T> {
|
||||
toString(): string { return `InjectionToken ${this._desc}`; }
|
||||
}
|
||||
|
||||
export interface InjectableDefToken<T> extends InjectionToken<T> { ngInjectableDef: never; }
|
||||
export interface InjectableDefToken<T> extends InjectionToken<T> { ɵprov: never; }
|
||||
|
@ -90,7 +90,7 @@ export abstract class Injector {
|
||||
}
|
||||
|
||||
/** @nocollapse */
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: Injector,
|
||||
providedIn: 'any' as any,
|
||||
factory: () => ɵɵinject(INJECTOR),
|
||||
|
@ -71,7 +71,7 @@ export interface ɵɵInjectorDef<T> {
|
||||
factory: () => T;
|
||||
|
||||
// TODO(alxhub): Narrow down the type here once decorators properly change the return type of the
|
||||
// class they are decorating (to add the ngInjectableDef property for example).
|
||||
// class they are decorating (to add the ɵprov property for example).
|
||||
providers: (Type<any>|ValueProvider|ExistingProvider|FactoryProvider|ConstructorProvider|
|
||||
StaticClassProvider|ClassProvider|any[])[];
|
||||
|
||||
@ -90,7 +90,7 @@ export interface InjectableType<T> extends Type<T> {
|
||||
/**
|
||||
* Opaque type whose structure is highly version dependent. Do not rely on any properties.
|
||||
*/
|
||||
ngInjectableDef: never;
|
||||
ɵprov: never;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +126,7 @@ export interface InjectorTypeWithProviders<T> {
|
||||
* Construct an `InjectableDef` which defines how a token will be constructed by the DI system, and
|
||||
* in which injectors (if any) it will be available.
|
||||
*
|
||||
* This should be assigned to a static `ngInjectableDef` field on a type, which will then be an
|
||||
* This should be assigned to a static `ɵprov` field on a type, which will then be an
|
||||
* `InjectableType`.
|
||||
*
|
||||
* Options:
|
||||
@ -168,7 +168,7 @@ export const defineInjectable = ɵɵdefineInjectable;
|
||||
* create the type must be provided. If that factory function needs to inject arguments, it can
|
||||
* use the `inject` function.
|
||||
* * `providers`: an optional array of providers to add to the injector. Each provider must
|
||||
* either have a factory or point to a type which has an `ngInjectableDef` static property (the
|
||||
* either have a factory or point to a type which has a `ɵprov` static property (the
|
||||
* type must be an `InjectableType`).
|
||||
* * `imports`: an optional array of imports of other `InjectorType`s or `InjectorTypeWithModule`s
|
||||
* whose providers will also be added to the injector. Locally provided types will override
|
||||
@ -184,39 +184,40 @@ export function ɵɵdefineInjector(options: {factory: () => any, providers?: any
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the `ngInjectableDef` for `type` in a way which is immune to accidentally reading inherited
|
||||
* value.
|
||||
* Read the injectable def (`ɵprov`) for `type` in a way which is immune to accidentally reading
|
||||
* inherited value.
|
||||
*
|
||||
* @param type A type which may have its own (non-inherited) `ngInjectableDef`.
|
||||
* @param type A type which may have its own (non-inherited) `ɵprov`.
|
||||
*/
|
||||
export function getInjectableDef<T>(type: any): ɵɵInjectableDef<T>|null {
|
||||
const def = type[NG_INJECTABLE_DEF] as ɵɵInjectableDef<T>;
|
||||
const def = (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]) as ɵɵInjectableDef<T>;
|
||||
// The definition read above may come from a base class. `hasOwnProperty` is not sufficient to
|
||||
// distinguish this case, as in older browsers (e.g. IE10) static property inheritance is
|
||||
// implemented by copying the properties.
|
||||
//
|
||||
// Instead, the ngInjectableDef's token is compared to the type, and if they don't match then the
|
||||
// Instead, the ɵprov's token is compared to the type, and if they don't match then the
|
||||
// property was not defined directly on the type itself, and was likely inherited. The definition
|
||||
// is only returned if the type matches the def.token.
|
||||
return def && def.token === type ? def : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the `ngInjectableDef` for `type` or read the `ngInjectableDef` from one of its ancestors.
|
||||
* Read the injectable def (`ɵprov`) for `type` or read the `ɵprov` from one of its ancestors.
|
||||
*
|
||||
* @param type A type which may have `ngInjectableDef`, via inheritance.
|
||||
* @param type A type which may have `ɵprov`, via inheritance.
|
||||
*
|
||||
* @deprecated Will be removed in v10, where an error will occur in the scenario if we find the
|
||||
* `ngInjectableDef` on an ancestor only.
|
||||
* `ɵprov` on an ancestor only.
|
||||
*/
|
||||
export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDef<T>|null {
|
||||
if (type && type[NG_INJECTABLE_DEF]) {
|
||||
const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]);
|
||||
if (def) {
|
||||
// TODO(FW-1307): Re-add ngDevMode when closure can handle it
|
||||
// ngDevMode &&
|
||||
console.warn(
|
||||
`DEPRECATED: DI is instantiating a token "${type.name}" that inherits its @Injectable decorator but does not provide one itself.\n` +
|
||||
`This will become an error in v10. Please add @Injectable() to the "${type.name}" class.`);
|
||||
return type[NG_INJECTABLE_DEF];
|
||||
return def;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -228,8 +229,14 @@ export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDef<T>|nu
|
||||
* @param type type which may have an injector def (`ɵinj`)
|
||||
*/
|
||||
export function getInjectorDef<T>(type: any): ɵɵInjectorDef<T>|null {
|
||||
return type && type.hasOwnProperty(NG_INJ_DEF) ? (type as any)[NG_INJ_DEF] : null;
|
||||
return type && (type.hasOwnProperty(NG_INJ_DEF) || type.hasOwnProperty(NG_INJECTOR_DEF)) ?
|
||||
(type as any)[NG_INJ_DEF] :
|
||||
null;
|
||||
}
|
||||
|
||||
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
|
||||
export const NG_PROV_DEF = getClosureSafeProperty({ɵprov: getClosureSafeProperty});
|
||||
export const NG_INJ_DEF = getClosureSafeProperty({ɵinj: getClosureSafeProperty});
|
||||
|
||||
// We need to keep these around so we can read off old defs if new defs are unavailable
|
||||
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
|
||||
export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty});
|
||||
|
@ -12,7 +12,7 @@ import {NG_FACTORY_DEF} from '../../render3/fields';
|
||||
import {getClosureSafeProperty} from '../../util/property';
|
||||
import {resolveForwardRef} from '../forward_ref';
|
||||
import {Injectable} from '../injectable';
|
||||
import {NG_INJECTABLE_DEF} from '../interface/defs';
|
||||
import {NG_PROV_DEF} from '../interface/defs';
|
||||
import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../interface/provider';
|
||||
|
||||
import {angularCoreDiEnv} from './environment';
|
||||
@ -22,19 +22,19 @@ import {convertDependencies, reflectDependencies} from './util';
|
||||
|
||||
/**
|
||||
* Compile an Angular injectable according to its `Injectable` metadata, and patch the resulting
|
||||
* `ngInjectableDef` onto the injectable type.
|
||||
* injectable def (`ɵprov`) onto the injectable type.
|
||||
*/
|
||||
export function compileInjectable(type: Type<any>, srcMeta?: Injectable): void {
|
||||
let ngInjectableDef: any = null;
|
||||
let ngFactoryDef: any = null;
|
||||
|
||||
// if NG_INJECTABLE_DEF is already defined on this class then don't overwrite it
|
||||
if (!type.hasOwnProperty(NG_INJECTABLE_DEF)) {
|
||||
Object.defineProperty(type, NG_INJECTABLE_DEF, {
|
||||
// if NG_PROV_DEF is already defined on this class then don't overwrite it
|
||||
if (!type.hasOwnProperty(NG_PROV_DEF)) {
|
||||
Object.defineProperty(type, NG_PROV_DEF, {
|
||||
get: () => {
|
||||
if (ngInjectableDef === null) {
|
||||
ngInjectableDef = getCompilerFacade().compileInjectable(
|
||||
angularCoreDiEnv, `ng:///${type.name}/ngInjectableDef.js`,
|
||||
angularCoreDiEnv, `ng:///${type.name}/ɵprov.js`,
|
||||
getInjectableMetadata(type, srcMeta));
|
||||
}
|
||||
return ngInjectableDef;
|
||||
|
@ -176,11 +176,11 @@ export class R3Injector {
|
||||
// SkipSelf isn't set, check if the record belongs to this injector.
|
||||
let record: Record<T>|undefined|null = this.records.get(token);
|
||||
if (record === undefined) {
|
||||
// No record, but maybe the token is scoped to this injector. Look for an ngInjectableDef
|
||||
// with a scope matching this injector.
|
||||
// No record, but maybe the token is scoped to this injector. Look for an injectable
|
||||
// def with a scope matching this injector.
|
||||
const def = couldBeInjectableType(token) && getInjectableDef(token);
|
||||
if (def && this.injectableDefInScope(def)) {
|
||||
// Found an ngInjectableDef and it's scoped to this injector. Pretend as if it was here
|
||||
// Found an injectable def and it's scoped to this injector. Pretend as if it was here
|
||||
// all along.
|
||||
record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET);
|
||||
} else {
|
||||
@ -408,7 +408,7 @@ export class R3Injector {
|
||||
}
|
||||
|
||||
function injectableDefOrInjectorDefFactory(token: Type<any>| InjectionToken<any>): () => any {
|
||||
// Most tokens will have an ngInjectableDef directly on them, which specifies a factory directly.
|
||||
// Most tokens will have an injectable def directly on them, which specifies a factory directly.
|
||||
const injectableDef = getInjectableDef(token);
|
||||
const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
|
||||
|
||||
@ -423,10 +423,10 @@ function injectableDefOrInjectorDefFactory(token: Type<any>| InjectionToken<any>
|
||||
return injectorDef.factory;
|
||||
}
|
||||
|
||||
// InjectionTokens should have an ngInjectableDef and thus should be handled above.
|
||||
// InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
|
||||
// If it's missing that, it's an error.
|
||||
if (token instanceof InjectionToken) {
|
||||
throw new Error(`Token ${stringify(token)} is missing an ngInjectableDef definition.`);
|
||||
throw new Error(`Token ${stringify(token)} is missing a ɵprov definition.`);
|
||||
}
|
||||
|
||||
// Undecorated types can sometimes be created if they have no constructor arguments.
|
||||
@ -447,8 +447,8 @@ function getUndecoratedInjectableFactory(token: Function) {
|
||||
}
|
||||
|
||||
// The constructor function appears to have no parameters.
|
||||
// This might be because it inherits from a super-class. In which case, use an ngInjectableDef
|
||||
// from an ancestor if there is one.
|
||||
// This might be because it inherits from a super-class. In which case, use an injectable
|
||||
// def from an ancestor if there is one.
|
||||
// Otherwise this really is a simple class with no dependencies, so return a factory that
|
||||
// just instantiates the zero-arg constructor.
|
||||
const inheritedInjectableDef = getInheritedInjectableDef(token);
|
||||
|
@ -331,9 +331,9 @@ The above will create the following layout:
|
||||
| `EXPANDO`
|
||||
| 11..18| cumulativeBloom | templateBloom
|
||||
| | *sub-section: `component` and `directives`*
|
||||
| 19 | `factory(Child.ɵcmp.factory)`* | `Child`
|
||||
| 19 | `factory(Child.ɵcmp.factory)`* | `Child`
|
||||
| | *sub-section: `providers`*
|
||||
| 20 | `factory(ServiceA.ngInjectableDef.factory)`* | `ServiceA`
|
||||
| 20 | `factory(ServiceA.ɵprov.factory)`* | `ServiceA`
|
||||
| 22 | `'someServiceBValue'`* | `ServiceB`
|
||||
| | *sub-section: `viewProviders`*
|
||||
| 22 | `factory(()=> new Service())`* | `ServiceC`
|
||||
@ -420,7 +420,7 @@ A pseudo-implementation of `inject` function.
|
||||
```typescript
|
||||
function inject(token: any): any {
|
||||
let injectableDef;
|
||||
if (typeof token === 'function' && injectableDef = token.ngInjectableDef) {
|
||||
if (typeof token === 'function' && injectableDef = token.ɵprov) {
|
||||
const provideIn = injectableDef.provideIn;
|
||||
if (provideIn === '__node_injector__') {
|
||||
// if we are injecting `Injector` than create a wrapper object around the inject but which
|
||||
|
@ -17,7 +17,7 @@ import {SecurityContext} from './security';
|
||||
export abstract class Sanitizer {
|
||||
abstract sanitize(context: SecurityContext, value: {}|string|null): string|null;
|
||||
/** @nocollapse */
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: Sanitizer,
|
||||
providedIn: 'root',
|
||||
factory: () => null,
|
||||
|
@ -29,9 +29,15 @@
|
||||
{
|
||||
"name": "NG_INJECTABLE_DEF"
|
||||
},
|
||||
{
|
||||
"name": "NG_INJECTOR_DEF"
|
||||
},
|
||||
{
|
||||
"name": "NG_INJ_DEF"
|
||||
},
|
||||
{
|
||||
"name": "NG_PROV_DEF"
|
||||
},
|
||||
{
|
||||
"name": "NG_TEMP_TOKEN_PATH"
|
||||
},
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {Injector, ɵcreateInjector as createInjector, ɵɵdefineInjectable, ɵɵdefineInjector} from '@angular/core';
|
||||
|
||||
export class RootService {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: RootService,
|
||||
providedIn: 'root',
|
||||
factory: () => new RootService(),
|
||||
@ -17,7 +17,7 @@ export class RootService {
|
||||
}
|
||||
|
||||
export class ScopedService {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: ScopedService,
|
||||
providedIn: null,
|
||||
factory: () => new ScopedService(),
|
||||
|
@ -140,6 +140,9 @@
|
||||
{
|
||||
"name": "NG_PIPE_DEF"
|
||||
},
|
||||
{
|
||||
"name": "NG_PROV_DEF"
|
||||
},
|
||||
{
|
||||
"name": "NG_TEMPLATE_SELECTOR"
|
||||
},
|
||||
|
@ -12,7 +12,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
describe('InjectorDef-based createInjector()', () => {
|
||||
class CircularA {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: CircularA,
|
||||
providedIn: null,
|
||||
factory: () => ɵɵinject(CircularB),
|
||||
@ -20,7 +20,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
}
|
||||
|
||||
class CircularB {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: CircularB,
|
||||
providedIn: null,
|
||||
factory: () => ɵɵinject(CircularA),
|
||||
@ -28,7 +28,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
}
|
||||
|
||||
class Service {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: Service,
|
||||
providedIn: null,
|
||||
factory: () => new Service(),
|
||||
@ -36,7 +36,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
}
|
||||
|
||||
class OptionalService {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: OptionalService,
|
||||
providedIn: null,
|
||||
factory: () => new OptionalService(),
|
||||
@ -59,7 +59,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
class ServiceWithDep {
|
||||
constructor(readonly service: Service) {}
|
||||
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: ServiceWithDep,
|
||||
providedIn: null,
|
||||
// ChildService is derived from ServiceWithDep, so the factory function here must do the right
|
||||
@ -71,7 +71,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
class ServiceWithOptionalDep {
|
||||
constructor(@Optional() readonly service: OptionalService|null) {}
|
||||
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: ServiceWithOptionalDep,
|
||||
providedIn: null,
|
||||
factory: () => new ServiceWithOptionalDep(ɵɵinject(OptionalService, InjectFlags.Optional)),
|
||||
@ -81,7 +81,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
class ServiceWithMissingDep {
|
||||
constructor(readonly service: Service) {}
|
||||
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: ServiceWithMissingDep,
|
||||
providedIn: null,
|
||||
factory: () => new ServiceWithMissingDep(ɵɵinject(Service)),
|
||||
@ -91,7 +91,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
class ServiceWithMultiDep {
|
||||
constructor(readonly locale: string[]) {}
|
||||
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: ServiceWithMultiDep,
|
||||
providedIn: null,
|
||||
factory: () => new ServiceWithMultiDep(ɵɵinject(LOCALE)),
|
||||
@ -99,7 +99,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
}
|
||||
|
||||
class ServiceTwo {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: ServiceTwo,
|
||||
providedIn: null,
|
||||
factory: () => new ServiceTwo(),
|
||||
@ -108,7 +108,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
|
||||
let deepServiceDestroyed = false;
|
||||
class DeepService {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: DeepService,
|
||||
providedIn: null,
|
||||
factory: () => new DeepService(),
|
||||
@ -119,7 +119,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
|
||||
let eagerServiceCreated: boolean = false;
|
||||
class EagerService {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: EagerService,
|
||||
providedIn: undefined,
|
||||
factory: () => new EagerService(),
|
||||
@ -218,7 +218,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
|
||||
let scopedServiceDestroyed = false;
|
||||
class ScopedService {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: ScopedService,
|
||||
providedIn: Module,
|
||||
factory: () => new ScopedService(),
|
||||
@ -228,7 +228,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
}
|
||||
|
||||
class WrongScopeService {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: WrongScopeService,
|
||||
providedIn: OtherModule,
|
||||
factory: () => new WrongScopeService(),
|
||||
|
@ -1387,7 +1387,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
}
|
||||
|
||||
class Bar {
|
||||
static ngInjectableDef: ɵɵInjectableDef<Bar> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<Bar> = ɵɵdefineInjectable({
|
||||
token: Bar,
|
||||
factory: () => new Bar(),
|
||||
providedIn: SomeModule,
|
||||
@ -1420,7 +1420,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
}
|
||||
|
||||
class Bar {
|
||||
static ngInjectableDef: ɵɵInjectableDef<Bar> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<Bar> = ɵɵdefineInjectable({
|
||||
token: Bar,
|
||||
factory: () => new Bar(),
|
||||
providedIn: SomeModule,
|
||||
|
@ -63,7 +63,7 @@ describe('component', () => {
|
||||
|
||||
class MyService {
|
||||
constructor(public value: string) {}
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: MyService,
|
||||
providedIn: 'root',
|
||||
factory: () => new MyService('no-injector'),
|
||||
|
@ -43,8 +43,8 @@ ivyEnabled && describe('render3 jit', () => {
|
||||
}
|
||||
const ServiceAny = Service as any;
|
||||
|
||||
expect(ServiceAny.ngInjectableDef).toBeDefined();
|
||||
expect(ServiceAny.ngInjectableDef.providedIn).toBe('root');
|
||||
expect(ServiceAny.ɵprov).toBeDefined();
|
||||
expect(ServiceAny.ɵprov.providedIn).toBe('root');
|
||||
expect(ɵɵinject(Service) instanceof Service).toBe(true);
|
||||
});
|
||||
|
||||
@ -167,7 +167,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||
|
||||
it('compiles a module to an ɵinj with the providers', () => {
|
||||
class Token {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: Token,
|
||||
providedIn: 'root',
|
||||
factory: () => 'default',
|
||||
|
@ -58,7 +58,7 @@ describe('providers', () => {
|
||||
public greet: string;
|
||||
constructor(private provider: GreeterProvider) { this.greet = this.provider.provide(); }
|
||||
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: GreeterInj,
|
||||
factory: () => new GreeterInj(ɵɵinject(GreeterProvider as any)),
|
||||
});
|
||||
@ -816,7 +816,7 @@ describe('providers', () => {
|
||||
it('should work with root', () => {
|
||||
@Injectable({providedIn: 'root'})
|
||||
class FooForRoot {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: FooForRoot,
|
||||
factory: () => new FooForRoot(),
|
||||
providedIn: 'root',
|
||||
@ -841,7 +841,7 @@ describe('providers', () => {
|
||||
|
||||
@Injectable({providedIn: MyModule})
|
||||
class FooForModule {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: FooForModule,
|
||||
factory: () => new FooForModule(),
|
||||
providedIn: MyModule,
|
||||
@ -1168,7 +1168,7 @@ describe('providers', () => {
|
||||
class MyService {
|
||||
constructor(public value: String) {}
|
||||
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: MyService,
|
||||
factory: () => new MyService(ɵɵinject(String)),
|
||||
});
|
||||
@ -1188,7 +1188,7 @@ describe('providers', () => {
|
||||
|
||||
it('should make sure that parent service does not see overrides in child directives', () => {
|
||||
class Greeter {
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: Greeter,
|
||||
factory: () => new Greeter(ɵɵinject(String)),
|
||||
});
|
||||
@ -1233,7 +1233,7 @@ describe('providers', () => {
|
||||
class SomeInj implements Some {
|
||||
constructor(public location: String) {}
|
||||
|
||||
static ngInjectableDef = ɵɵdefineInjectable({
|
||||
static ɵprov = ɵɵdefineInjectable({
|
||||
token: SomeInj,
|
||||
factory: () => new SomeInj(ɵɵinject(String)),
|
||||
});
|
||||
|
@ -25,7 +25,7 @@ class MyChildModule {}
|
||||
class NotMyModule {}
|
||||
|
||||
class Bar {
|
||||
static ngInjectableDef: ɵɵInjectableDef<Bar> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<Bar> = ɵɵdefineInjectable({
|
||||
token: Bar,
|
||||
factory: () => new Bar(),
|
||||
providedIn: MyModule,
|
||||
@ -33,7 +33,7 @@ class Bar {
|
||||
}
|
||||
|
||||
class Baz {
|
||||
static ngInjectableDef: ɵɵInjectableDef<Baz> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<Baz> = ɵɵdefineInjectable({
|
||||
token: Baz,
|
||||
factory: () => new Baz(),
|
||||
providedIn: NotMyModule,
|
||||
@ -43,7 +43,7 @@ class Baz {
|
||||
class HasNormalDep {
|
||||
constructor(public foo: Foo) {}
|
||||
|
||||
static ngInjectableDef: ɵɵInjectableDef<HasNormalDep> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<HasNormalDep> = ɵɵdefineInjectable({
|
||||
token: HasNormalDep,
|
||||
factory: () => new HasNormalDep(inject(Foo)),
|
||||
providedIn: MyModule,
|
||||
@ -53,7 +53,7 @@ class HasNormalDep {
|
||||
class HasDefinedDep {
|
||||
constructor(public bar: Bar) {}
|
||||
|
||||
static ngInjectableDef: ɵɵInjectableDef<HasDefinedDep> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<HasDefinedDep> = ɵɵdefineInjectable({
|
||||
token: HasDefinedDep,
|
||||
factory: () => new HasDefinedDep(inject(Bar)),
|
||||
providedIn: MyModule,
|
||||
@ -63,7 +63,7 @@ class HasDefinedDep {
|
||||
class HasOptionalDep {
|
||||
constructor(public baz: Baz|null) {}
|
||||
|
||||
static ngInjectableDef: ɵɵInjectableDef<HasOptionalDep> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<HasOptionalDep> = ɵɵdefineInjectable({
|
||||
token: HasOptionalDep,
|
||||
factory: () => new HasOptionalDep(inject(Baz, InjectFlags.Optional)),
|
||||
providedIn: MyModule,
|
||||
@ -71,7 +71,7 @@ class HasOptionalDep {
|
||||
}
|
||||
|
||||
class ChildDep {
|
||||
static ngInjectableDef: ɵɵInjectableDef<ChildDep> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<ChildDep> = ɵɵdefineInjectable({
|
||||
token: ChildDep,
|
||||
factory: () => new ChildDep(),
|
||||
providedIn: MyChildModule,
|
||||
@ -80,7 +80,7 @@ class ChildDep {
|
||||
|
||||
class FromChildWithOptionalDep {
|
||||
constructor(public baz: Baz|null) {}
|
||||
static ngInjectableDef: ɵɵInjectableDef<FromChildWithOptionalDep> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<FromChildWithOptionalDep> = ɵɵdefineInjectable({
|
||||
token: FromChildWithOptionalDep,
|
||||
factory: () => new FromChildWithOptionalDep(inject(Baz, InjectFlags.Default)),
|
||||
providedIn: MyChildModule,
|
||||
@ -91,7 +91,7 @@ class FromChildWithSkipSelfDep {
|
||||
constructor(
|
||||
public skipSelfChildDep: ChildDep|null, public selfChildDep: ChildDep|null,
|
||||
public optionalSelfBar: Bar|null) {}
|
||||
static ngInjectableDef: ɵɵInjectableDef<FromChildWithSkipSelfDep> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<FromChildWithSkipSelfDep> = ɵɵdefineInjectable({
|
||||
token: FromChildWithSkipSelfDep,
|
||||
factory: () => new FromChildWithSkipSelfDep(
|
||||
inject(ChildDep, InjectFlags.SkipSelf|InjectFlags.Optional),
|
||||
@ -215,7 +215,7 @@ describe('NgModuleRef_ injector', () => {
|
||||
|
||||
ngOnDestroy(): void { Service.destroyed++; }
|
||||
|
||||
static ngInjectableDef: ɵɵInjectableDef<Service> = ɵɵdefineInjectable({
|
||||
static ɵprov: ɵɵInjectableDef<Service> = ɵɵdefineInjectable({
|
||||
token: Service,
|
||||
factory: () => new Service(),
|
||||
providedIn: 'root',
|
||||
|
Reference in New Issue
Block a user