From 9ebe42370a0f76c86dd3228d7baeb8f96f910a91 Mon Sep 17 00:00:00 2001 From: arturovt Date: Fri, 4 Dec 2020 12:58:53 +0200 Subject: [PATCH] perf(animations): use `ngDevMode` to tree-shake warning (#39964) This commit adds ngDevMode guard to show warning only in dev mode (similar to how things work in other parts of Ivy runtime code). The ngDevMode flag helps to tree-shake this warning from production builds (in dev mode everything will work as it works right now) to decrease production bundle size. PR Close #39964 --- .../css_keyframes/css_keyframes_driver.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/animations/browser/src/render/css_keyframes/css_keyframes_driver.ts b/packages/animations/browser/src/render/css_keyframes/css_keyframes_driver.ts index 3653a20d5a..c4a6d20987 100644 --- a/packages/animations/browser/src/render/css_keyframes/css_keyframes_driver.ts +++ b/packages/animations/browser/src/render/css_keyframes/css_keyframes_driver.ts @@ -21,7 +21,6 @@ const TAB_SPACE = ' '; export class CssKeyframesDriver implements AnimationDriver { private _count = 0; private readonly _head: any = document.querySelector('head'); - private _warningIssued = false; validateStyleProperty(prop: string): boolean { return validateStyleProperty(prop); @@ -79,8 +78,8 @@ export class CssKeyframesDriver implements AnimationDriver { animate( element: any, keyframes: ɵStyleData[], duration: number, delay: number, easing: string, previousPlayers: AnimationPlayer[] = [], scrubberAccessRequested?: boolean): AnimationPlayer { - if (scrubberAccessRequested) { - this._notifyFaultyScrubber(); + if ((typeof ngDevMode === 'undefined' || ngDevMode) && scrubberAccessRequested) { + notifyFaultyScrubber(); } const previousCssKeyframePlayers = previousPlayers.filter( @@ -117,15 +116,6 @@ export class CssKeyframesDriver implements AnimationDriver { player.onDestroy(() => removeElement(kfElm)); return player; } - - private _notifyFaultyScrubber() { - if (!this._warningIssued) { - console.warn( - '@angular/animations: please load the web-animations.js polyfill to allow programmatic access...\n', - ' visit https://bit.ly/IWukam to learn more about using the web-animation-js polyfill.'); - this._warningIssued = true; - } - } } function flattenKeyframesIntoStyles(keyframes: null|{[key: string]: any}| @@ -146,3 +136,12 @@ function flattenKeyframesIntoStyles(keyframes: null|{[key: string]: any}| function removeElement(node: any) { node.parentNode.removeChild(node); } + +let warningIssued = false; +function notifyFaultyScrubber(): void { + if (warningIssued) return; + console.warn( + '@angular/animations: please load the web-animations.js polyfill to allow programmatic access...\n', + ' visit https://bit.ly/IWukam to learn more about using the web-animation-js polyfill.'); + warningIssued = true; +}