UNPKG

@angular/core

Version:

Angular - the core framework

1,447 lines (1,426 loc) 1.69 MB
/** * @license Angular v9.1.11 * (c) 2010-2020 Google LLC. https://angular.io/ * License: MIT */ import { Subject, Subscription, Observable, merge as merge$1 } from 'rxjs'; import { share } from 'rxjs/operators'; /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Convince closure compiler that the wrapped function has no side-effects. * * Closure compiler always assumes that `toString` has no side-effects. We use this quirk to * allow us to execute a function but have closure compiler mark the call as no-side-effects. * It is important that the return value for the `noSideEffects` function be assigned * to something which is retained otherwise the call to `noSideEffects` will be removed by closure * compiler. */ function noSideEffects(fn) { return { toString: fn }.toString(); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ const ANNOTATIONS = '__annotations__'; const PARAMETERS = '__parameters__'; const PROP_METADATA = '__prop__metadata__'; /** * @suppress {globalThis} */ function makeDecorator(name, props, parentClass, additionalProcessing, typeFn) { return noSideEffects(() => { const metaCtor = makeMetadataCtor(props); function DecoratorFactory(...args) { if (this instanceof DecoratorFactory) { metaCtor.call(this, ...args); return this; } const annotationInstance = new DecoratorFactory(...args); return function TypeDecorator(cls) { if (typeFn) typeFn(cls, ...args); // Use of Object.defineProperty is important since it creates non-enumerable property which // prevents the property is copied during subclassing. const annotations = cls.hasOwnProperty(ANNOTATIONS) ? cls[ANNOTATIONS] : Object.defineProperty(cls, ANNOTATIONS, { value: [] })[ANNOTATIONS]; annotations.push(annotationInstance); if (additionalProcessing) additionalProcessing(cls); return cls; }; } if (parentClass) { DecoratorFactory.prototype = Object.create(parentClass.prototype); } DecoratorFactory.prototype.ngMetadataName = name; DecoratorFactory.annotationCls = DecoratorFactory; return DecoratorFactory; }); } function makeMetadataCtor(props) { return function ctor(...args) { if (props) { const values = props(...args); for (const propName in values) { this[propName] = values[propName]; } } }; } function makeParamDecorator(name, props, parentClass) { return noSideEffects(() => { const metaCtor = makeMetadataCtor(props); function ParamDecoratorFactory(...args) { if (this instanceof ParamDecoratorFactory) { metaCtor.apply(this, args); return this; } const annotationInstance = new ParamDecoratorFactory(...args); ParamDecorator.annotation = annotationInstance; return ParamDecorator; function ParamDecorator(cls, unusedKey, index) { // Use of Object.defineProperty is important since it creates non-enumerable property which // prevents the property is copied during subclassing. const parameters = cls.hasOwnProperty(PARAMETERS) ? cls[PARAMETERS] : Object.defineProperty(cls, PARAMETERS, { value: [] })[PARAMETERS]; // there might be gaps if some in between parameters do not have annotations. // we pad with nulls. while (parameters.length <= index) { parameters.push(null); } (parameters[index] = parameters[index] || []).push(annotationInstance); return cls; } } if (parentClass) { ParamDecoratorFactory.prototype = Object.create(parentClass.prototype); } ParamDecoratorFactory.prototype.ngMetadataName = name; ParamDecoratorFactory.annotationCls = ParamDecoratorFactory; return ParamDecoratorFactory; }); } function makePropDecorator(name, props, parentClass, additionalProcessing) { return noSideEffects(() => { const metaCtor = makeMetadataCtor(props); function PropDecoratorFactory(...args) { if (this instanceof PropDecoratorFactory) { metaCtor.apply(this, args); return this; } const decoratorInstance = new PropDecoratorFactory(...args); function PropDecorator(target, name) { const constructor = target.constructor; // Use of Object.defineProperty is important since it creates non-enumerable property which // prevents the property is copied during subclassing. const meta = constructor.hasOwnProperty(PROP_METADATA) ? constructor[PROP_METADATA] : Object.defineProperty(constructor, PROP_METADATA, { value: {} })[PROP_METADATA]; meta[name] = meta.hasOwnProperty(name) && meta[name] || []; meta[name].unshift(decoratorInstance); if (additionalProcessing) additionalProcessing(target, name, ...args); } return PropDecorator; } if (parentClass) { PropDecoratorFactory.prototype = Object.create(parentClass.prototype); } PropDecoratorFactory.prototype.ngMetadataName = name; PropDecoratorFactory.annotationCls = PropDecoratorFactory; return PropDecoratorFactory; }); } /** * @fileoverview added by tsickle * Generated from: packages/core/src/di/metadata.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Type of the Inject decorator / constructor function. * * \@publicApi * @record */ function InjectDecorator() { } // WARNING: interface has both a type and a value, skipping emit const ɵ0 = /** * @param {?} token * @return {?} */ (token) => ({ token }); /** * Inject decorator and metadata. * * \@Annotation * \@publicApi * @type {?} */ const Inject = makeParamDecorator('Inject', (ɵ0)); /** * Type of the Optional decorator / constructor function. * * \@publicApi * @record */ function OptionalDecorator() { } // WARNING: interface has both a type and a value, skipping emit /** * Optional decorator and metadata. * * \@Annotation * \@publicApi * @type {?} */ const Optional = makeParamDecorator('Optional'); /** * Type of the Self decorator / constructor function. * * \@publicApi * @record */ function SelfDecorator() { } // WARNING: interface has both a type and a value, skipping emit /** * Self decorator and metadata. * * \@Annotation * \@publicApi * @type {?} */ const Self = makeParamDecorator('Self'); /** * Type of the SkipSelf decorator / constructor function. * * \@publicApi * @record */ function SkipSelfDecorator() { } // WARNING: interface has both a type and a value, skipping emit /** * SkipSelf decorator and metadata. * * \@Annotation * \@publicApi * @type {?} */ const SkipSelf = makeParamDecorator('SkipSelf'); /** * Type of the Host decorator / constructor function. * * \@publicApi * @record */ function HostDecorator() { } // WARNING: interface has both a type and a value, skipping emit /** * Host decorator and metadata. * * \@Annotation * \@publicApi * @type {?} */ const Host = makeParamDecorator('Host'); /** * Type of the Attribute decorator / constructor function. * * \@publicApi * @record */ function AttributeDecorator() { } // WARNING: interface has both a type and a value, skipping emit const ɵ1 = /** * @param {?=} attributeName * @return {?} */ (attributeName) => ({ attributeName }); /** * Attribute decorator and metadata. * * \@Annotation * \@publicApi * @type {?} */ const Attribute = makeParamDecorator('Attribute', (ɵ1)); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Injection flags for DI. * * @publicApi */ var InjectFlags; (function (InjectFlags) { // TODO(alxhub): make this 'const' when ngc no longer writes exports of it into ngfactory files. /** Check self and check parent injector if needed */ InjectFlags[InjectFlags["Default"] = 0] = "Default"; /** * Specifies that an injector should retrieve a dependency from any injector until reaching the * host element of the current component. (Only used with Element Injector) */ InjectFlags[InjectFlags["Host"] = 1] = "Host"; /** Don't ascend to ancestors of the node requesting injection. */ InjectFlags[InjectFlags["Self"] = 2] = "Self"; /** Skip the node that is requesting injection. */ InjectFlags[InjectFlags["SkipSelf"] = 4] = "SkipSelf"; /** Inject `defaultValue` instead if token not found. */ InjectFlags[InjectFlags["Optional"] = 8] = "Optional"; })(InjectFlags || (InjectFlags = {})); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function getClosureSafeProperty(objWithPropertyToExtract) { for (let key in objWithPropertyToExtract) { if (objWithPropertyToExtract[key] === getClosureSafeProperty) { return key; } } throw Error('Could not find renamed property on target object.'); } /** * Sets properties on a target object from a source object, but only if * the property doesn't already exist on the target object. * @param target The target to set properties on * @param source The source of the property keys and values to set */ function fillProperties(target, source) { for (const key in source) { if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) { target[key] = source[key]; } } } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * 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 `ɵprov` field on a type, which will then be an * `InjectableType`. * * Options: * * `providedIn` determines which injectors will include the injectable, by either associating it * with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be * provided in the `'root'` injector, which will be the application-level injector in most apps. * * `factory` gives the zero argument function which will create an instance of the injectable. * The factory can call `inject` to access the `Injector` and request injection of dependencies. * * @codeGenApi */ function ɵɵdefineInjectable(opts) { return { token: opts.token, providedIn: opts.providedIn || null, factory: opts.factory, value: undefined, }; } /** * @deprecated in v8, delete after v10. This API should be used only be generated code, and that * code should now use ɵɵdefineInjectable instead. * @publicApi */ const defineInjectable = ɵɵdefineInjectable; /** * Construct an `InjectorDef` which configures an injector. * * This should be assigned to a static injector def (`ɵinj`) field on a type, which will then be an * `InjectorType`. * * Options: * * * `factory`: an `InjectorType` is an instantiable type, so a zero argument `factory` function to * 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 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 * providers from imports. * * @publicApi */ function ɵɵdefineInjector(options) { return { factory: options.factory, providers: options.providers || [], imports: options.imports || [], }; } /** * 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) `ɵprov`. */ function getInjectableDef(type) { return getOwnDefinition(type, type[NG_PROV_DEF]) || getOwnDefinition(type, type[NG_INJECTABLE_DEF]); } /** * Return `def` only if it is defined directly on `type` and is not inherited from a base * class of `type`. * * The function `Object.hasOwnProperty` is not sufficient to distinguish this case because in older * browsers (e.g. IE10) static property inheritance is implemented by copying the properties. * * Instead, the definition'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`. */ function getOwnDefinition(type, def) { return def && def.token === type ? def : null; } /** * Read the injectable def (`ɵprov`) for `type` or read the `ɵprov` from one of its ancestors. * * @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 * `ɵprov` on an ancestor only. */ function getInheritedInjectableDef(type) { // See `jit/injectable.ts#compileInjectable` for context on NG_PROV_DEF_FALLBACK. const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF] || (type[NG_PROV_DEF_FALLBACK] && type[NG_PROV_DEF_FALLBACK]())); if (def) { const typeName = getTypeName(type); // TODO(FW-1307): Re-add ngDevMode when closure can handle it // ngDevMode && console.warn(`DEPRECATED: DI is instantiating a token "${typeName}" that inherits its @Injectable decorator but does not provide one itself.\n` + `This will become an error in v10. Please add @Injectable() to the "${typeName}" class.`); return def; } else { return null; } } /** Gets the name of a type, accounting for some cross-browser differences. */ function getTypeName(type) { // `Function.prototype.name` behaves differently between IE and other browsers. In most browsers // it'll always return the name of the function itself, no matter how many other functions it // inherits from. On IE the function doesn't have its own `name` property, but it takes it from // the lowest level in the prototype chain. E.g. if we have `class Foo extends Parent` most // browsers will evaluate `Foo.name` to `Foo` while IE will return `Parent`. We work around // the issue by converting the function to a string and parsing its name out that way via a regex. if (type.hasOwnProperty('name')) { return type.name; } const match = ('' + type).match(/^function\s*([^\s(]+)/); return match === null ? '' : match[1]; } /** * Read the injector def type in a way which is immune to accidentally reading inherited value. * * @param type type which may have an injector def (`ɵinj`) */ function getInjectorDef(type) { return type && (type.hasOwnProperty(NG_INJ_DEF) || type.hasOwnProperty(NG_INJECTOR_DEF)) ? type[NG_INJ_DEF] : null; } const NG_PROV_DEF = getClosureSafeProperty({ ɵprov: getClosureSafeProperty }); const NG_INJ_DEF = getClosureSafeProperty({ ɵinj: getClosureSafeProperty }); // On IE10 properties defined via `defineProperty` won't be inherited by child classes, // which will break inheriting the injectable definition from a grandparent through an // undecorated parent class. We work around it by defining a fallback method which will be // used to retrieve the definition. This should only be a problem in JIT mode, because in // AOT TypeScript seems to have a workaround for static properties. When inheriting from an // undecorated parent is no longer supported in v10, this can safely be removed. const NG_PROV_DEF_FALLBACK = getClosureSafeProperty({ ɵprovFallback: getClosureSafeProperty }); // We need to keep these around so we can read off old defs if new defs are unavailable const NG_INJECTABLE_DEF = getClosureSafeProperty({ ngInjectableDef: getClosureSafeProperty }); const NG_INJECTOR_DEF = getClosureSafeProperty({ ngInjectorDef: getClosureSafeProperty }); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function stringify(token) { if (typeof token === 'string') { return token; } if (Array.isArray(token)) { return '[' + token.map(stringify).join(', ') + ']'; } if (token == null) { return '' + token; } if (token.overriddenName) { return `${token.overriddenName}`; } if (token.name) { return `${token.name}`; } const res = token.toString(); if (res == null) { return '' + res; } const newLineIndex = res.indexOf('\n'); return newLineIndex === -1 ? res : res.substring(0, newLineIndex); } /** * Concatenates two strings with separator, allocating new strings only when necessary. * * @param before before string. * @param separator separator string. * @param after after string. * @returns concatenated string. */ function concatStringsWithSpace(before, after) { return (before == null || before === '') ? (after === null ? '' : after) : ((after == null || after === '') ? before : before + ' ' + after); } /** * @fileoverview added by tsickle * Generated from: packages/core/src/di/forward_ref.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * An interface that a function passed into {\@link forwardRef} has to implement. * * \@usageNotes * ### Example * * {\@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref_fn'} * \@publicApi * @record */ function ForwardRefFn() { } /** @type {?} */ const __forward_ref__ = getClosureSafeProperty({ __forward_ref__: getClosureSafeProperty }); /** * Allows to refer to references which are not yet defined. * * For instance, `forwardRef` is used when the `token` which we need to refer to for the purposes of * DI is declared, but not yet defined. It is also used when the `token` which we use when creating * a query is not yet defined. * * \@usageNotes * ### Example * {\@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'} * \@publicApi * @param {?} forwardRefFn * @return {?} */ function forwardRef(forwardRefFn) { ((/** @type {?} */ (forwardRefFn))).__forward_ref__ = forwardRef; ((/** @type {?} */ (forwardRefFn))).toString = (/** * @return {?} */ function () { return stringify(this()); }); return ((/** @type {?} */ ((/** @type {?} */ (forwardRefFn))))); } /** * Lazily retrieves the reference value from a forwardRef. * * Acts as the identity function when given a non-forward-ref value. * * \@usageNotes * ### Example * * {\@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'} * * @see `forwardRef` * \@publicApi * @template T * @param {?} type * @return {?} */ function resolveForwardRef(type) { return isForwardRef(type) ? type() : type; } /** * Checks whether a function is wrapped by a `forwardRef`. * @param {?} fn * @return {?} */ function isForwardRef(fn) { return typeof fn === 'function' && fn.hasOwnProperty(__forward_ref__) && fn.__forward_ref__ === forwardRef; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ const __globalThis = typeof globalThis !== 'undefined' && globalThis; const __window = typeof window !== 'undefined' && window; const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope && self; const __global = typeof global !== 'undefined' && global; // Always use __globalThis if available, which is the spec-defined global variable across all // environments, then fallback to __global first, because in Node tests both __global and // __window may be defined and _global should be __global in that case. const _global = __globalThis || __global || __window || __self; /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var R3ResolvedDependencyType; (function (R3ResolvedDependencyType) { R3ResolvedDependencyType[R3ResolvedDependencyType["Token"] = 0] = "Token"; R3ResolvedDependencyType[R3ResolvedDependencyType["Attribute"] = 1] = "Attribute"; R3ResolvedDependencyType[R3ResolvedDependencyType["ChangeDetectorRef"] = 2] = "ChangeDetectorRef"; R3ResolvedDependencyType[R3ResolvedDependencyType["Invalid"] = 3] = "Invalid"; })(R3ResolvedDependencyType || (R3ResolvedDependencyType = {})); var R3FactoryTarget; (function (R3FactoryTarget) { R3FactoryTarget[R3FactoryTarget["Directive"] = 0] = "Directive"; R3FactoryTarget[R3FactoryTarget["Component"] = 1] = "Component"; R3FactoryTarget[R3FactoryTarget["Injectable"] = 2] = "Injectable"; R3FactoryTarget[R3FactoryTarget["Pipe"] = 3] = "Pipe"; R3FactoryTarget[R3FactoryTarget["NgModule"] = 4] = "NgModule"; })(R3FactoryTarget || (R3FactoryTarget = {})); var ViewEncapsulation; (function (ViewEncapsulation) { ViewEncapsulation[ViewEncapsulation["Emulated"] = 0] = "Emulated"; ViewEncapsulation[ViewEncapsulation["Native"] = 1] = "Native"; ViewEncapsulation[ViewEncapsulation["None"] = 2] = "None"; ViewEncapsulation[ViewEncapsulation["ShadowDom"] = 3] = "ShadowDom"; })(ViewEncapsulation || (ViewEncapsulation = {})); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function getCompilerFacade() { const globalNg = _global['ng']; if (!globalNg || !globalNg.ɵcompilerFacade) { throw new Error(`Angular JIT compilation failed: '@angular/compiler' not loaded!\n` + ` - JIT compilation is discouraged for production use-cases! Consider AOT mode instead.\n` + ` - Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?\n` + ` - Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping.`); } return globalNg.ɵcompilerFacade; } /** * @fileoverview added by tsickle * Generated from: packages/core/src/render3/fields.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const NG_COMP_DEF = getClosureSafeProperty({ ɵcmp: getClosureSafeProperty }); /** @type {?} */ const NG_DIR_DEF = getClosureSafeProperty({ ɵdir: getClosureSafeProperty }); /** @type {?} */ const NG_PIPE_DEF = getClosureSafeProperty({ ɵpipe: getClosureSafeProperty }); /** @type {?} */ const NG_MOD_DEF = getClosureSafeProperty({ ɵmod: getClosureSafeProperty }); /** @type {?} */ const NG_LOC_ID_DEF = getClosureSafeProperty({ ɵloc: getClosureSafeProperty }); /** @type {?} */ const NG_FACTORY_DEF = getClosureSafeProperty({ ɵfac: getClosureSafeProperty }); // TODO(misko): This is wrong. The NG_ELEMENT_ID should never be minified. /** * If a directive is diPublic, bloomAdd sets a property on the type with this constant as * the key and the directive's unique ID as the value. This allows us to map directives to their * bloom filter bit for DI. * @type {?} */ const NG_ELEMENT_ID = getClosureSafeProperty({ __NG_ELEMENT_ID__: getClosureSafeProperty }); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function ngDevModeResetPerfCounters() { const locationString = typeof location !== 'undefined' ? location.toString() : ''; const newCounters = { namedConstructors: locationString.indexOf('ngDevMode=namedConstructors') != -1, firstCreatePass: 0, tNode: 0, tView: 0, rendererCreateTextNode: 0, rendererSetText: 0, rendererCreateElement: 0, rendererAddEventListener: 0, rendererSetAttribute: 0, rendererRemoveAttribute: 0, rendererSetProperty: 0, rendererSetClassName: 0, rendererAddClass: 0, rendererRemoveClass: 0, rendererSetStyle: 0, rendererRemoveStyle: 0, rendererDestroy: 0, rendererDestroyNode: 0, rendererMoveNode: 0, rendererRemoveNode: 0, rendererAppendChild: 0, rendererInsertBefore: 0, rendererCreateComment: 0, }; // Make sure to refer to ngDevMode as ['ngDevMode'] for closure. const allowNgDevModeTrue = locationString.indexOf('ngDevMode=false') === -1; _global['ngDevMode'] = allowNgDevModeTrue && newCounters; return newCounters; } /** * This function checks to see if the `ngDevMode` has been set. If yes, * then we honor it, otherwise we default to dev mode with additional checks. * * The idea is that unless we are doing production build where we explicitly * set `ngDevMode == false` we should be helping the developer by providing * as much early warning and errors as possible. * * `ɵɵdefineComponent` is guaranteed to have been called before any component template functions * (and thus Ivy instructions), so a single initialization there is sufficient to ensure ngDevMode * is defined for the entire instruction set. * * When using checking `ngDevMode` on toplevel, always init it before referencing it * (e.g. `((typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode())`), otherwise you can * get a `ReferenceError` like in https://github.com/angular/angular/issues/31595. * * Details on possible values for `ngDevMode` can be found on its docstring. * * NOTE: * - changes to the `ngDevMode` name must be synced with `compiler-cli/src/tooling.ts`. */ function initNgDevMode() { // The below checks are to ensure that calling `initNgDevMode` multiple times does not // reset the counters. // If the `ngDevMode` is not an object, then it means we have not created the perf counters // yet. if (typeof ngDevMode === 'undefined' || ngDevMode) { if (typeof ngDevMode !== 'object') { ngDevModeResetPerfCounters(); } return !!ngDevMode; } return false; } /** * @fileoverview added by tsickle * Generated from: packages/core/src/di/injection_token.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Creates a token that can be used in a DI Provider. * * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a * runtime representation) such as when injecting an interface, callable type, array or * parameterized type. * * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by * the `Injector`. This provides additional level of type safety. * * ``` * interface MyInterface {...} * var myInterface = injector.get(new InjectionToken<MyInterface>('SomeToken')); * // myInterface is inferred to be MyInterface. * ``` * * When creating an `InjectionToken`, you can optionally specify a factory function which returns * (possibly by creating) a default value of the parameterized type `T`. This sets up the * `InjectionToken` using this factory as a provider as if it was defined explicitly in the * application's root injector. If the factory function, which takes zero arguments, needs to inject * dependencies, it can do so using the `inject` function. See below for an example. * * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which * overrides the above behavior and marks the token as belonging to a particular `\@NgModule`. As * mentioned above, `'root'` is the default value for `providedIn`. * * \@usageNotes * ### Basic Example * * ### Plain InjectionToken * * {\@example core/di/ts/injector_spec.ts region='InjectionToken'} * * ### Tree-shakable InjectionToken * * {\@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'} * * * \@publicApi * @template T */ class InjectionToken { /** * @param {?} _desc * @param {?=} options */ constructor(_desc, options) { this._desc = _desc; /** * \@internal */ this.ngMetadataName = 'InjectionToken'; 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`. ((/** @type {?} */ (this))).__NG_ELEMENT_ID__ = options; } else if (options !== undefined) { this.ɵprov = ɵɵdefineInjectable({ token: this, providedIn: options.providedIn || 'root', factory: options.factory, }); } } /** * @return {?} */ toString() { return `InjectionToken ${this._desc}`; } } if (false) { /** * \@internal * @type {?} */ InjectionToken.prototype.ngMetadataName; /** @type {?} */ InjectionToken.prototype.ɵprov; /** * @type {?} * @protected */ InjectionToken.prototype._desc; } /** * @record * @template T */ function InjectableDefToken() { } if (false) { /** @type {?} */ InjectableDefToken.prototype.ɵprov; } /** * @fileoverview added by tsickle * Generated from: packages/core/src/di/injector_compatibility.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * An InjectionToken that gets the current `Injector` for `createInjector()`-style injectors. * * Requesting this token instead of `Injector` allows `StaticInjector` to be tree-shaken from a * project. * * \@publicApi * @type {?} */ const INJECTOR = new InjectionToken('INJECTOR', (/** @type {?} */ (-1))); /** @type {?} */ const _THROW_IF_NOT_FOUND = {}; /** @type {?} */ const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND; /** @type {?} */ const NG_TEMP_TOKEN_PATH = 'ngTempTokenPath'; /** @type {?} */ const NG_TOKEN_PATH = 'ngTokenPath'; /** @type {?} */ const NEW_LINE = /\n/gm; /** @type {?} */ const NO_NEW_LINE = 'ɵ'; /** @type {?} */ const SOURCE = '__source'; const ɵ0$1 = getClosureSafeProperty; /** @type {?} */ const USE_VALUE = getClosureSafeProperty({ provide: String, useValue: ɵ0$1 }); /** * Current injector value used by `inject`. * - `undefined`: it is an error to call `inject` * - `null`: `inject` can be called but there is no injector (limp-mode). * - Injector instance: Use the injector for resolution. * @type {?} */ let _currentInjector = undefined; /** * @param {?} injector * @return {?} */ function setCurrentInjector(injector) { /** @type {?} */ const former = _currentInjector; _currentInjector = injector; return former; } /** * Current implementation of inject. * * By default, it is `injectInjectorOnly`, which makes it `Injector`-only aware. It can be changed * to `directiveInject`, which brings in the `NodeInjector` system of ivy. It is designed this * way for two reasons: * 1. `Injector` should not depend on ivy logic. * 2. To maintain tree shake-ability we don't want to bring in unnecessary code. * @type {?} */ let _injectImplementation; /** * Sets the current inject implementation. * @param {?} impl * @return {?} */ function setInjectImplementation(impl) { /** @type {?} */ const previous = _injectImplementation; _injectImplementation = impl; return previous; } /** * @template T * @param {?} token * @param {?=} flags * @return {?} */ function injectInjectorOnly(token, flags = InjectFlags.Default) { if (_currentInjector === undefined) { throw new Error(`inject() must be called from an injection context`); } else if (_currentInjector === null) { return injectRootLimpMode(token, undefined, flags); } else { return _currentInjector.get(token, flags & InjectFlags.Optional ? null : undefined, flags); } } /** * @template T * @param {?} token * @param {?=} flags * @return {?} */ function ɵɵinject(token, flags = InjectFlags.Default) { return (_injectImplementation || injectInjectorOnly)(resolveForwardRef(token), flags); } /** * Throws an error indicating that a factory function could not be generated by the compiler for a * particular class. * * This instruction allows the actual error message to be optimized away when ngDevMode is turned * off, saving bytes of generated code while still providing a good experience in dev mode. * * The name of the class is not mentioned here, but will be in the generated factory function name * and thus in the stack trace. * * \@codeGenApi * @param {?} index * @return {?} */ function ɵɵinvalidFactoryDep(index) { /** @type {?} */ const msg = ngDevMode ? `This constructor is not compatible with Angular Dependency Injection because its dependency at index ${index} of the parameter list is invalid. This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator. Please check that 1) the type for the parameter at index ${index} is correct and 2) the correct Angular decorators are defined for this class and its ancestors.` : 'invalid'; throw new Error(msg); } /** * Injects a token from the currently active injector. * * Must be used in the context of a factory function such as one defined for an * `InjectionToken`. Throws an error if not called from such a context. * * Within such a factory function, using this function to request injection of a dependency * is faster and more type-safe than providing an additional array of dependencies * (as has been common with `useFactory` providers). * * \@param token The injection token for the dependency to be injected. * \@param flags Optional flags that control how injection is executed. * The flags correspond to injection strategies that can be specified with * parameter decorators `\@Host`, `\@Self`, `\@SkipSef`, and `\@Optional`. * \@return True if injection is successful, null otherwise. * * \@usageNotes * * ### Example * * {\@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'} * * \@publicApi * @type {?} */ const inject = ɵɵinject; /** * Injects `root` tokens in limp mode. * * If no injector exists, we can still inject tree-shakable providers which have `providedIn` set to * `"root"`. This is known as the limp mode injection. In such case the value is stored in the * `InjectableDef`. * @template T * @param {?} token * @param {?} notFoundValue * @param {?} flags * @return {?} */ function injectRootLimpMode(token, notFoundValue, flags) { /** @type {?} */ const injectableDef = getInjectableDef(token); if (injectableDef && injectableDef.providedIn == 'root') { return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() : injectableDef.value; } if (flags & InjectFlags.Optional) return null; if (notFoundValue !== undefined) return notFoundValue; throw new Error(`Injector: NOT_FOUND [${stringify(token)}]`); } /** * @param {?} types * @return {?} */ function injectArgs(types) { /** @type {?} */ const args = []; for (let i = 0; i < types.length; i++) { /** @type {?} */ const arg = resolveForwardRef(types[i]); if (Array.isArray(arg)) { if (arg.length === 0) { throw new Error('Arguments array must have arguments.'); } /** @type {?} */ let type = undefined; /** @type {?} */ let flags = InjectFlags.Default; for (let j = 0; j < arg.length; j++) { /** @type {?} */ const meta = arg[j]; if (meta instanceof Optional || meta.ngMetadataName === 'Optional' || meta === Optional) { flags |= InjectFlags.Optional; } else if (meta instanceof SkipSelf || meta.ngMetadataName === 'SkipSelf' || meta === SkipSelf) { flags |= InjectFlags.SkipSelf; } else if (meta instanceof Self || meta.ngMetadataName === 'Self' || meta === Self) { flags |= InjectFlags.Self; } else if (meta instanceof Inject || meta === Inject) { type = meta.token; } else { type = meta; } } args.push(ɵɵinject((/** @type {?} */ (type)), flags)); } else { args.push(ɵɵinject(arg)); } } return args; } class NullInjector { /** * @param {?} token * @param {?=} notFoundValue * @return {?} */ get(token, notFoundValue = THROW_IF_NOT_FOUND) { if (notFoundValue === THROW_IF_NOT_FOUND) { // Intentionally left behind: With dev tools open the debugger will stop here. There is no // reason why correctly written application should cause this exception. // TODO(misko): uncomment the next line once `ngDevMode` works with closure. // if (ngDevMode) debugger; /** @type {?} */ const error = new Error(`NullInjectorError: No provider for ${stringify(token)}!`); error.name = 'NullInjectorError'; throw error; } return notFoundValue; } } /** * @param {?} e * @param {?} token * @param {?} injectorErrorName * @param {?} source * @return {?} */ function catchInjectorError(e, token, injectorErrorName, source) { /** @type {?} */ const tokenPath = e[NG_TEMP_TOKEN_PATH]; if (token[SOURCE]) { tokenPath.unshift(token[SOURCE]); } e.message = formatError('\n' + e.message, tokenPath, injectorErrorName, source); e[NG_TOKEN_PATH] = tokenPath; e[NG_TEMP_TOKEN_PATH] = null; throw e; } /** * @param {?} text * @param {?} obj * @param {?} injectorErrorName * @param {?=} source * @return {?} */ function formatError(text, obj, injectorErrorName, source = null) { text = text && text.charAt(0) === '\n' && text.charAt(1) == NO_NEW_LINE ? text.substr(2) : text; /** @type {?} */ let context = stringify(obj); if (Array.isArray(obj)) { context = obj.map(stringify).join(' -> '); } else if (typeof obj === 'object') { /** @type {?} */ let parts = (/** @type {?} */ ([])); for (let key in obj) { if (obj.hasOwnProperty(key)) { /** @type {?} */ let value = obj[key]; parts.push(key + ':' + (typeof value === 'string' ? JSON.stringify(value) : stringify(value))); } } context = `{${parts.join(', ')}}`; } return `${injectorErrorName}${source ? '(' + source + ')' : ''}[${context}]: ${text.replace(NEW_LINE, '\n ')}`; } /** * @fileoverview added by tsickle * Generated from: packages/core/src/di/jit/environment.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * A mapping of the \@angular/core API surface used in generated expressions to the actual symbols. * * This should be kept up to date with the public exports of \@angular/core. * @type {?} */ const angularCoreDiEnv = { 'ɵɵdefineInjectable': ɵɵdefineInjectable, 'ɵɵdefineInjector': ɵɵdefineInjector, 'ɵɵinject': ɵɵinject, 'ɵɵgetFactoryOf': getFactoryOf, 'ɵɵinvalidFactoryDep': ɵɵinvalidFactoryDep, }; /** * @template T * @param {?} type * @return {?} */ function getFactoryOf(type) { /** @type {?} */ const typeAny = (/** @type {?} */ (type)); if (isForwardRef(type)) { return (/** @type {?} */ (((/** * @return {?} */ () => { /** @type {?} */ const factory = getFactoryOf(resolveForwardRef(typeAny)); return factory ? factory() : null; })))); } /** @type {?} */ const def = getInjectableDef(typeAny) || getInjectorDef(typeAny); if (!def || def.factory === undefined) { return null; } return def.factory; } /** * @fileoverview added by tsickle * Generated from: packages/core/src/linker/ng_module_factory.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Represents an instance of an NgModule created via a {\@link NgModuleFactory}. * * `NgModuleRef` provides access to the NgModule Instance as well other objects related to this * NgModule Instance. * * \@publicApi * @abstract * @template T */ class NgModuleRef { } if (false) { /** * The injector that contains all of the providers of the NgModule. * @abstract * @return {?} */ NgModuleRef.prototype.injector = function () { }; /** * The ComponentFactoryResolver to get hold of the ComponentFactories * declared in the `entryComponents` property of the module. * @abstract * @return {?} */ NgModuleRef.prototype.componentFactoryResolver = function () { }; /** * The NgModule instance. * @abstract * @return {?} */ NgModuleRef.prototype.instance = function () { }; /** * Destroys the module instance and all of the data structures associated with it. * @abstract * @return {?} */ NgModuleRef.prototype.destroy = function () { }; /** * Allows to register a callback that will be called when the module is destroyed. * @abstract * @param {?} callback * @return {?} */ NgModuleRef.prototype.onDestroy = function (callback) { }; } /** * @record * @template T */ function InternalNgModuleRef() { } if (false) { /** @type {?} */ InternalNgModuleRef.prototype._bootstrapComponents; } /** * \@publicApi * @abstract * @template T */ class NgModuleFactory { } if (false) { /** * @abstract * @return {?} */ NgModuleFactory.prototype.moduleType = function () { }; /** * @abstract * @param {?} parentInjector * @return {?} */ NgModuleFactory.prototype.create = function (parentInjector) { }; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function assertNumber(actual, msg) { if (!(typeof actual === 'number')) { throwError(msg, typeof actual, 'number', '==='); } } function assertNumberInRange(actual, minInclusive, maxInclusive) { assertNumber(actual, 'Expected a number'); assertLessThanOrEqual(actual, maxInclusive, 'Expected number to be less than or equal to'); assertGreaterThanOrEqual(actual, minInclusive, 'Expected number to be greater than or equal to'); } function assertString(actual, msg) { if (!(typeof actual === 'string')) { throwError(msg, actual === null ? 'null' : typeof actual, 'string', '==='); } } function assertEqual(actual, expected, msg) { if (!(actual == expected)) { throwError(msg, actual, expected, '=='); } } function assertNotEqual(actual, expected, msg) { if (!(actual != expected)) { throwError(msg, actual, expected, '!='); } } function assertSame(actual, expected, msg) { if (!(actual === expected)) { throwError(msg, actual, expected, '==='); } } function assertNotSame(actual, expected, msg) { if (!(actual !== expected)) { throwError(msg, actual, expected, '!=='); } } function assertLessThan(actual, expected, msg) { if (!(actual < expected)) { throwError(msg, actual, expected, '<'); } } function assertLessThanOrEqual(actual, expected, msg) { if (!(actual <= expected)) { throwError(msg, actual, expected, '<='); } } function assertGreaterThan(actual, expected, msg) { if (!(actual > expected)) { throwError(msg, actual, expected, '>'); } } function assertGreaterThanOrEqual(actual, expected, msg) { if (!(actual >= expected)) { throwError(msg, actual, expected, '>='); } } function assertNotDefined(actual, msg) { if (actual != null) { throwError(msg, actual, null, '=='); } } function assertDefined(actual, msg) { if (actual == null) { throwError(msg, actual, null, '!='); } } function throwError(msg, actual, expected, comparison) { throw new Error(`ASSERTION ERROR: ${msg}` + (comparison == null ? '' : ` [Expected=> ${expected} ${comparison} ${actual} <=Actual]`)); } function assertDomNode(node) { // If we're in a worker, `Node` will not be defined. assertEqual((typeof Node !== 'undefined' && node instanceof Node) || (typeof node === 'object' && node != null && node.constructor.name === 'WebWorkerRenderNode'), true, `The provided value must be an instance of a DOM Node but got ${stringify(node)}`); } function assertDataInRange(arr, index) { const maxLen = arr ? arr.length : 0; assertLessThan(index, maxLen, `Index expected to be less than ${maxLen} but got ${index}`); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Equivalent to ES6 spread, add each item to an array. * * @param items The items to add * @param arr The array to which you want to add the items */ function addAllToArray(items, arr) { for (let i = 0; i < items.length; i++) { arr.push(items[i]); } } /** * Flattens an array. */ function flatten(list, dst) { if (dst === undefined) dst = list; for (let i = 0; i < list.length; i++) { let item = list[i]; if (Array.isArray(item)) { // we need to inline it. if (dst === list) { // Our assumption that the list was already flat was wrong and // we need to clone flat since we need to write to it. dst = list.slice(0, i); } flatten(item, dst); } else if (dst !== list) { dst.push(item); } } return dst; } function deepForEach(input, fn) { input.forEach(value => Array.isArray(value) ? deepForEach(value, fn) : fn(value)); } function addToArray(arr, index, value) { // perf: array.push is faster than array.splice! if (index >= arr.length) { arr.push(value); } else { arr.splice(index, 0, value); } } function removeFromArray(arr, index) { // perf: array.pop is faster than array.splice! if (index >= arr.length - 1) { return arr.pop(); } else { return arr.splice(index, 1)[0]; } } function newArray(size, value) { const list = []; for (let i = 0; i < size; i++) { list.push(value); } return list; } /** * Remove item from array (Same as `Array.splice()` but faster.) * * `Array.splice()` is not as fast because it has to allocate an array for the elements which were * removed. This causes memory pressure and slows down code when most of the time we don't * care about the deleted items array. * * https://jsperf.com/fast-array-splice (About 20x faster) * * @param array Array to splice * @param index Index of element in array to remove. * @param count Number of items to remove. */ function arraySplice(array, index, count) { const length = array.length - count; while (index < length) { array[index] = array[index + count]; index++; } while (count--) { array.pop(); // sh