refactor: remove `global` from facade/lang (#14837)
This commit is contained in:
parent
b0e0839075
commit
84a65cf788
|
@ -14,7 +14,8 @@ import {merge} from 'rxjs/observable/merge';
|
|||
import {share} from 'rxjs/operator/share';
|
||||
|
||||
import {ErrorHandler} from '../src/error_handler';
|
||||
import {scheduleMicroTask, stringify} from '../src/facade/lang';
|
||||
import {stringify} from '../src/facade/lang';
|
||||
import {scheduleMicroTask} from '../src/util';
|
||||
import {isPromise} from '../src/util/lang';
|
||||
|
||||
import {ApplicationInitStatus} from './application_init';
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {getSymbolIterator, isJsObject, isPrimitive, looseIdentical} from '../facade/lang';
|
||||
import {isJsObject, isPrimitive, looseIdentical} from '../facade/lang';
|
||||
import {getSymbolIterator} from '../util';
|
||||
|
||||
export {looseIdentical} from '../facade/lang';
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*/
|
||||
export * from './metadata';
|
||||
export * from './version';
|
||||
export * from './util';
|
||||
export {Class, ClassDefinition, TypeDecorator} from './util/decorators';
|
||||
export * from './di';
|
||||
export {createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, enableProdMode, isDevMode, createPlatformFactory, NgProbeToken} from './application_ref';
|
||||
export {APP_ID, PACKAGE_ROOT_URL, PLATFORM_INITIALIZER, PLATFORM_ID, APP_BOOTSTRAP_LISTENER} from './application_tokens';
|
||||
|
|
|
@ -23,5 +23,6 @@ export {ReflectionCapabilities as ɵReflectionCapabilities} from './reflection/r
|
|||
export {ReflectorReader as ɵReflectorReader} from './reflection/reflector_reader';
|
||||
export {GetterFn as ɵGetterFn, MethodFn as ɵMethodFn, SetterFn as ɵSetterFn} from './reflection/types';
|
||||
export {DirectRenderer as ɵDirectRenderer, RenderDebugInfo as ɵRenderDebugInfo} from './render/api';
|
||||
export {global as ɵglobal} from './util';
|
||||
export {makeDecorator as ɵmakeDecorator} from './util/decorators';
|
||||
export {isObservable as ɵisObservable, isPromise as ɵisPromise, merge as ɵmerge} from './util/lang';
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
import {EventEmitter} from '../event_emitter';
|
||||
import {getSymbolIterator} from '../facade/lang';
|
||||
import {getSymbolIterator} from '../util';
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {global} from '../facade/lang';
|
||||
import {global} from '../util';
|
||||
|
||||
/**
|
||||
* A scope function for the Web Tracing Framework (WTF).
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {global, isPresent, stringify} from '../facade/lang';
|
||||
import {isPresent, stringify} from '../facade/lang';
|
||||
import {Type, isType} from '../type';
|
||||
|
||||
import {global} from '../util';
|
||||
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
|
||||
import {GetterFn, MethodFn, SetterFn} from './types';
|
||||
|
||||
|
@ -21,7 +21,7 @@ export const DELEGATE_CTOR =
|
|||
export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
private _reflect: any;
|
||||
|
||||
constructor(reflect?: any) { this._reflect = reflect || global.Reflect; }
|
||||
constructor(reflect?: any) { this._reflect = reflect || global['Reflect']; }
|
||||
|
||||
isReflectionEnabled(): boolean { return true; }
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {Injectable} from '../di';
|
||||
import {scheduleMicroTask} from '../facade/lang';
|
||||
import {scheduleMicroTask} from '../util';
|
||||
import {NgZone} from '../zone/ng_zone';
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,5 +6,42 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
// Public API for util
|
||||
export {Class, ClassDefinition, TypeDecorator} from './util/decorators';
|
||||
// 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;
|
||||
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) {
|
||||
var Symbol = _global['Symbol'];
|
||||
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) {
|
||||
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {global, stringify} from '../facade/lang';
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {global} from '../util';
|
||||
|
||||
let _nextClassId = 0;
|
||||
const Reflect = global.Reflect;
|
||||
const Reflect = global['Reflect'];
|
||||
|
||||
/**
|
||||
* Declares the interface to be used with {@link Class}.
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {getSymbolIterator} from '../../src/facade/lang';
|
||||
import {getSymbolIterator} from '@angular/core/src/util';
|
||||
|
||||
export class TestIterable {
|
||||
list: number[];
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {global} from '@angular/common/src/facade/lang';
|
||||
import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
|
||||
import {global} from '@angular/core/src/util';
|
||||
import {async} from '@angular/core/testing';
|
||||
import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal';
|
||||
|
||||
|
@ -24,14 +24,14 @@ export function main() {
|
|||
describe('SystemJsNgModuleLoader', () => {
|
||||
let oldSystem: any = null;
|
||||
beforeEach(() => {
|
||||
oldSystem = (global as any).System;
|
||||
(global as any).System = mockSystem({
|
||||
oldSystem = global['System'];
|
||||
global['System'] = mockSystem({
|
||||
'test.ngfactory':
|
||||
{'default': 'test module factory', 'NamedNgFactory': 'test NamedNgFactory'},
|
||||
'prefixed/test/suffixed': {'NamedNgFactory': 'test module factory'}
|
||||
});
|
||||
});
|
||||
afterEach(() => { (global as any).System = oldSystem; });
|
||||
afterEach(() => { global['System'] = oldSystem; });
|
||||
|
||||
it('loads a default factory by appending the factory suffix', async(() => {
|
||||
const loader = new SystemJsNgModuleLoader(new Compiler());
|
||||
|
|
|
@ -12,7 +12,7 @@ import {Testability} from '@angular/core/src/testability/testability';
|
|||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
import {AsyncTestCompleter, SpyObject, beforeEach, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {scheduleMicroTask} from '../../src/facade/lang';
|
||||
import {scheduleMicroTask} from '../../src/util';
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,15 +8,14 @@
|
|||
|
||||
import {Inject} from '@angular/core';
|
||||
import {reflector} from '@angular/core/src/reflection/reflection';
|
||||
import {global} from '@angular/core/src/util';
|
||||
import {Class, makeDecorator, makePropDecorator} from '@angular/core/src/util/decorators';
|
||||
|
||||
import {global} from '../../src/facade/lang';
|
||||
|
||||
class DecoratedParent {}
|
||||
class DecoratedChild extends DecoratedParent {}
|
||||
|
||||
export function main() {
|
||||
const Reflect = global.Reflect;
|
||||
const Reflect = global['Reflect'];
|
||||
|
||||
const TerminalDecorator = makeDecorator('TerminalDecorator', {terminal: true});
|
||||
const TestDecorator = makeDecorator(
|
||||
|
|
|
@ -10,7 +10,8 @@ import {NgZone} from '@angular/core/src/zone/ng_zone';
|
|||
import {async, fakeAsync, flushMicrotasks} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, Log, beforeEach, describe, expect, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/browser_util';
|
||||
import {isPresent, scheduleMicroTask} from '../../src/facade/lang';
|
||||
import {isPresent} from '../../src/facade/lang';
|
||||
import {scheduleMicroTask} from '../../src/util';
|
||||
|
||||
const needsLongerTimers = browserDetection.isSlow || browserDetection.isEdge;
|
||||
const resultTimer = 1000;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, NgZone, getDebugNode} from '@angular/core';
|
||||
import {scheduleMicroTask} from './facade/lang';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -186,3 +185,7 @@ export class ComponentFixture<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleMicroTask(fn: Function) {
|
||||
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
*/
|
||||
|
||||
import {ɵisPromise as isPromise, ɵmerge as merge} from '@angular/core';
|
||||
import {global} from '@angular/core/src/util';
|
||||
|
||||
import {AsyncTestCompleter} from './async_test_completer';
|
||||
import {global} from './facade/lang';
|
||||
import {getTestBed, inject} from './test_bed';
|
||||
|
||||
export {AsyncTestCompleter} from './async_test_completer';
|
||||
|
|
|
@ -6,68 +6,11 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
export interface BrowserNodeGlobal {
|
||||
Object: typeof Object;
|
||||
Array: typeof Array;
|
||||
Map: typeof Map;
|
||||
Set: typeof Set;
|
||||
Date: DateConstructor;
|
||||
RegExp: RegExpConstructor;
|
||||
JSON: typeof JSON;
|
||||
Math: any; // typeof Math;
|
||||
assert(condition: any): void;
|
||||
Reflect: any;
|
||||
getAngularTestability: Function;
|
||||
getAllAngularTestabilities: Function;
|
||||
getAllAngularRootElements: Function;
|
||||
frameworkStabilizers: Array<Function>;
|
||||
setTimeout: Function;
|
||||
clearTimeout: Function;
|
||||
setInterval: Function;
|
||||
clearInterval: Function;
|
||||
encodeURI: Function;
|
||||
}
|
||||
|
||||
// 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 */;
|
||||
|
||||
let globalScope: BrowserNodeGlobal;
|
||||
if (typeof window === 'undefined') {
|
||||
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
|
||||
// TODO: Replace any with WorkerGlobalScope from lib.webworker.d.ts #3492
|
||||
globalScope = <any>self;
|
||||
} else {
|
||||
globalScope = <any>global;
|
||||
}
|
||||
} else {
|
||||
globalScope = <any>window;
|
||||
}
|
||||
|
||||
export function scheduleMicroTask(fn: Function) {
|
||||
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
||||
}
|
||||
|
||||
// Need to declare a new variable for global here since TypeScript
|
||||
// exports the original value of the symbol.
|
||||
const _global: BrowserNodeGlobal = globalScope;
|
||||
|
||||
export {_global as global};
|
||||
|
||||
export function getTypeNameForDebugging(type: any): string {
|
||||
return type['name'] || typeof type;
|
||||
}
|
||||
|
||||
// TODO: remove calls to assert in production environment
|
||||
// Note: Can't just export this and import in in other files
|
||||
// as `assert` is a reserved keyword in Dart
|
||||
_global.assert = function assert(condition) {
|
||||
// TODO: to be fixed properly via #2830, noop for now
|
||||
};
|
||||
|
||||
export function isPresent(obj: any): boolean {
|
||||
return obj != null;
|
||||
}
|
||||
|
@ -150,28 +93,6 @@ export function setValueOnPath(global: any, path: string, value: any) {
|
|||
obj[parts.shift()] = value;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if ((<any>globalScope).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 isPrimitive(obj: any): boolean {
|
||||
return !isJsObject(obj);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {ResourceLoader} from '@angular/compiler';
|
||||
import {global} from '../facade/lang';
|
||||
import {ɵglobal as global} from '@angular/core';
|
||||
|
||||
/**
|
||||
* An implementation of ResourceLoader that uses a template cache to avoid doing an actual
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ɵglobal as global} from '@angular/core';
|
||||
import {setRootDomAdapter} from '../dom/dom_adapter';
|
||||
import {global, isBlank, isPresent, setValueOnPath} from '../facade/lang';
|
||||
import {isBlank, isPresent, setValueOnPath} from '../facade/lang';
|
||||
|
||||
import {GenericBrowserDomAdapter} from './generic_browser_adapter';
|
||||
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {GetTestability, Testability, TestabilityRegistry, setTestabilityGetter} from '@angular/core';
|
||||
import {GetTestability, Testability, TestabilityRegistry, setTestabilityGetter, ɵglobal as global} from '@angular/core';
|
||||
|
||||
import {getDOM} from '../dom/dom_adapter';
|
||||
import {global, isPresent} from '../facade/lang';
|
||||
import {isPresent} from '../facade/lang';
|
||||
|
||||
export class BrowserGetTestability implements GetTestability {
|
||||
static init() { setTestabilityGetter(new BrowserGetTestability()); }
|
||||
|
||||
addToWindow(registry: TestabilityRegistry): void {
|
||||
global.getAngularTestability = (elem: any, findInAncestors: boolean = true) => {
|
||||
global['getAngularTestability'] = (elem: any, findInAncestors: boolean = true) => {
|
||||
const testability = registry.findTestabilityInTree(elem, findInAncestors);
|
||||
if (testability == null) {
|
||||
throw new Error('Could not find testability for element.');
|
||||
|
@ -23,12 +23,12 @@ export class BrowserGetTestability implements GetTestability {
|
|||
return testability;
|
||||
};
|
||||
|
||||
global.getAllAngularTestabilities = () => registry.getAllTestabilities();
|
||||
global['getAllAngularTestabilities'] = () => registry.getAllTestabilities();
|
||||
|
||||
global.getAllAngularRootElements = () => registry.getAllRootElements();
|
||||
global['getAllAngularRootElements'] = () => registry.getAllRootElements();
|
||||
|
||||
const whenAllStable = (callback: any /** TODO #9100 */) => {
|
||||
const testabilities = global.getAllAngularTestabilities();
|
||||
const testabilities = global['getAllAngularTestabilities']();
|
||||
let count = testabilities.length;
|
||||
let didWork = false;
|
||||
const decrement = function(didWork_: any /** TODO #9100 */) {
|
||||
|
|
|
@ -6,12 +6,10 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ReflectiveInjector} from '@angular/core';
|
||||
import {ReflectiveInjector, ɵglobal as global} from '@angular/core';
|
||||
import {ApplicationRef, ApplicationRef_} from '@angular/core/src/application_ref';
|
||||
import {SpyObject} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {global} from '../../../src/facade/lang';
|
||||
|
||||
export class SpyApplicationRef extends SpyObject {
|
||||
constructor() { super(ApplicationRef_); }
|
||||
}
|
||||
|
|
|
@ -6,11 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgZone} from '@angular/core';
|
||||
import {NgZone, ɵglobal as global} from '@angular/core';
|
||||
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
|
||||
import {global} from './facade/lang';
|
||||
|
||||
export let browserDetection: BrowserDetection;
|
||||
|
||||
export class BrowserDetection {
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
*/
|
||||
|
||||
|
||||
import {ɵglobal as global} from '@angular/core';
|
||||
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
|
||||
import {global} from './facade/lang';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,6 @@ import {Inject, Injectable, Optional} from '@angular/core';
|
|||
import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
import {Subject} from 'rxjs/Subject';
|
||||
import * as url from 'url';
|
||||
import {scheduleMicroTask} from './facade/lang';
|
||||
import {INITIAL_CONFIG, PlatformConfig} from './tokens';
|
||||
|
||||
|
||||
|
@ -88,3 +87,7 @@ export class ServerPlatformLocation implements PlatformLocation {
|
|||
|
||||
back(): void { throw new Error('Not implemented'); }
|
||||
}
|
||||
|
||||
export function scheduleMicroTask(fn: Function) {
|
||||
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
const parse5 = require('parse5');
|
||||
|
||||
import {ɵglobal as global} from '@angular/core';
|
||||
import {ɵDomAdapter as DomAdapter, ɵsetRootDomAdapter as setRootDomAdapter} from '@angular/platform-browser';
|
||||
import {isPresent, isBlank, global, setValueOnPath} from '../src/facade/lang';
|
||||
import {isPresent, isBlank, setValueOnPath} from '../src/facade/lang';
|
||||
import {SelectorMatcher, CssSelector} from '@angular/compiler';
|
||||
|
||||
let treeAdapter: any;
|
||||
|
|
Loading…
Reference in New Issue