refactor: remove toplevel property accesses (#29329)

PR Close #29329
This commit is contained in:
Filipe Silva
2019-05-02 16:44:24 +01:00
committed by Jason Aden
parent 739e5a4f53
commit ac34a1429b
32 changed files with 231 additions and 253 deletions

View File

@ -63,13 +63,15 @@ const _chromeNumKeyPadMap = {
'\x90': 'NumLock'
};
let nodeContains: (a: any, b: any) => boolean;
const nodeContains: (a: any, b: any) => boolean = (() => {
if (global['Node']) {
return global['Node'].prototype.contains || function(node: any) {
return !!(this.compareDocumentPosition(node) & 16);
};
}
if (global['Node']) {
nodeContains = global['Node'].prototype.contains || function(node) {
return !!(this.compareDocumentPosition(node) & 16);
};
}
return undefined as any;
})();
/**
* A `DomAdapter` powered by full browser DOM APIs.

View File

@ -6,13 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as core from '@angular/core';
import {APP_INITIALIZER, ApplicationRef, DebugNode, NgProbeToken, NgZone, Optional, Provider, getDebugNode} from '@angular/core';
import {exportNgVar} from '../util';
const CORE_TOKENS = {
'ApplicationRef': core.ApplicationRef,
'NgZone': core.NgZone,
};
const CORE_TOKENS = (() => ({
'ApplicationRef': ApplicationRef,
'NgZone': NgZone,
}))();
const INSPECT_GLOBAL_NAME = 'probe';
const CORE_TOKENS_GLOBAL_NAME = 'coreTokens';
@ -22,17 +23,17 @@ const CORE_TOKENS_GLOBAL_NAME = 'coreTokens';
* null if the given native element does not have an Angular view associated
* with it.
*/
export function inspectNativeElement(element: any): core.DebugNode|null {
return core.getDebugNode(element);
export function inspectNativeElement(element: any): DebugNode|null {
return getDebugNode(element);
}
export function _createNgProbe(coreTokens: core.NgProbeToken[]): any {
export function _createNgProbe(coreTokens: NgProbeToken[]): any {
exportNgVar(INSPECT_GLOBAL_NAME, inspectNativeElement);
exportNgVar(CORE_TOKENS_GLOBAL_NAME, {...CORE_TOKENS, ..._ngProbeTokensToMap(coreTokens || [])});
return () => inspectNativeElement;
}
function _ngProbeTokensToMap(tokens: core.NgProbeToken[]): {[name: string]: any} {
function _ngProbeTokensToMap(tokens: NgProbeToken[]): {[name: string]: any} {
return tokens.reduce((prev: any, t: any) => (prev[t.name] = t.token, prev), {});
}
@ -48,12 +49,12 @@ export const ELEMENT_PROBE_PROVIDERS__POST_R3__ = [];
/**
* Providers which support debugging Angular applications (e.g. via `ng.probe`).
*/
export const ELEMENT_PROBE_PROVIDERS__PRE_R3__: core.Provider[] = [
export const ELEMENT_PROBE_PROVIDERS__PRE_R3__: Provider[] = [
{
provide: core.APP_INITIALIZER,
provide: APP_INITIALIZER,
useFactory: _createNgProbe,
deps: [
[core.NgProbeToken, new core.Optional()],
[NgProbeToken, new Optional()],
],
multi: true,
},

View File

@ -231,7 +231,7 @@ class DefaultDomRenderer2 implements Renderer2 {
}
}
const AT_CHARCODE = '@'.charCodeAt(0);
const AT_CHARCODE = (() => '@'.charCodeAt(0))();
function checkNoSyntheticProp(name: string, nameKind: string) {
if (name.charCodeAt(0) === AT_CHARCODE) {
throw new Error(

View File

@ -18,9 +18,8 @@ import {EventManagerPlugin} from './event_manager';
* addEventListener by 3x.
*/
const __symbol__ =
(typeof Zone !== 'undefined') && (Zone as any)['__symbol__'] || function(v: string): string {
return '__zone_symbol__' + v;
};
(() => (typeof Zone !== 'undefined') && (Zone as any)['__symbol__'] ||
function(v: string): string { return '__zone_symbol__' + v; })();
const ADD_EVENT_LISTENER: 'addEventListener' = __symbol__('addEventListener');
const REMOVE_EVENT_LISTENER: 'removeEventListener' = __symbol__('removeEventListener');
@ -35,13 +34,18 @@ const NATIVE_REMOVE_LISTENER = 'removeEventListener';
const stopSymbol = '__zone_symbol__propagationStopped';
const stopMethodSymbol = '__zone_symbol__stopImmediatePropagation';
const blackListedEvents: string[] =
(typeof Zone !== 'undefined') && (Zone as any)[__symbol__('BLACK_LISTED_EVENTS')];
let blackListedMap: {[eventName: string]: string};
if (blackListedEvents) {
blackListedMap = {};
blackListedEvents.forEach(eventName => { blackListedMap[eventName] = eventName; });
}
const blackListedMap = (() => {
const blackListedEvents: string[] =
(typeof Zone !== 'undefined') && (Zone as any)[__symbol__('BLACK_LISTED_EVENTS')];
if (blackListedEvents) {
const res: {[eventName: string]: string} = {};
blackListedEvents.forEach(eventName => { res[eventName] = eventName; });
return res;
}
return undefined;
})();
const isBlackListedEvent = function(eventName: string) {
if (!blackListedMap) {