diff --git a/packages/core/src/core.externs.js b/packages/core/src/core.externs.js index 8ee983fc7e..936424081b 100644 --- a/packages/core/src/core.externs.js +++ b/packages/core/src/core.externs.js @@ -8,10 +8,10 @@ * @externs */ -/** - * @suppress {duplicate} - */ -var ng; +// Note: we can't declare an extern for the global variable `ng` as +// the namespace `ng` is already used within Google +// for typings for angularJS (via `goog.provide('ng....')`). + /** * @suppress {duplicate} */ diff --git a/packages/goog.d.ts b/packages/goog.d.ts new file mode 100644 index 0000000000..063601d738 --- /dev/null +++ b/packages/goog.d.ts @@ -0,0 +1,15 @@ +/** + * @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 + */ + + +/** + * Typings for google closure. + */ +declare namespace goog { + export const DEBUG: boolean; +} diff --git a/packages/platform-browser/src/dom/util.ts b/packages/platform-browser/src/dom/util.ts index efbbbdb71a..6a0ea7b7e4 100644 --- a/packages/platform-browser/src/dom/util.ts +++ b/packages/platform-browser/src/dom/util.ts @@ -28,10 +28,12 @@ export function dashCaseToCamelCase(input: string): string { * @param value The value to export. */ export function exportNgVar(name: string, value: any): void { - if (!ng) { - global['ng'] = ng = (global['ng'] as{[key: string]: any} | undefined) || {}; + if (typeof goog === 'undefined' || goog.DEBUG) { + // Note: we can't export `ng` when using closure enhanced optimization as: + // - closure declares globals itself for minified names, which sometimes clobber our `ng` global + // - we can't declare a closure extern as the namespace `ng` is already used within Google + // for typings for angularJS (via `goog.provide('ng....')`). + const ng = global['ng'] = (global['ng'] as{[key: string]: any} | undefined) || {}; + ng[name] = value; } - ng[name] = value; } - -let ng: {[key: string]: any}|undefined; diff --git a/packages/platform-browser/tsconfig-build.json b/packages/platform-browser/tsconfig-build.json index cf4b567c7e..f1c58e2ef6 100644 --- a/packages/platform-browser/tsconfig-build.json +++ b/packages/platform-browser/tsconfig-build.json @@ -15,7 +15,8 @@ "files": [ "public_api.ts", "../../node_modules/@types/hammerjs/index.d.ts", - "../../node_modules/zone.js/dist/zone.js.d.ts" + "../../node_modules/zone.js/dist/zone.js.d.ts", + "../goog.d.ts" ], "angularCompilerOptions": { diff --git a/packages/types.d.ts b/packages/types.d.ts index 009398d12f..30d6280539 100644 --- a/packages/types.d.ts +++ b/packages/types.d.ts @@ -15,3 +15,4 @@ /// /// /// +///