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IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACzD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACnD,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7C;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport { Injector, THROW_IF_NOT_FOUND } from './injector';\nimport { Self, SkipSelf } from './metadata';\nimport { Provider } from './provider';\nimport { cyclicDependencyError, instantiationError, noProviderError, outOfBoundsError } from './reflective_errors';\nimport { ReflectiveKey } from './reflective_key';\nimport {\n ReflectiveDependency,\n ResolvedReflectiveFactory,\n ResolvedReflectiveProvider,\n resolveReflectiveProviders,\n} from './reflective_provider';\n\n// Threshold for the dynamic version\nconst UNDEFINED = new Object();\n\n/**\n * A ReflectiveDependency injection container used for instantiating objects and resolving\n * dependencies.\n *\n * An `Injector` is a replacement for a `new` operator, which can automatically resolve the\n * constructor dependencies.\n *\n * In typical use, application code asks for the dependencies in the constructor and they are\n * resolved by the `Injector`.\n *\n * ### Example ([live demo](http://plnkr.co/edit/jzjec0?p=preview))\n *\n * The following example creates an `Injector` configured to create `Engine` and `Car`.\n *\n * ```typescript\n * @Injectable()\n * class Engine {\n * }\n *\n * @Injectable()\n * class Car {\n * constructor(public engine:Engine) {}\n * }\n *\n * var injector = ReflectiveInjector.resolveAndCreate([Car, Engine]);\n * var car = injector.get(Car);\n * expect(car instanceof Car).toBe(true);\n * expect(car.engine instanceof Engine).toBe(true);\n * ```\n *\n * Notice, we don't use the `new` operator because we explicitly want to have the `Injector`\n * resolve all of the object's dependencies automatically.\n *\n * @stable\n */\nexport abstract class ReflectiveInjector implements Injector {\n /**\n * Turns an array of provider definitions into an array of resolved providers.\n *\n * A resolution is a process of flattening multiple nested arrays and converting individual\n * providers into an array of {@link ResolvedReflectiveProvider}s.\n *\n * ### Example ([live demo](http://plnkr.co/edit/AiXTHi?p=preview))\n *\n * ```typescript\n * @Injectable()\n * class Engine {\n * }\n *\n * @Injectable()\n * class Car {\n * constructor(public engine:Engine) {}\n * }\n *\n * var providers = ReflectiveInjector.resolve([Car, [[Engine]]]);\n *\n * expect(providers.length).toEqual(2);\n *\n * expect(providers[0] instanceof ResolvedReflectiveProvider).toBe(true);\n * expect(providers[0].key.displayName).toBe(\"Car\");\n * expect(providers[0].dependencies.length).toEqual(1);\n * expect(providers[0].factory).toBeDefined();\n *\n * expect(providers[1].key.displayName).toBe(\"Engine\");\n * });\n * ```\n *\n * See {@link ReflectiveInjector#fromResolvedProviders} for more info.\n */\n static resolve(providers: Provider[]): ResolvedReflectiveProvider[] {\n return resolveReflectiveProviders(providers);\n }\n\n /**\n * Resolves an array of providers and creates an injector from those providers.\n *\n * The passed-in providers can be an array of `Type`, {@link Provider},\n * or a recursive array of more providers.\n *\n * ### Example ([live demo](http://plnkr.co/edit/ePOccA?p=preview))\n *\n * ```typescript\n * @Injectable()\n * class Engine {\n * }\n *\n * @Injectable()\n * class Car {\n * constructor(public engine:Engine) {}\n * }\n *\n * var injector = ReflectiveInjector.resolveAndCreate([Car, Engine]);\n * expect(injector.get(Car) instanceof Car).toBe(true);\n * ```\n *\n * This function is slower than the corresponding `fromResolvedProviders`\n * because it needs to resolve the passed-in providers first.\n * See {@link Injector#resolve} and {@link Injector#fromResolvedProviders}.\n */\n static resolveAndCreate(providers: Provider[], parent?: Injector): ReflectiveInjector {\n const ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);\n return ReflectiveInjector.fromResolvedProviders(ResolvedReflectiveProviders, parent);\n }\n\n /**\n * Creates an injector from previously resolved providers.\n *\n * This API is the recommended way to construct injectors in performance-sensitive parts.\n *\n * ### Example ([live demo](http://plnkr.co/edit/KrSMci?p=preview))\n *\n * ```typescript\n * @Injectable()\n * class Engine {\n * }\n *\n * @Injectable()\n * class Car {\n * constructor(public engine:Engine) {}\n * }\n *\n * var providers = ReflectiveInjector.resolve([Car, Engine]);\n * var injector = ReflectiveInjector.fromResolvedProviders(providers);\n * expect(injector.get(Car) instanceof Car).toBe(true);\n * ```\n * @experimental\n */\n static fromResolvedProviders(providers: ResolvedReflectiveProvider[], parent?: Injector): ReflectiveInjector {\n // tslint:disable-next-line:no-use-before-declare\n return new ReflectiveInjector_(providers, parent);\n }\n\n /**\n * Parent of this injector.\n *\n * <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection.\n * -->\n *\n * ### Example ([live demo](http://plnkr.co/edit/eosMGo?p=preview))\n *\n * ```typescript\n * var parent = ReflectiveInjector.resolveAndCreate([]);\n * var child = parent.resolveAndCreateChild([]);\n * expect(child.parent).toBe(parent);\n * ```\n */\n abstract get parent(): Injector | null;\n\n /**\n * Resolves an array of providers and creates a child injector from those providers.\n *\n * <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection.\n * -->\n *\n * The passed-in providers can be an array of `Type`, {@link Provider},\n * or a recursive array of more providers.\n *\n * ### Example ([live demo](http://plnkr.co/edit/opB3T4?p=preview))\n *\n * ```typescript\n * class ParentProvider {}\n * class ChildProvider {}\n *\n * var parent = ReflectiveInjector.resolveAndCreate([ParentProvider]);\n * var child = parent.resolveAndCreateChild([ChildProvider]);\n *\n * expect(child.get(ParentProvider) instanceof ParentProvider).toBe(true);\n * expect(child.get(ChildProvider) instanceof ChildProvider).toBe(true);\n * expect(child.get(ParentProvider)).toBe(parent.get(ParentProvider));\n * ```\n *\n * This function is slower than the corresponding `createChildFromResolved`\n * because it needs to resolve the passed-in providers first.\n * See {@link Injector#resolve} and {@link Injector#createChildFromResolved}.\n */\n abstract resolveAndCreateChild(providers: Provider[]): ReflectiveInjector;\n\n /**\n * Creates a child injector from previously resolved providers.\n *\n * <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection.\n * -->\n *\n * This API is the recommended way to construct injectors in performance-sensitive parts.\n *\n * ### Example ([live demo](http://plnkr.co/edit/VhyfjN?p=preview))\n *\n * ```typescript\n * class ParentProvider {}\n * class ChildProvider {}\n *\n * var parentProviders = ReflectiveInjector.resolve([ParentProvider]);\n * var childProviders = ReflectiveInjector.resolve([ChildProvider]);\n *\n * var parent = ReflectiveInjector.fromResolvedProviders(parentProviders);\n * var child = parent.createChildFromResolved(childProviders);\n *\n * expect(child.get(ParentProvider) instanceof ParentProvider).toBe(true);\n * expect(child.get(ChildProvider) instanceof ChildProvider).toBe(true);\n * expect(child.get(ParentProvider)).toBe(parent.get(ParentProvider));\n * ```\n */\n abstract createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector;\n\n /**\n * Resolves a provider and instantiates an object in the context of the injector.\n *\n * The created object does not get cached by the injector.\n *\n * ### Example ([live demo](http://plnkr.co/edit/yvVXoB?p=preview))\n *\n * ```typescript\n * @Injectable()\n * class Engine {\n * }\n *\n * @Injectable()\n * class Car {\n * constructor(public engine:Engine) {}\n * }\n *\n * var injector = ReflectiveInjector.resolveAndCreate([Engine]);\n *\n * var car = injector.resolveAndInstantiate(Car);\n * expect(car.engine).toBe(injector.get(Engine));\n * expect(car).not.toBe(injector.resolveAndInstantiate(Car));\n * ```\n */\n abstract resolveAndInstantiate(provider: Provider): any;\n\n /**\n * Instantiates an object using a resolved provider in the context of the injector.\n *\n * The created object does not get cached by the injector.\n *\n * ### Example ([live demo](http://plnkr.co/edit/ptCImQ?p=preview))\n *\n * ```typescript\n * @Injectable()\n * class Engine {\n * }\n *\n * @Injectable()\n * class Car {\n * constructor(public engine:Engine) {}\n * }\n *\n * var injector = ReflectiveInjector.resolveAndCreate([Engine]);\n * var carProvider = ReflectiveInjector.resolve([Car])[0];\n * var car = injector.instantiateResolved(carProvider);\n * expect(car.engine).toBe(injector.get(Engine));\n * expect(car).not.toBe(injector.instantiateResolved(carProvider));\n * ```\n */\n abstract instantiateResolved(provider: ResolvedReflectiveProvider): any;\n\n abstract get(token: any, notFoundValue?: any): any;\n}\n\n// tslint:disable-next-line:class-name\nexport class ReflectiveInjector_ implements ReflectiveInjector {\n /** @internal */\n _constructionCounter: number = 0;\n /** @internal */\n public _providers: ResolvedReflectiveProvider[];\n /** @internal */\n public _parent: Injector | null;\n\n keyIds: number[];\n objs: any[];\n /**\n * Private\n */\n constructor(_providers: ResolvedReflectiveProvider[], _parent?: Injector) {\n this._providers = _providers;\n this._parent = _parent || null;\n\n const len = _providers.length;\n\n this.keyIds = new Array(len);\n this.objs = new Array(len);\n\n for (let i = 0; i < len; i++) {\n this.keyIds[i] = _providers[i].key.id;\n this.objs[i] = UNDEFINED;\n }\n }\n\n get(token: any, notFoundValue: any = THROW_IF_NOT_FOUND): any {\n return this._getByKey(ReflectiveKey.get(token), null, notFoundValue);\n }\n\n get parent(): Injector | null {\n return this._parent;\n }\n\n resolveAndCreateChild(providers: Provider[]): ReflectiveInjector {\n const ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);\n return this.createChildFromResolved(ResolvedReflectiveProviders);\n }\n\n createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector {\n const inj = new ReflectiveInjector_(providers);\n inj._parent = this;\n return inj;\n }\n\n resolveAndInstantiate(provider: Provider): any {\n return this.instantiateResolved(ReflectiveInjector.resolve([provider])[0]);\n }\n\n instantiateResolved(provider: ResolvedReflectiveProvider): any {\n return this._instantiateProvider(provider);\n }\n\n getProviderAtIndex(index: number): ResolvedReflectiveProvider {\n if (index < 0 || index >= this._providers.length) {\n throw outOfBoundsError(index);\n }\n return this._providers[index];\n }\n\n /** @internal */\n _new(provider: ResolvedReflectiveProvider): any {\n if (this._constructionCounter++ > this._getMaxNumberOfObjects()) {\n throw cyclicDependencyError(this, provider.key);\n }\n return this._instantiateProvider(provider);\n }\n\n private _getMaxNumberOfObjects(): number {\n return this.objs.length;\n }\n\n private _instantiateProvider(provider: ResolvedReflectiveProvider): any {\n if (provider.multiProvider) {\n const res = new Array(provider.resolvedFactories.length);\n for (let i = 0; i < provider.resolvedFactories.length; ++i) {\n res[i] = this._instantiate(provider, provider.resolvedFactories[i]);\n }\n return res;\n } else {\n return this._instantiate(provider, provider.resolvedFactories[0]);\n }\n }\n\n private _instantiate(provider: ResolvedReflectiveProvider, ResolvedReflectiveFactory: ResolvedReflectiveFactory): any {\n const factory = ResolvedReflectiveFactory.factory;\n\n let deps: any[];\n try {\n deps = ResolvedReflectiveFactory.dependencies.map(dep => this._getByReflectiveDependency(dep));\n } catch (e) {\n if (e.addKey) {\n e.addKey(this, provider.key);\n }\n throw e;\n }\n\n let obj: any;\n try {\n obj = factory(...deps);\n } catch (e) {\n throw instantiationError(this, e, e.stack, provider.key);\n }\n\n return obj;\n }\n\n private _getByReflectiveDependency(dep: ReflectiveDependency): any {\n return this._getByKey(dep.key, dep.visibility, dep.optional ? null : THROW_IF_NOT_FOUND);\n }\n\n private _getByKey(key: ReflectiveKey, visibility: Self | SkipSelf | null, notFoundValue: any): any {\n // tslint:disable-next-line:no-use-before-declare\n if (key === INJECTOR_KEY) {\n return this;\n }\n\n if (visibility instanceof Self) {\n return this._getByKeySelf(key, notFoundValue);\n } else {\n return this._getByKeyDefault(key, notFoundValue, visibility);\n }\n }\n\n private _getObjByKeyId(keyId: number): any {\n for (let i = 0; i < this.keyIds.length; i++) {\n if (this.keyIds[i] === keyId) {\n if (this.objs[i] === UNDEFINED) {\n this.objs[i] = this._new(this._providers[i]);\n }\n\n return this.objs[i];\n }\n }\n\n return UNDEFINED;\n }\n\n /** @internal */\n _throwOrNull(key: ReflectiveKey, notFoundValue: any): any {\n if (notFoundValue !== THROW_IF_NOT_FOUND) {\n return notFoundValue;\n } else {\n throw noProviderError(this, key);\n }\n }\n\n /** @internal */\n _getByKeySelf(key: ReflectiveKey, notFoundValue: any): any {\n const obj = this._getObjByKeyId(key.id);\n return obj !== UNDEFINED ? obj : this._throwOrNull(key, notFoundValue);\n }\n\n /** @internal */\n _getByKeyDefault(key: ReflectiveKey, notFoundValue: any, visibility: Self | SkipSelf | null): any {\n let inj: Injector | null;\n\n if (visibility instanceof SkipSelf) {\n inj = this._parent;\n } else {\n inj = this;\n }\n\n while (inj instanceof ReflectiveInjector_) {\n const inj_ = <ReflectiveInjector_>inj;\n const obj = inj_._getObjByKeyId(key.id);\n if (obj !== UNDEFINED) return obj;\n inj = inj_._parent;\n }\n if (inj !== null) {\n return inj.get(key.token, notFoundValue);\n } else {\n return this._throwOrNull(key, notFoundValue);\n }\n }\n\n get displayName(): string {\n const providers = _mapProviders(this, (b: ResolvedReflectiveProvider) => ' \"' + b.key.displayName + '\" ').join(', ');\n return `ReflectiveInjector(providers: [${providers}])`;\n }\n\n toString(): string {\n return this.displayName;\n }\n}\n\nconst INJECTOR_KEY = ReflectiveKey.get(Injector);\n\nfunction _mapProviders(injector: ReflectiveInjector_, fn: Function): any[] {\n const res: any[] = new Array(injector._providers.length);\n for (let i = 0; i < injector._providers.length; ++i) {\n res[i] = fn(injector.getProviderAtIndex(i));\n }\n return res;\n}\n"]}
\No newline at end of file