@angular/core
Version:
Angular - the core framework
1,642 lines (1,630 loc) • 137 kB
JavaScript
/**
* @license Angular v8.2.9
* (c) 2010-2019 Google LLC. https://angular.io/
* License: MIT
*/
import { getDebugNode, RendererFactory2, InjectionToken, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, ɵNG_COMPONENT_DEF, ɵRender3NgModuleRef, LOCALE_ID, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ApplicationInitStatus, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIRECTIVE_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJECTOR_DEF, ɵNG_MODULE_DEF, ɵcompileNgModuleDefs, NgZone, Compiler, COMPILER_OPTIONS, ɵNgModuleFactory, ModuleWithComponentFactories, Injector, InjectFlags, ɵresetCompiledComponents, ɵflushModuleScopingQueueAsMuchAsPossible, Injectable, ɵclearOverrides, ɵoverrideComponentView, ɵAPP_ROOT, Optional, SkipSelf, ɵoverrideProvider, ɵivyEnabled } from '@angular/core';
import { __awaiter } from 'tslib';
import { ResourceLoader } from '@angular/compiler';
/**
* @fileoverview added by tsickle
* @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
*/
/** @type {?} */
const _global = (/** @type {?} */ ((typeof window === 'undefined' ? global : window)));
/**
* Wraps a test function in an asynchronous test zone. The test will automatically
* complete when all asynchronous calls within this zone are done. Can be used
* to wrap an {\@link inject} call.
*
* Example:
*
* ```
* it('...', async(inject([AClass], (object) => {
* object.doSomething.then(() => {
* expect(...);
* })
* });
* ```
*
*
* @param {?} fn
* @return {?}
*/
function asyncFallback(fn) {
// If we're running using the Jasmine test framework, adapt to call the 'done'
// function when asynchronous activity is finished.
if (_global.jasmine) {
// Not using an arrow function to preserve context passed from call site
return (/**
* @this {?}
* @param {?} done
* @return {?}
*/
function (done) {
if (!done) {
// if we run beforeEach in @angular/core/testing/testing_internal then we get no done
// fake it here and assume sync.
done = (/**
* @return {?}
*/
function () { });
done.fail = (/**
* @param {?} e
* @return {?}
*/
function (e) { throw e; });
}
runInTestZone(fn, this, done, (/**
* @param {?} err
* @return {?}
*/
(err) => {
if (typeof err === 'string') {
return done.fail(new Error((/** @type {?} */ (err))));
}
else {
done.fail(err);
}
}));
});
}
// Otherwise, return a promise which will resolve when asynchronous activity
// is finished. This will be correctly consumed by the Mocha framework with
// it('...', async(myFn)); or can be used in a custom framework.
// Not using an arrow function to preserve context passed from call site
return (/**
* @this {?}
* @return {?}
*/
function () {
return new Promise((/**
* @param {?} finishCallback
* @param {?} failCallback
* @return {?}
*/
(finishCallback, failCallback) => {
runInTestZone(fn, this, finishCallback, failCallback);
}));
});
}
/**
* @param {?} fn
* @param {?} context
* @param {?} finishCallback
* @param {?} failCallback
* @return {?}
*/
function runInTestZone(fn, context, finishCallback, failCallback) {
/** @type {?} */
const currentZone = Zone.current;
/** @type {?} */
const AsyncTestZoneSpec = ((/** @type {?} */ (Zone)))['AsyncTestZoneSpec'];
if (AsyncTestZoneSpec === undefined) {
throw new Error('AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +
'Please make sure that your environment includes zone.js/dist/async-test.js');
}
/** @type {?} */
const ProxyZoneSpec = (/** @type {?} */ (((/** @type {?} */ (Zone)))['ProxyZoneSpec']));
if (ProxyZoneSpec === undefined) {
throw new Error('ProxyZoneSpec is needed for the async() test helper but could not be found. ' +
'Please make sure that your environment includes zone.js/dist/proxy.js');
}
/** @type {?} */
const proxyZoneSpec = ProxyZoneSpec.get();
ProxyZoneSpec.assertPresent();
// We need to create the AsyncTestZoneSpec outside the ProxyZone.
// If we do it in ProxyZone then we will get to infinite recursion.
/** @type {?} */
const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
/** @type {?} */
const previousDelegate = proxyZoneSpec.getDelegate();
(/** @type {?} */ ((/** @type {?} */ (proxyZone)).parent)).run((/**
* @return {?}
*/
() => {
/** @type {?} */
const testZoneSpec = new AsyncTestZoneSpec((/**
* @return {?}
*/
() => {
// Need to restore the original zone.
currentZone.run((/**
* @return {?}
*/
() => {
if (proxyZoneSpec.getDelegate() == testZoneSpec) {
// Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
proxyZoneSpec.setDelegate(previousDelegate);
}
finishCallback();
}));
}), (/**
* @param {?} error
* @return {?}
*/
(error) => {
// Need to restore the original zone.
currentZone.run((/**
* @return {?}
*/
() => {
if (proxyZoneSpec.getDelegate() == testZoneSpec) {
// Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
proxyZoneSpec.setDelegate(previousDelegate);
}
failCallback(error);
}));
}), 'test');
proxyZoneSpec.setDelegate(testZoneSpec);
}));
return Zone.current.runGuarded(fn, context);
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Wraps a test function in an asynchronous test zone. The test will automatically
* complete when all asynchronous calls within this zone are done. Can be used
* to wrap an {\@link inject} call.
*
* Example:
*
* ```
* it('...', async(inject([AClass], (object) => {
* object.doSomething.then(() => {
* expect(...);
* })
* });
* ```
*
* \@publicApi
* @param {?} fn
* @return {?}
*/
function async(fn) {
/** @type {?} */
const _Zone = typeof Zone !== 'undefined' ? Zone : null;
if (!_Zone) {
return (/**
* @return {?}
*/
function () {
return Promise.reject('Zone is needed for the async() test helper but could not be found. ' +
'Please make sure that your environment includes zone.js/dist/zone.js');
});
}
/** @type {?} */
const asyncTest = _Zone && _Zone[_Zone.__symbol__('asyncTest')];
if (typeof asyncTest === 'function') {
return asyncTest(fn);
}
// not using new version of zone.js
// TODO @JiaLiPassion, remove this after all library updated to
// newest version of zone.js(0.8.25)
return asyncFallback(fn);
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Fixture for debugging and testing a component.
*
* \@publicApi
* @template T
*/
class ComponentFixture {
/**
* @param {?} componentRef
* @param {?} ngZone
* @param {?} _autoDetect
*/
constructor(componentRef, ngZone, _autoDetect) {
this.componentRef = componentRef;
this.ngZone = ngZone;
this._autoDetect = _autoDetect;
this._isStable = true;
this._isDestroyed = false;
this._resolve = null;
this._promise = null;
this._onUnstableSubscription = null;
this._onStableSubscription = null;
this._onMicrotaskEmptySubscription = null;
this._onErrorSubscription = null;
this.changeDetectorRef = componentRef.changeDetectorRef;
this.elementRef = componentRef.location;
this.debugElement = (/** @type {?} */ (getDebugNode(this.elementRef.nativeElement)));
this.componentInstance = componentRef.instance;
this.nativeElement = this.elementRef.nativeElement;
this.componentRef = componentRef;
this.ngZone = ngZone;
if (ngZone) {
// Create subscriptions outside the NgZone so that the callbacks run oustide
// of NgZone.
ngZone.runOutsideAngular((/**
* @return {?}
*/
() => {
this._onUnstableSubscription =
ngZone.onUnstable.subscribe({ next: (/**
* @return {?}
*/
() => { this._isStable = false; }) });
this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
next: (/**
* @return {?}
*/
() => {
if (this._autoDetect) {
// Do a change detection run with checkNoChanges set to true to check
// there are no changes on the second run.
this.detectChanges(true);
}
})
});
this._onStableSubscription = ngZone.onStable.subscribe({
next: (/**
* @return {?}
*/
() => {
this._isStable = true;
// Check whether there is a pending whenStable() completer to resolve.
if (this._promise !== null) {
// If so check whether there are no pending macrotasks before resolving.
// Do this check in the next tick so that ngZone gets a chance to update the state of
// pending macrotasks.
scheduleMicroTask((/**
* @return {?}
*/
() => {
if (!ngZone.hasPendingMacrotasks) {
if (this._promise !== null) {
(/** @type {?} */ (this._resolve))(true);
this._resolve = null;
this._promise = null;
}
}
}));
}
})
});
this._onErrorSubscription =
ngZone.onError.subscribe({ next: (/**
* @param {?} error
* @return {?}
*/
(error) => { throw error; }) });
}));
}
}
/**
* @private
* @param {?} checkNoChanges
* @return {?}
*/
_tick(checkNoChanges) {
this.changeDetectorRef.detectChanges();
if (checkNoChanges) {
this.checkNoChanges();
}
}
/**
* Trigger a change detection cycle for the component.
* @param {?=} checkNoChanges
* @return {?}
*/
detectChanges(checkNoChanges = true) {
if (this.ngZone != null) {
// Run the change detection inside the NgZone so that any async tasks as part of the change
// detection are captured by the zone and can be waited for in isStable.
this.ngZone.run((/**
* @return {?}
*/
() => { this._tick(checkNoChanges); }));
}
else {
// Running without zone. Just do the change detection.
this._tick(checkNoChanges);
}
}
/**
* Do a change detection run to make sure there were no changes.
* @return {?}
*/
checkNoChanges() { this.changeDetectorRef.checkNoChanges(); }
/**
* Set whether the fixture should autodetect changes.
*
* Also runs detectChanges once so that any existing change is detected.
* @param {?=} autoDetect
* @return {?}
*/
autoDetectChanges(autoDetect = true) {
if (this.ngZone == null) {
throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
}
this._autoDetect = autoDetect;
this.detectChanges();
}
/**
* Return whether the fixture is currently stable or has async tasks that have not been completed
* yet.
* @return {?}
*/
isStable() { return this._isStable && !(/** @type {?} */ (this.ngZone)).hasPendingMacrotasks; }
/**
* Get a promise that resolves when the fixture is stable.
*
* This can be used to resume testing after events have triggered asynchronous activity or
* asynchronous change detection.
* @return {?}
*/
whenStable() {
if (this.isStable()) {
return Promise.resolve(false);
}
else if (this._promise !== null) {
return this._promise;
}
else {
this._promise = new Promise((/**
* @param {?} res
* @return {?}
*/
res => { this._resolve = res; }));
return this._promise;
}
}
/**
* @private
* @return {?}
*/
_getRenderer() {
if (this._renderer === undefined) {
this._renderer = this.componentRef.injector.get(RendererFactory2, null);
}
return (/** @type {?} */ (this._renderer));
}
/**
* Get a promise that resolves when the ui state is stable following animations.
* @return {?}
*/
whenRenderingDone() {
/** @type {?} */
const renderer = this._getRenderer();
if (renderer && renderer.whenRenderingDone) {
return renderer.whenRenderingDone();
}
return this.whenStable();
}
/**
* Trigger component destruction.
* @return {?}
*/
destroy() {
if (!this._isDestroyed) {
this.componentRef.destroy();
if (this._onUnstableSubscription != null) {
this._onUnstableSubscription.unsubscribe();
this._onUnstableSubscription = null;
}
if (this._onStableSubscription != null) {
this._onStableSubscription.unsubscribe();
this._onStableSubscription = null;
}
if (this._onMicrotaskEmptySubscription != null) {
this._onMicrotaskEmptySubscription.unsubscribe();
this._onMicrotaskEmptySubscription = null;
}
if (this._onErrorSubscription != null) {
this._onErrorSubscription.unsubscribe();
this._onErrorSubscription = null;
}
this._isDestroyed = true;
}
}
}
if (false) {
/**
* The DebugElement associated with the root element of this component.
* @type {?}
*/
ComponentFixture.prototype.debugElement;
/**
* The instance of the root component class.
* @type {?}
*/
ComponentFixture.prototype.componentInstance;
/**
* The native element at the root of the component.
* @type {?}
*/
ComponentFixture.prototype.nativeElement;
/**
* The ElementRef for the element at the root of the component.
* @type {?}
*/
ComponentFixture.prototype.elementRef;
/**
* The ChangeDetectorRef for the component
* @type {?}
*/
ComponentFixture.prototype.changeDetectorRef;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._renderer;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._isStable;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._isDestroyed;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._resolve;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._promise;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._onUnstableSubscription;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._onStableSubscription;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._onMicrotaskEmptySubscription;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._onErrorSubscription;
/** @type {?} */
ComponentFixture.prototype.componentRef;
/** @type {?} */
ComponentFixture.prototype.ngZone;
/**
* @type {?}
* @private
*/
ComponentFixture.prototype._autoDetect;
}
/**
* @param {?} fn
* @return {?}
*/
function scheduleMicroTask(fn) {
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
}
/**
* @fileoverview added by tsickle
* @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
*/
/**
* fakeAsync has been moved to zone.js
* this file is for fallback in case old version of zone.js is used
* @type {?}
*/
const _Zone = typeof Zone !== 'undefined' ? Zone : null;
/** @type {?} */
const FakeAsyncTestZoneSpec = _Zone && _Zone['FakeAsyncTestZoneSpec'];
/** @type {?} */
const ProxyZoneSpec = _Zone && _Zone['ProxyZoneSpec'];
/** @type {?} */
let _fakeAsyncTestZoneSpec = null;
/**
* Clears out the shared fake async zone for a test.
* To be called in a global `beforeEach`.
*
* \@publicApi
* @return {?}
*/
function resetFakeAsyncZoneFallback() {
_fakeAsyncTestZoneSpec = null;
// in node.js testing we may not have ProxyZoneSpec in which case there is nothing to reset.
ProxyZoneSpec && ProxyZoneSpec.assertPresent().resetDelegate();
}
/** @type {?} */
let _inFakeAsyncCall = false;
/**
* Wraps a function to be executed in the fakeAsync zone:
* - microtasks are manually executed by calling `flushMicrotasks()`,
* - timers are synchronous, `tick()` simulates the asynchronous passage of time.
*
* If there are any pending timers at the end of the function, an exception will be thrown.
*
* Can be used to wrap inject() calls.
*
* \@usageNotes
* ### Example
*
* {\@example core/testing/ts/fake_async.ts region='basic'}
*
* \@publicApi
* @param {?} fn
* @return {?} The function wrapped to be executed in the fakeAsync zone
*
*/
function fakeAsyncFallback(fn) {
// Not using an arrow function to preserve context passed from call site
return (/**
* @this {?}
* @param {...?} args
* @return {?}
*/
function (...args) {
/** @type {?} */
const proxyZoneSpec = ProxyZoneSpec.assertPresent();
if (_inFakeAsyncCall) {
throw new Error('fakeAsync() calls can not be nested');
}
_inFakeAsyncCall = true;
try {
if (!_fakeAsyncTestZoneSpec) {
if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) {
throw new Error('fakeAsync() calls can not be nested');
}
_fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec();
}
/** @type {?} */
let res;
/** @type {?} */
const lastProxyZoneSpec = proxyZoneSpec.getDelegate();
proxyZoneSpec.setDelegate(_fakeAsyncTestZoneSpec);
try {
res = fn.apply(this, args);
flushMicrotasksFallback();
}
finally {
proxyZoneSpec.setDelegate(lastProxyZoneSpec);
}
if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) {
throw new Error(`${_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length} ` +
`periodic timer(s) still in the queue.`);
}
if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) {
throw new Error(`${_fakeAsyncTestZoneSpec.pendingTimers.length} timer(s) still in the queue.`);
}
return res;
}
finally {
_inFakeAsyncCall = false;
resetFakeAsyncZoneFallback();
}
});
}
/**
* @return {?}
*/
function _getFakeAsyncZoneSpec() {
if (_fakeAsyncTestZoneSpec == null) {
throw new Error('The code should be running in the fakeAsync zone to call this function');
}
return _fakeAsyncTestZoneSpec;
}
/**
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
*
* The microtasks queue is drained at the very start of this function and after any timer callback
* has been executed.
*
* \@usageNotes
* ### Example
*
* {\@example core/testing/ts/fake_async.ts region='basic'}
*
* \@publicApi
* @param {?=} millis
* @return {?}
*/
function tickFallback(millis = 0) {
_getFakeAsyncZoneSpec().tick(millis);
}
/**
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
* draining the macrotask queue until it is empty. The returned value is the milliseconds
* of time that would have been elapsed.
*
* \@publicApi
* @param {?=} maxTurns
* @return {?} The simulated time elapsed, in millis.
*
*/
function flushFallback(maxTurns) {
return _getFakeAsyncZoneSpec().flush(maxTurns);
}
/**
* Discard all remaining periodic tasks.
*
* \@publicApi
* @return {?}
*/
function discardPeriodicTasksFallback() {
/** @type {?} */
const zoneSpec = _getFakeAsyncZoneSpec();
zoneSpec.pendingPeriodicTimers.length = 0;
}
/**
* Flush any pending microtasks.
*
* \@publicApi
* @return {?}
*/
function flushMicrotasksFallback() {
_getFakeAsyncZoneSpec().flushMicrotasks();
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const _Zone$1 = typeof Zone !== 'undefined' ? Zone : null;
/** @type {?} */
const fakeAsyncTestModule = _Zone$1 && _Zone$1[_Zone$1.__symbol__('fakeAsyncTest')];
/**
* Clears out the shared fake async zone for a test.
* To be called in a global `beforeEach`.
*
* \@publicApi
* @return {?}
*/
function resetFakeAsyncZone() {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.resetFakeAsyncZone();
}
else {
return resetFakeAsyncZoneFallback();
}
}
/**
* Wraps a function to be executed in the fakeAsync zone:
* - microtasks are manually executed by calling `flushMicrotasks()`,
* - timers are synchronous, `tick()` simulates the asynchronous passage of time.
*
* If there are any pending timers at the end of the function, an exception will be thrown.
*
* Can be used to wrap inject() calls.
*
* \@usageNotes
* ### Example
*
* {\@example core/testing/ts/fake_async.ts region='basic'}
*
* \@publicApi
* @param {?} fn
* @return {?} The function wrapped to be executed in the fakeAsync zone
*
*/
function fakeAsync(fn) {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.fakeAsync(fn);
}
else {
return fakeAsyncFallback(fn);
}
}
/**
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
*
* The microtasks queue is drained at the very start of this function and after any timer callback
* has been executed.
*
* \@usageNotes
* ### Example
*
* {\@example core/testing/ts/fake_async.ts region='basic'}
*
* \@publicApi
* @param {?=} millis
* @return {?}
*/
function tick(millis = 0) {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.tick(millis);
}
else {
return tickFallback(millis);
}
}
/**
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
* draining the macrotask queue until it is empty. The returned value is the milliseconds
* of time that would have been elapsed.
*
* \@publicApi
* @param {?=} maxTurns
* @return {?} The simulated time elapsed, in millis.
*
*/
function flush(maxTurns) {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.flush(maxTurns);
}
else {
return flushFallback(maxTurns);
}
}
/**
* Discard all remaining periodic tasks.
*
* \@publicApi
* @return {?}
*/
function discardPeriodicTasks() {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.discardPeriodicTasks();
}
else {
discardPeriodicTasksFallback();
}
}
/**
* Flush any pending microtasks.
*
* \@publicApi
* @return {?}
*/
function flushMicrotasks() {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.flushMicrotasks();
}
else {
return flushMicrotasksFallback();
}
}
/**
* @fileoverview added by tsickle
* @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
*/
/**
* Injectable completer that allows signaling completion of an asynchronous test. Used internally.
*/
class AsyncTestCompleter {
constructor() {
this._promise = new Promise((/**
* @param {?} res
* @param {?} rej
* @return {?}
*/
(res, rej) => {
this._resolve = res;
this._reject = rej;
}));
}
/**
* @param {?=} value
* @return {?}
*/
done(value) { this._resolve(value); }
/**
* @param {?=} error
* @param {?=} stackTrace
* @return {?}
*/
fail(error, stackTrace) { this._reject(error); }
/**
* @return {?}
*/
get promise() { return this._promise; }
}
if (false) {
/**
* @type {?}
* @private
*/
AsyncTestCompleter.prototype._resolve;
/**
* @type {?}
* @private
*/
AsyncTestCompleter.prototype._reject;
/**
* @type {?}
* @private
*/
AsyncTestCompleter.prototype._promise;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* An abstract class for inserting the root test component element in a platform independent way.
*
* \@publicApi
*/
class TestComponentRenderer {
/**
* @param {?} rootElementId
* @return {?}
*/
insertRootElement(rootElementId) { }
}
/**
* \@publicApi
* @type {?}
*/
const ComponentFixtureAutoDetect = new InjectionToken('ComponentFixtureAutoDetect');
/**
* \@publicApi
* @type {?}
*/
const ComponentFixtureNoNgZone = new InjectionToken('ComponentFixtureNoNgZone');
/**
* Static methods implemented by the `TestBedViewEngine` and `TestBedRender3`
*
* \@publicApi
* @record
*/
function TestBedStatic() { }
if (false) {
/* Skipping unhandled member: new (...args: any[]): TestBed;*/
/**
* @param {?} ngModule
* @param {?} platform
* @param {?=} aotSummaries
* @return {?}
*/
TestBedStatic.prototype.initTestEnvironment = function (ngModule, platform, aotSummaries) { };
/**
* Reset the providers for the test injector.
* @return {?}
*/
TestBedStatic.prototype.resetTestEnvironment = function () { };
/**
* @return {?}
*/
TestBedStatic.prototype.resetTestingModule = function () { };
/**
* Allows overriding default compiler providers and settings
* which are defined in test_injector.js
* @param {?} config
* @return {?}
*/
TestBedStatic.prototype.configureCompiler = function (config) { };
/**
* Allows overriding default providers, directives, pipes, modules of the test injector,
* which are defined in test_injector.js
* @param {?} moduleDef
* @return {?}
*/
TestBedStatic.prototype.configureTestingModule = function (moduleDef) { };
/**
* Compile components with a `templateUrl` for the test's NgModule.
* It is necessary to call this function
* as fetching urls is asynchronous.
* @return {?}
*/
TestBedStatic.prototype.compileComponents = function () { };
/**
* @param {?} ngModule
* @param {?} override
* @return {?}
*/
TestBedStatic.prototype.overrideModule = function (ngModule, override) { };
/**
* @param {?} component
* @param {?} override
* @return {?}
*/
TestBedStatic.prototype.overrideComponent = function (component, override) { };
/**
* @param {?} directive
* @param {?} override
* @return {?}
*/
TestBedStatic.prototype.overrideDirective = function (directive, override) { };
/**
* @param {?} pipe
* @param {?} override
* @return {?}
*/
TestBedStatic.prototype.overridePipe = function (pipe, override) { };
/**
* @param {?} component
* @param {?} template
* @return {?}
*/
TestBedStatic.prototype.overrideTemplate = function (component, template) { };
/**
* Overrides the template of the given component, compiling the template
* in the context of the TestingModule.
*
* Note: This works for JIT and AOTed components as well.
* @param {?} component
* @param {?} template
* @return {?}
*/
TestBedStatic.prototype.overrideTemplateUsingTestingModule = function (component, template) { };
/**
* Overwrites all providers for the given token with the given provider definition.
*
* Note: This works for JIT and AOTed components as well.
* @param {?} token
* @param {?} provider
* @return {?}
*/
TestBedStatic.prototype.overrideProvider = function (token, provider) { };
/**
* @param {?} token
* @param {?} provider
* @return {?}
*/
TestBedStatic.prototype.overrideProvider = function (token, provider) { };
/**
* @param {?} token
* @param {?} provider
* @return {?}
*/
TestBedStatic.prototype.overrideProvider = function (token, provider) { };
/**
* @template T
* @param {?} token
* @param {?=} notFoundValue
* @param {?=} flags
* @return {?}
*/
TestBedStatic.prototype.get = function (token, notFoundValue, flags) { };
/**
* deprecated from v8.0.0 use Type<T> or InjectionToken<T>
* This does not use the deprecated jsdoc tag on purpose
* because it renders all overloads as deprecated in TSLint
* due to https://github.com/palantir/tslint/issues/4522.
* @param {?} token
* @param {?=} notFoundValue
* @return {?}
*/
TestBedStatic.prototype.get = function (token, notFoundValue) { };
/**
* @template T
* @param {?} component
* @return {?}
*/
TestBedStatic.prototype.createComponent = function (component) { };
}
/**
* @fileoverview added by tsickle
* @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
*/
/**
* Used to resolve resource URLs on `\@Component` when used with JIT compilation.
*
* Example:
* ```
* \@Component({
* selector: 'my-comp',
* templateUrl: 'my-comp.html', // This requires asynchronous resolution
* })
* class MyComponent{
* }
*
* // Calling `renderComponent` will fail because `renderComponent` is a synchronous process
* // and `MyComponent`'s `\@Component.templateUrl` needs to be resolved asynchronously.
*
* // Calling `resolveComponentResources()` will resolve `\@Component.templateUrl` into
* // `\@Component.template`, which allows `renderComponent` to proceed in a synchronous manner.
*
* // Use browser's `fetch()` function as the default resource resolution strategy.
* resolveComponentResources(fetch).then(() => {
* // After resolution all URLs have been converted into `template` strings.
* renderComponent(MyComponent);
* });
*
* ```
*
* NOTE: In AOT the resolution happens during compilation, and so there should be no need
* to call this method outside JIT mode.
*
* @param {?} resourceResolver a function which is responsible for returning a `Promise` to the
* contents of the resolved URL. Browser's `fetch()` method is a good default implementation.
* @return {?}
*/
function resolveComponentResources(resourceResolver) {
// Store all promises which are fetching the resources.
/** @type {?} */
const componentResolved = [];
// Cache so that we don't fetch the same resource more than once.
/** @type {?} */
const urlMap = new Map();
/**
* @param {?} url
* @return {?}
*/
function cachedResourceResolve(url) {
/** @type {?} */
let promise = urlMap.get(url);
if (!promise) {
/** @type {?} */
const resp = resourceResolver(url);
urlMap.set(url, promise = resp.then(unwrapResponse));
}
return promise;
}
componentResourceResolutionQueue.forEach((/**
* @param {?} component
* @param {?} type
* @return {?}
*/
(component, type) => {
/** @type {?} */
const promises = [];
if (component.templateUrl) {
promises.push(cachedResourceResolve(component.templateUrl).then((/**
* @param {?} template
* @return {?}
*/
(template) => {
component.template = template;
})));
}
/** @type {?} */
const styleUrls = component.styleUrls;
/** @type {?} */
const styles = component.styles || (component.styles = []);
/** @type {?} */
const styleOffset = component.styles.length;
styleUrls && styleUrls.forEach((/**
* @param {?} styleUrl
* @param {?} index
* @return {?}
*/
(styleUrl, index) => {
styles.push(''); // pre-allocate array.
promises.push(cachedResourceResolve(styleUrl).then((/**
* @param {?} style
* @return {?}
*/
(style) => {
styles[styleOffset + index] = style;
styleUrls.splice(styleUrls.indexOf(styleUrl), 1);
if (styleUrls.length == 0) {
component.styleUrls = undefined;
}
})));
}));
/** @type {?} */
const fullyResolved = Promise.all(promises).then((/**
* @return {?}
*/
() => componentDefResolved(type)));
componentResolved.push(fullyResolved);
}));
clearResolutionOfComponentResourcesQueue();
return Promise.all(componentResolved).then((/**
* @return {?}
*/
() => undefined));
}
/** @type {?} */
let componentResourceResolutionQueue = new Map();
// Track when existing ngComponentDef for a Type is waiting on resources.
/** @type {?} */
const componentDefPendingResolution = new Set();
/**
* @param {?} type
* @param {?} metadata
* @return {?}
*/
function maybeQueueResolutionOfComponentResources(type, metadata) {
if (componentNeedsResolution(metadata)) {
componentResourceResolutionQueue.set(type, metadata);
componentDefPendingResolution.add(type);
}
}
/**
* @param {?} type
* @return {?}
*/
function isComponentDefPendingResolution(type) {
return componentDefPendingResolution.has(type);
}
/**
* @param {?} component
* @return {?}
*/
function componentNeedsResolution(component) {
return !!((component.templateUrl && !component.hasOwnProperty('template')) ||
component.styleUrls && component.styleUrls.length);
}
/**
* @return {?}
*/
function clearResolutionOfComponentResourcesQueue() {
/** @type {?} */
const old = componentResourceResolutionQueue;
componentResourceResolutionQueue = new Map();
return old;
}
/**
* @param {?} queue
* @return {?}
*/
function restoreComponentResolutionQueue(queue) {
componentDefPendingResolution.clear();
queue.forEach((/**
* @param {?} _
* @param {?} type
* @return {?}
*/
(_, type) => componentDefPendingResolution.add(type)));
componentResourceResolutionQueue = queue;
}
/**
* @return {?}
*/
function isComponentResourceResolutionQueueEmpty() {
return componentResourceResolutionQueue.size === 0;
}
/**
* @param {?} response
* @return {?}
*/
function unwrapResponse(response) {
return typeof response == 'string' ? response : response.text();
}
/**
* @param {?} type
* @return {?}
*/
function componentDefResolved(type) {
componentDefPendingResolution.delete(type);
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
let _nextReferenceId = 0;
class MetadataOverrider {
constructor() {
this._references = new Map();
}
/**
* Creates a new instance for the given metadata class
* based on an old instance and overrides.
* @template C, T
* @param {?} metadataClass
* @param {?} oldMetadata
* @param {?} override
* @return {?}
*/
overrideMetadata(metadataClass, oldMetadata, override) {
/** @type {?} */
const props = {};
if (oldMetadata) {
_valueProps(oldMetadata).forEach((/**
* @param {?} prop
* @return {?}
*/
(prop) => props[prop] = ((/** @type {?} */ (oldMetadata)))[prop]));
}
if (override.set) {
if (override.remove || override.add) {
throw new Error(`Cannot set and add/remove ${ɵstringify(metadataClass)} at the same time!`);
}
setMetadata(props, override.set);
}
if (override.remove) {
removeMetadata(props, override.remove, this._references);
}
if (override.add) {
addMetadata(props, override.add);
}
return new metadataClass((/** @type {?} */ (props)));
}
}
if (false) {
/**
* @type {?}
* @private
*/
MetadataOverrider.prototype._references;
}
/**
* @param {?} metadata
* @param {?} remove
* @param {?} references
* @return {?}
*/
function removeMetadata(metadata, remove, references) {
/** @type {?} */
const removeObjects = new Set();
for (const prop in remove) {
/** @type {?} */
const removeValue = remove[prop];
if (removeValue instanceof Array) {
removeValue.forEach((/**
* @param {?} value
* @return {?}
*/
(value) => { removeObjects.add(_propHashKey(prop, value, references)); }));
}
else {
removeObjects.add(_propHashKey(prop, removeValue, references));
}
}
for (const prop in metadata) {
/** @type {?} */
const propValue = metadata[prop];
if (propValue instanceof Array) {
metadata[prop] = propValue.filter((/**
* @param {?} value
* @return {?}
*/
(value) => !removeObjects.has(_propHashKey(prop, value, references))));
}
else {
if (removeObjects.has(_propHashKey(prop, propValue, references))) {
metadata[prop] = undefined;
}
}
}
}
/**
* @param {?} metadata
* @param {?} add
* @return {?}
*/
function addMetadata(metadata, add) {
for (const prop in add) {
/** @type {?} */
const addValue = add[prop];
/** @type {?} */
const propValue = metadata[prop];
if (propValue != null && propValue instanceof Array) {
metadata[prop] = propValue.concat(addValue);
}
else {
metadata[prop] = addValue;
}
}
}
/**
* @param {?} metadata
* @param {?} set
* @return {?}
*/
function setMetadata(metadata, set) {
for (const prop in set) {
metadata[prop] = set[prop];
}
}
/**
* @param {?} propName
* @param {?} propValue
* @param {?} references
* @return {?}
*/
function _propHashKey(propName, propValue, references) {
/** @type {?} */
const replacer = (/**
* @param {?} key
* @param {?} value
* @return {?}
*/
(key, value) => {
if (typeof value === 'function') {
value = _serializeReference(value, references);
}
return value;
});
return `${propName}:${JSON.stringify(propValue, replacer)}`;
}
/**
* @param {?} ref
* @param {?} references
* @return {?}
*/
function _serializeReference(ref, references) {
/** @type {?} */
let id = references.get(ref);
if (!id) {
id = `${ɵstringify(ref)}${_nextReferenceId++}`;
references.set(ref, id);
}
return id;
}
/**
* @param {?} obj
* @return {?}
*/
function _valueProps(obj) {
/** @type {?} */
const props = [];
// regular public props
Object.keys(obj).forEach((/**
* @param {?} prop
* @return {?}
*/
(prop) => {
if (!prop.startsWith('_')) {
props.push(prop);
}
}));
// getters
/** @type {?} */
let proto = obj;
while (proto = Object.getPrototypeOf(proto)) {
Object.keys(proto).forEach((/**
* @param {?} protoProp
* @return {?}
*/
(protoProp) => {
/** @type {?} */
const desc = Object.getOwnPropertyDescriptor(proto, protoProp);
if (!protoProp.startsWith('_') && desc && 'get' in desc) {
props.push(protoProp);
}
}));
}
return props;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const reflection = new ɵReflectionCapabilities();
/**
* Base interface to resolve `\@Component`, `\@Directive`, `\@Pipe` and `\@NgModule`.
* @record
* @template T
*/
function Resolver() { }
if (false) {
/**
* @param {?} type
* @param {?} override
* @return {?}
*/
Resolver.prototype.addOverride = function (type, override) { };
/**
* @param {?} overrides
* @return {?}
*/
Resolver.prototype.setOverrides = function (overrides) { };
/**
* @param {?} type
* @return {?}
*/
Resolver.prototype.resolve = function (type) { };
}
/**
* Allows to override ivy metadata for tests (via the `TestBed`).
* @abstract
* @template T
*/
class OverrideResolver {
constructor() {
this.overrides = new Map();
this.resolved = new Map();
}
/**
* @param {?} type
* @param {?} override
* @return {?}
*/
addOverride(type, override) {
/** @type {?} */
const overrides = this.overrides.get(type) || [];
overrides.push(override);
this.overrides.set(type, overrides);
this.resolved.delete(type);
}
/**
* @param {?} overrides
* @return {?}
*/
setOverrides(overrides) {
this.overrides.clear();
overrides.forEach((/**
* @param {?} __0
* @return {?}
*/
([type, override]) => { this.addOverride(type, override); }));
}
/**
* @param {?} type
* @return {?}
*/
getAnnotation(type) {
/** @type {?} */
const annotations = reflection.annotations(type);
// Try to find the nearest known Type annotation and make sure that this annotation is an
// instance of the type we are looking for, so we can use it for resolution. Note: there might
// be multiple known annotations found due to the fact that Components can extend Directives (so
// both Directive and Component annotations would be present), so we always check if the known
// annotation has the right type.
for (let i = annotations.length - 1; i >= 0; i--) {
/** @type {?} */
const annotation = annotations[i];
/** @type {?} */
const isKnownType = annotation instanceof Directive || annotation instanceof Component ||
annotation instanceof Pipe || annotation instanceof NgModule;
if (isKnownType) {
return annotation instanceof this.type ? annotation : null;
}
}
return null;
}
/**
* @param {?} type
* @return {?}
*/
resolve(type) {
/** @type {?} */
let resolved = this.resolved.get(type) || null;
if (!resolved) {
resolved = this.getAnnotation(type);
if (resolved) {
/** @type {?} */
const overrides = this.overrides.get(type);
if (overrides) {
/** @type {?} */
const overrider = new MetadataOverrider();
overrides.forEach((/**
* @param {?} override
* @return {?}
*/
override => {
resolved = overrider.overrideMetadata(this.type, (/** @type {?} */ (resolved)), override);
}));
}
}
this.resolved.set(type, resolved);
}
return resolved;
}
}
if (false) {
/**
* @type {?}
* @private
*/
OverrideResolver.prototype.overrides;
/**
* @type {?}
* @private
*/
OverrideResolver.prototype.resolved;
/**
* @abstract
* @return {?}
*/
OverrideResolver.prototype.type = function () { };
}
class DirectiveResolver extends OverrideResolver {
/**
* @return {?}
*/
get type() { return Directive; }
}
class ComponentResolver extends OverrideResolver {
/**
* @return {?}
*/
get type() { return Component; }
}
class PipeResolver extends OverrideResolver {
/**
* @return {?}
*/
get type() { return Pipe; }
}
class NgModuleResolver extends OverrideResolver {
/**
* @return {?}
*/
get type() { return NgModule; }
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
const TestingModuleOverride = {
DECLARATION: 0,
OVERRIDE_TEMPLATE: 1,
};
TestingModuleOverride[TestingModuleOverride.DECLARATION] = 'DECLARATION';
TestingModuleOverride[TestingModuleOverride.OVERRIDE_TEMPLATE] = 'OVERRIDE_TEMPLATE';
/**
* @param {?} value
* @return {?}
*/
function isTestingModuleOverride(value) {
return value === TestingModuleOverride.DECLARATION ||
value === TestingModuleOverride.OVERRIDE_TEMPLATE;
}
/**
* @record
*/
function CleanupOperation() { }
if (false) {
/** @type {?} */
CleanupOperation.prototype.field;
/** @type {?} */
CleanupOperation.prototype.def;
/** @type {?} */
CleanupOperation.prototype.original;
}
class R3TestBedCompiler {
/**
* @param {?} platform
* @param {?} additionalModuleTypes
*/
constructor(platform, additionalModuleTypes) {
this.platform = platform;
this.additionalModuleTypes = additionalModuleTypes;
this.originalComponentResolutionQueue = null;
// Testing module configuration
this.declarations = [];
this.imports = [];
this.providers = [];
this.schemas = [];
// Queues of components/directives/pipes that should be recompiled.
this.pendingComponents = new Set();
this.pendingDirectives = new Set();
this.pendingPipes = new Set();
// Keep track of all components and directives, so we can patch Providers onto defs later.
this.seenComponents = new Set();
this.seenDirectives = new Set();
// Store resolved styles for Components that have template overrides present and `styleUrls`
// defined at the same time.
this.existingComponentStyles = new Map();
this.resolvers = initResolvers();
this.componentToModuleScope = new Map();
// Map that keeps initial version of component/directive/pipe defs in case
// we compile a Type again, thus overriding respective static fields. This is
// required to make sure we restore defs to their initial states between test runs
// TODO: we should support the case with multiple defs on a type
this.initialNgDefs = new Map();
// Array that keeps cleanup operations for initial versions of component/directive/pipe/module
// defs in case TestBed makes changes to the originals.
this.defClean