Skip to content

Commit

Permalink
fix: don’t use the global ng at all with closure enhanced optimizat…
Browse files Browse the repository at this point in the history
…ions

This is needed 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....')`).
  • Loading branch information
tbosch authored and vicb committed Sep 27, 2017
1 parent b21a1d1 commit a7798f2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/core.externs.js
Expand Up @@ -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}
*/
Expand Down
15 changes: 15 additions & 0 deletions 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;
}
12 changes: 7 additions & 5 deletions packages/platform-browser/src/dom/util.ts
Expand Up @@ -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;
3 changes: 2 additions & 1 deletion packages/platform-browser/tsconfig-build.json
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/types.d.ts
Expand Up @@ -15,3 +15,4 @@
/// <reference path="../node_modules/@types/selenium-webdriver/index.d.ts" />
/// <reference path="./es6-subset.d.ts" />
/// <reference path="./system.d.ts" />
/// <reference path="./goog.d.ts" />

0 comments on commit a7798f2

Please sign in to comment.