refactor: remove lang.ts (#14837)

This commit is contained in:
Miško Hevery
2017-03-02 09:37:01 -08:00
committed by Chuck Jazdzewski
parent 84a65cf788
commit 8343fb7740
139 changed files with 406 additions and 676 deletions

View File

@ -8,7 +8,6 @@
import {ɵglobal as global} from '@angular/core';
import {setRootDomAdapter} from '../dom/dom_adapter';
import {isBlank, isPresent, setValueOnPath} from '../facade/lang';
import {GenericBrowserDomAdapter} from './generic_browser_adapter';
@ -133,7 +132,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
evt.returnValue = false;
}
isPrevented(evt: Event): boolean {
return evt.defaultPrevented || isPresent(evt.returnValue) && !evt.returnValue;
return evt.defaultPrevented || evt.returnValue != null && !evt.returnValue;
}
getInnerHTML(el: HTMLElement): string { return el.innerHTML; }
getTemplateContent(el: Node): Node {
@ -297,7 +296,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
isCommentNode(node: Node): boolean { return node.nodeType === Node.COMMENT_NODE; }
isElementNode(node: Node): boolean { return node.nodeType === Node.ELEMENT_NODE; }
hasShadowRoot(node: any): boolean {
return isPresent(node.shadowRoot) && node instanceof HTMLElement;
return node.shadowRoot != null && node instanceof HTMLElement;
}
isShadowRoot(node: any): boolean { return node instanceof DocumentFragment; }
importIntoDoc(node: Node): any { return document.importNode(this.templateAwareRoot(node), true); }
@ -306,12 +305,12 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
getEventKey(event: any): string {
let key = event.key;
if (isBlank(key)) {
if (key == null) {
key = event.keyIdentifier;
// keyIdentifier is defined in the old draft of DOM Level 3 Events implemented by Chrome and
// Safari cf
// http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-KeyboardEvents-Interfaces
if (isBlank(key)) {
if (key == null) {
return 'Unidentified';
}
if (key.startsWith('U+')) {
@ -342,7 +341,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
getLocation(): Location { return window.location; }
getBaseHref(doc: Document): string {
const href = getBaseElementHref();
return isBlank(href) ? null : relativePath(href);
return href == null ? null : relativePath(href);
}
resetBaseElement(): void { baseElement = null; }
getUserAgent(): string { return window.navigator.userAgent; }
@ -410,3 +409,20 @@ export function parseCookieValue(cookieStr: string, name: string): string {
}
return null;
}
export function setValueOnPath(global: any, path: string, value: any) {
const parts = path.split('.');
let obj: any = global;
while (parts.length > 1) {
const name = parts.shift();
if (obj.hasOwnProperty(name) && obj[name] != null) {
obj = obj[name];
} else {
obj = obj[name] = {};
}
}
if (obj === undefined || obj === null) {
obj = {};
}
obj[parts.shift()] = value;
}

View File

@ -7,7 +7,6 @@
*/
import {DomAdapter} from '../dom/dom_adapter';
import {isPresent} from '../facade/lang';
@ -24,13 +23,13 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
super();
try {
const element = this.createElement('div', document);
if (isPresent(this.getStyle(element, 'animationName'))) {
if (this.getStyle(element, 'animationName') != null) {
this._animationPrefix = '';
} else {
const domPrefixes = ['Webkit', 'Moz', 'O', 'ms'];
for (let i = 0; i < domPrefixes.length; i++) {
if (isPresent(this.getStyle(element, domPrefixes[i] + 'AnimationName'))) {
if (this.getStyle(element, domPrefixes[i] + 'AnimationName') != null) {
this._animationPrefix = '-' + domPrefixes[i].toLowerCase() + '-';
break;
}
@ -45,7 +44,7 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
};
Object.keys(transEndEventNames).forEach((key: string) => {
if (isPresent(this.getStyle(element, key))) {
if (this.getStyle(element, key) != null) {
this._transitionEnd = transEndEventNames[key];
}
});
@ -66,6 +65,6 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
getAnimationPrefix(): string { return this._animationPrefix ? this._animationPrefix : ''; }
getTransitionEnd(): string { return this._transitionEnd ? this._transitionEnd : ''; }
supportsAnimation(): boolean {
return isPresent(this._animationPrefix) && isPresent(this._transitionEnd);
return this._animationPrefix != null && this._transitionEnd != null;
}
}

View File

@ -9,7 +9,6 @@
import {GetTestability, Testability, TestabilityRegistry, setTestabilityGetter, ɵglobal as global} from '@angular/core';
import {getDOM} from '../dom/dom_adapter';
import {isPresent} from '../facade/lang';
export class BrowserGetTestability implements GetTestability {
static init() { setTestabilityGetter(new BrowserGetTestability()); }
@ -55,7 +54,7 @@ export class BrowserGetTestability implements GetTestability {
return null;
}
const t = registry.getTestability(elem);
if (isPresent(t)) {
if (t != null) {
return t;
} else if (!findInAncestors) {
return null;

View File

@ -0,0 +1,10 @@
/**
* @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
*/
const win = typeof window !== 'undefined' && window || <any>{};
export {win as window};

View File

@ -7,11 +7,8 @@
*/
import {ApplicationRef, ComponentRef} from '@angular/core';
import {getDOM} from '../../dom/dom_adapter';
import {isPresent} from '../../facade/lang';
const win = typeof window !== 'undefined' && window || <any>{};
import {window} from './browser';
export class ChangeDetectionPerfRecord {
constructor(public msPerTick: number, public numTicks: number) {}
@ -47,9 +44,9 @@ export class AngularProfiler {
const record = config && config['record'];
const profileName = 'Change Detection';
// Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
const isProfilerAvailable = isPresent(win.console.profile);
const isProfilerAvailable = window.console.profile != null;
if (record && isProfilerAvailable) {
win.console.profile(profileName);
window.console.profile(profileName);
}
const start = getDOM().performanceNow();
let numTicks = 0;
@ -63,11 +60,11 @@ export class AngularProfiler {
// while in fact there is:
//
// https://developer.mozilla.org/en-US/docs/Web/API/Console/profileEnd
(<any>win.console.profileEnd)(profileName);
(<any>window.console.profileEnd)(profileName);
}
const msPerTick = (end - start) / numTicks;
win.console.log(`ran ${numTicks} change detection cycles`);
win.console.log(`${msPerTick.toFixed(2)} ms per check`);
window.console.log(`ran ${numTicks} change detection cycles`);
window.console.log(`${msPerTick.toFixed(2)} ms per check`);
return new ChangeDetectionPerfRecord(msPerTick, numTicks);
}

View File

@ -8,7 +8,6 @@
import {DebugElement, Predicate, Type} from '@angular/core';
import {getDOM} from '../../dom/dom_adapter';
import {isPresent} from '../../facade/lang';
@ -36,7 +35,7 @@ export class By {
*/
static css(selector: string): Predicate<DebugElement> {
return (debugElement) => {
return isPresent(debugElement.nativeElement) ?
return debugElement.nativeElement != null ?
getDOM().elementMatches(debugElement.nativeElement, selector) :
false;
};

View File

@ -7,10 +7,6 @@
*/
import {APP_ID, Inject, Injectable, RenderComponentType, Renderer, RendererFactoryV2, RendererTypeV2, RendererV2, RootRenderer, ViewEncapsulation} from '@angular/core';
import {isPresent, stringify} from '../facade/lang';
import {DOCUMENT} from './dom_tokens';
import {EventManager} from './events/event_manager';
import {DomSharedStylesHost} from './shared_styles_host';

View File

@ -1 +0,0 @@
../../facade/src

View File

@ -8,6 +8,7 @@
export {BROWSER_SANITIZATION_PROVIDERS as ɵBROWSER_SANITIZATION_PROVIDERS, INTERNAL_BROWSER_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS, initDomAdapter as ɵinitDomAdapter} from './browser';
export {BrowserDomAdapter as ɵBrowserDomAdapter} from './browser/browser_adapter';
export {setValueOnPath as ɵsetValueOnPath} from './browser/browser_adapter';
export {BrowserPlatformLocation as ɵBrowserPlatformLocation} from './browser/location/browser_platform_location';
export {TRANSITION_ID as ɵTRANSITION_ID} from './browser/server-transition';
export {BrowserGetTestability as ɵBrowserGetTestability} from './browser/testability';