| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-02 09:43:52 -07:00
										 |  |  | // Import zero symbols from zone.js. This causes the zone ambient type to be
 | 
					
						
							|  |  |  | // added to the type-checker, without emitting any runtime module load statement
 | 
					
						
							|  |  |  | import {} from 'zone.js'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-01 15:18:10 -08:00
										 |  |  | // TODO(jteplitz602): Load WorkerGlobalScope from lib.webworker.d.ts file #3492
 | 
					
						
							|  |  |  | declare var WorkerGlobalScope: any /** TODO #9100 */; | 
					
						
							|  |  |  | // CommonJS / Node have global context exposed as "global" variable.
 | 
					
						
							|  |  |  | // We don't want to include the whole node.d.ts this this compilation unit so we'll just fake
 | 
					
						
							|  |  |  | // the global "global" var for now.
 | 
					
						
							|  |  |  | declare var global: any /** TODO #9100 */; | 
					
						
							|  |  |  | const __window = typeof window !== 'undefined' && window; | 
					
						
							|  |  |  | const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && | 
					
						
							|  |  |  |     self instanceof WorkerGlobalScope && self; | 
					
						
							|  |  |  | const __global = typeof global !== 'undefined' && global; | 
					
						
							|  |  |  | const _global: {[name: string]: any} = __window || __global || __self; | 
					
						
							| 
									
										
										
										
											2017-11-28 16:23:24 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | const promise: Promise<any> = Promise.resolve(0); | 
					
						
							| 
									
										
										
										
											2017-09-26 15:02:33 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Attention: whenever providing a new value, be sure to add an | 
					
						
							|  |  |  |  * entry into the corresponding `....externs.js` file, | 
					
						
							|  |  |  |  * so that closure won't use that global for its purposes. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-01 15:18:10 -08:00
										 |  |  | export {_global as global}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // When Symbol.iterator doesn't exist, retrieves the key used in es6-shim
 | 
					
						
							|  |  |  | declare const Symbol: any; | 
					
						
							|  |  |  | let _symbolIterator: any = null; | 
					
						
							|  |  |  | export function getSymbolIterator(): string|symbol { | 
					
						
							|  |  |  |   if (!_symbolIterator) { | 
					
						
							| 
									
										
										
										
											2017-03-02 09:37:01 -08:00
										 |  |  |     const Symbol = _global['Symbol']; | 
					
						
							| 
									
										
										
										
											2017-03-01 15:18:10 -08:00
										 |  |  |     if (Symbol && Symbol.iterator) { | 
					
						
							|  |  |  |       _symbolIterator = Symbol.iterator; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       // es6-shim specific logic
 | 
					
						
							|  |  |  |       const keys = Object.getOwnPropertyNames(Map.prototype); | 
					
						
							|  |  |  |       for (let i = 0; i < keys.length; ++i) { | 
					
						
							|  |  |  |         const key = keys[i]; | 
					
						
							|  |  |  |         if (key !== 'entries' && key !== 'size' && | 
					
						
							|  |  |  |             (Map as any).prototype[key] === Map.prototype['entries']) { | 
					
						
							|  |  |  |           _symbolIterator = key; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return _symbolIterator; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function scheduleMicroTask(fn: Function) { | 
					
						
							| 
									
										
										
										
											2017-11-28 16:23:24 +09:00
										 |  |  |   if (typeof Zone === 'undefined') { | 
					
						
							|  |  |  |     // use promise to schedule microTask instead of use Zone
 | 
					
						
							|  |  |  |     promise.then(() => { fn && fn.apply(null, null); }); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Zone.current.scheduleMicroTask('scheduleMicrotask', fn); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-01 15:18:10 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-02 09:37:01 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // JS has NaN !== NaN
 | 
					
						
							|  |  |  | export function looseIdentical(a: any, b: any): boolean { | 
					
						
							|  |  |  |   return a === b || typeof a === 'number' && typeof b === 'number' && isNaN(a) && isNaN(b); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function stringify(token: any): string { | 
					
						
							|  |  |  |   if (typeof token === 'string') { | 
					
						
							|  |  |  |     return token; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-27 13:49:33 -07:00
										 |  |  |   if (token instanceof Array) { | 
					
						
							|  |  |  |     return '[' + token.map(stringify).join(', ') + ']'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 09:37:01 -08:00
										 |  |  |   if (token == null) { | 
					
						
							|  |  |  |     return '' + token; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (token.overriddenName) { | 
					
						
							|  |  |  |     return `${token.overriddenName}`; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (token.name) { | 
					
						
							|  |  |  |     return `${token.name}`; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const res = token.toString(); | 
					
						
							| 
									
										
										
										
											2017-03-07 10:31:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (res == null) { | 
					
						
							|  |  |  |     return '' + res; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 09:37:01 -08:00
										 |  |  |   const newLineIndex = res.indexOf('\n'); | 
					
						
							|  |  |  |   return newLineIndex === -1 ? res : res.substring(0, newLineIndex); | 
					
						
							|  |  |  | } |