2019-01-09 13:49:16 -08:00
|
|
|
/**
|
|
|
|
|
* @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.
|
|
|
|
|
*/
|
2020-02-21 11:08:59 -08:00
|
|
|
export function noSideEffects<T>(fn: () => T): T {
|
|
|
|
|
return {toString: fn}.toString() as unknown as T;
|
|
|
|
|
}
|