fix: don’t use the global `ng` at all with closure enhanced optimizations

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....')`).
This commit is contained in:
Tobias Bosch 2017-09-26 19:41:08 -07:00 committed by Victor Berchet
parent b21a1d1961
commit a7798f2a93
5 changed files with 29 additions and 10 deletions

View File

@ -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}
*/

15
packages/goog.d.ts vendored Normal file
View File

@ -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;
}

View File

@ -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;

View File

@ -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": {

1
packages/types.d.ts vendored
View File

@ -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" />