From 788656199788790a073531a1ea0e90d550c4cfb9 Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Fri, 11 Nov 2016 21:46:53 +0300 Subject: [PATCH] fix(router): check if windows.console exists before using it (#12348) --- .../src/browser/browser_adapter.ts | 30 ++++++++++++++----- .../src/private_import_platform-browser.ts | 10 +++++++ modules/@angular/router/src/router_module.ts | 12 ++++---- modules/@angular/router/tsconfig-upgrade.json | 1 + scripts/ci-lite/build.sh | 1 + 5 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 modules/@angular/router/src/private_import_platform-browser.ts diff --git a/modules/@angular/platform-browser/src/browser/browser_adapter.ts b/modules/@angular/platform-browser/src/browser/browser_adapter.ts index 57f924b682..eace0bf914 100644 --- a/modules/@angular/platform-browser/src/browser/browser_adapter.ts +++ b/modules/@angular/platform-browser/src/browser/browser_adapter.ts @@ -77,16 +77,30 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { invoke(el: Node, methodName: string, args: any[]): any { (el)[methodName](...args); } // TODO(tbosch): move this into a separate environment class once we have it - logError(error: string) { (window.console.error || window.console.log)(error); } - - log(error: string) { window.console.log(error); } - - logGroup(error: string) { - window.console.group && window.console.group(error); - this.logError(error); + logError(error: string): void { + if (window.console) { + (window.console.error || window.console.log)(error); + } } - logGroupEnd() { window.console.groupEnd && window.console.groupEnd(); } + log(error: string): void { + if (window.console) { + window.console.log && window.console.log(error); + } + } + + logGroup(error: string): void { + if (window.console) { + window.console.group && window.console.group(error); + this.logError(error); + } + } + + logGroupEnd(): void { + if (window.console) { + window.console.groupEnd && window.console.groupEnd(); + } + } get attrToPropMap(): any { return _attrToPropMap; } diff --git a/modules/@angular/router/src/private_import_platform-browser.ts b/modules/@angular/router/src/private_import_platform-browser.ts new file mode 100644 index 0000000000..1b82a8c95e --- /dev/null +++ b/modules/@angular/router/src/private_import_platform-browser.ts @@ -0,0 +1,10 @@ +/** + * @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 + */ +import {__platform_browser_private__ as r} from '@angular/platform-browser'; + +export var getDOM: typeof r.getDOM = r.getDOM; diff --git a/modules/@angular/router/src/router_module.ts b/modules/@angular/router/src/router_module.ts index 9144c820d6..d4ae762ffe 100644 --- a/modules/@angular/router/src/router_module.ts +++ b/modules/@angular/router/src/router_module.ts @@ -8,10 +8,12 @@ import {APP_BASE_HREF, HashLocationStrategy, Location, LocationStrategy, PathLocationStrategy, PlatformLocation} from '@angular/common'; import {ANALYZE_FOR_ENTRY_COMPONENTS, APP_BOOTSTRAP_LISTENER, ApplicationRef, Compiler, Inject, Injector, ModuleWithProviders, NgModule, NgModuleFactoryLoader, OpaqueToken, Optional, Provider, SkipSelf, SystemJsNgModuleLoader} from '@angular/core'; + import {Route, Routes} from './config'; import {RouterLink, RouterLinkWithHref} from './directives/router_link'; import {RouterLinkActive} from './directives/router_link_active'; import {RouterOutlet} from './directives/router_outlet'; +import {getDOM} from './private_import_platform-browser'; import {ErrorHandler, Router} from './router'; import {ROUTES} from './router_config_loader'; import {RouterOutletMap} from './router_outlet_map'; @@ -22,7 +24,6 @@ import {DefaultUrlSerializer, UrlSerializer} from './url_tree'; import {flatten} from './utils/collection'; - /** * @whatItDoes Contains a list of directives * @stable @@ -249,11 +250,12 @@ export function setupRouter( } if (opts.enableTracing) { + const dom = getDOM(); router.events.subscribe(e => { - console.group(`Router Event: ${(e.constructor).name}`); - console.log(e.toString()); - console.log(e); - console.groupEnd(); + dom.logGroup(`Router Event: ${(e.constructor).name}`); + dom.log(e.toString()); + dom.log(e); + dom.logGroupEnd(); }); } diff --git a/modules/@angular/router/tsconfig-upgrade.json b/modules/@angular/router/tsconfig-upgrade.json index 5c4f78dad4..afa6c8a97b 100644 --- a/modules/@angular/router/tsconfig-upgrade.json +++ b/modules/@angular/router/tsconfig-upgrade.json @@ -13,6 +13,7 @@ "outDir": "../../../dist/packages-dist/router", "paths": { "@angular/core": ["../../../dist/packages-dist/core"], + "@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"], "@angular/router": ["../../../dist/packages-dist/router"], "@angular/upgrade/static": ["../../../dist/packages-dist/upgrade/static"] }, diff --git a/scripts/ci-lite/build.sh b/scripts/ci-lite/build.sh index 5510b9e1dc..d960503eef 100755 --- a/scripts/ci-lite/build.sh +++ b/scripts/ci-lite/build.sh @@ -15,6 +15,7 @@ cp tools/@angular/tsc-wrapped/package.json dist/tools/@angular/tsc-wrapped node --max-old-space-size=3000 dist/tools/@angular/tsc-wrapped/src/main -p modules node dist/tools/@angular/tsc-wrapped/src/main -p modules/@angular/core/tsconfig-build.json node dist/tools/@angular/tsc-wrapped/src/main -p modules/@angular/common/tsconfig-build.json +node dist/tools/@angular/tsc-wrapped/src/main -p modules/@angular/platform-browser/tsconfig-build.json node dist/tools/@angular/tsc-wrapped/src/main -p modules/@angular/router/tsconfig-build.json echo 'travis_fold:end:BUILD'