refactor: remove lang.ts (#14837)
This commit is contained in:

committed by
Chuck Jazdzewski

parent
84a65cf788
commit
8343fb7740
@ -12,12 +12,9 @@ import {Subject} from 'rxjs/Subject';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {merge} from 'rxjs/observable/merge';
|
||||
import {share} from 'rxjs/operator/share';
|
||||
|
||||
import {ErrorHandler} from '../src/error_handler';
|
||||
import {stringify} from '../src/facade/lang';
|
||||
import {scheduleMicroTask} from '../src/util';
|
||||
import {scheduleMicroTask, stringify} from '../src/util';
|
||||
import {isPromise} from '../src/util/lang';
|
||||
|
||||
import {ApplicationInitStatus} from './application_init';
|
||||
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
|
||||
import {Console} from './console';
|
||||
|
@ -12,7 +12,7 @@ import {IterableDifferFactory, IterableDiffers} from './differs/iterable_differs
|
||||
import {KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs';
|
||||
|
||||
export {SimpleChanges} from '../metadata/lifecycle_hooks';
|
||||
export {SimpleChange, ValueUnwrapper, WrappedValue, devModeEqual, looseIdentical} from './change_detection_util';
|
||||
export {SimpleChange, ValueUnwrapper, WrappedValue, devModeEqual} from './change_detection_util';
|
||||
export {ChangeDetectorRef} from './change_detector_ref';
|
||||
export {ChangeDetectionStrategy, ChangeDetectorStatus, isDefaultChangeDetectionStrategy} from './constants';
|
||||
export {DefaultIterableDifferFactory} from './differs/default_iterable_differ';
|
||||
|
@ -6,21 +6,21 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {isJsObject, isPrimitive, looseIdentical} from '../facade/lang';
|
||||
import {getSymbolIterator} from '../util';
|
||||
|
||||
export {looseIdentical} from '../facade/lang';
|
||||
import {getSymbolIterator, looseIdentical} from '../util';
|
||||
|
||||
export function devModeEqual(a: any, b: any): boolean {
|
||||
if (isListLikeIterable(a) && isListLikeIterable(b)) {
|
||||
const isListLikeIterableA = isListLikeIterable(a);
|
||||
const isListLikeIterableB = isListLikeIterable(b);
|
||||
if (isListLikeIterableA && isListLikeIterableB) {
|
||||
return areIterablesEqual(a, b, devModeEqual);
|
||||
|
||||
} else if (
|
||||
!isListLikeIterable(a) && !isPrimitive(a) && !isListLikeIterable(b) && !isPrimitive(b)) {
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return looseIdentical(a, b);
|
||||
const isAObject = a && (typeof a === 'object' || typeof a === 'function');
|
||||
const isBObject = b && (typeof b === 'object' || typeof b === 'function');
|
||||
if (!isListLikeIterableA && isAObject && !isListLikeIterableB && isBObject) {
|
||||
return true;
|
||||
} else {
|
||||
return looseIdentical(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,3 +113,7 @@ export function iterateListLike(obj: any, fn: (p: any) => any) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isJsObject(o: any): boolean {
|
||||
return o !== null && (typeof o === 'function' || typeof o === 'object');
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {isBlank} from '../facade/lang';
|
||||
|
||||
/**
|
||||
* Describes within the change detector which strategy will be used the next time change
|
||||
@ -68,6 +67,6 @@ export enum ChangeDetectorStatus {
|
||||
|
||||
export function isDefaultChangeDetectionStrategy(changeDetectionStrategy: ChangeDetectionStrategy):
|
||||
boolean {
|
||||
return isBlank(changeDetectionStrategy) ||
|
||||
return changeDetectionStrategy == null ||
|
||||
changeDetectionStrategy === ChangeDetectionStrategy.Default;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {isBlank, looseIdentical, stringify} from '../../facade/lang';
|
||||
import {looseIdentical, stringify} from '../../util';
|
||||
import {isListLikeIterable, iterateListLike} from '../change_detection_util';
|
||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||
|
||||
@ -155,7 +155,7 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
||||
}
|
||||
|
||||
diff(collection: NgIterable<V>): DefaultIterableDiffer<V> {
|
||||
if (isBlank(collection)) collection = [];
|
||||
if (collection == null) collection = [];
|
||||
if (!isListLikeIterable(collection)) {
|
||||
throw new Error(`Error trying to diff '${collection}'`);
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {isJsObject, looseIdentical, stringify} from '../../facade/lang';
|
||||
import {looseIdentical, stringify} from '../../util';
|
||||
import {isJsObject} from '../change_detection_util';
|
||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||
|
||||
import {KeyValueChangeRecord, KeyValueChanges, KeyValueDiffer, KeyValueDifferFactory} from './keyvalue_differs';
|
||||
|
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {Optional, Provider, SkipSelf} from '../../di';
|
||||
import {getTypeNameForDebugging, isPresent} from '../../facade/lang';
|
||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||
|
||||
/**
|
||||
@ -158,7 +157,7 @@ export class IterableDiffers {
|
||||
constructor(factories: IterableDifferFactory[]) { this.factories = factories; }
|
||||
|
||||
static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers {
|
||||
if (isPresent(parent)) {
|
||||
if (parent != null) {
|
||||
const copied = parent.factories.slice();
|
||||
factories = factories.concat(copied);
|
||||
return new IterableDiffers(factories);
|
||||
@ -205,7 +204,7 @@ export class IterableDiffers {
|
||||
|
||||
find(iterable: any): IterableDifferFactory {
|
||||
const factory = this.factories.find(f => f.supports(iterable));
|
||||
if (isPresent(factory)) {
|
||||
if (factory != null) {
|
||||
return factory;
|
||||
} else {
|
||||
throw new Error(
|
||||
@ -213,3 +212,7 @@ export class IterableDiffers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getTypeNameForDebugging(type: any): string {
|
||||
return type['name'] || typeof type;
|
||||
}
|
||||
|
@ -7,11 +7,16 @@
|
||||
*/
|
||||
|
||||
import {Injectable} from './di';
|
||||
import {print, warn} from './facade/lang';
|
||||
|
||||
@Injectable()
|
||||
export class Console {
|
||||
log(message: string): void { print(message); }
|
||||
log(message: string): void {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(message);
|
||||
}
|
||||
// Note: for reporting errors use `DOM.logError()` as it is platform specific
|
||||
warn(message: string): void { warn(message); }
|
||||
warn(message: string): void {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.warn(message);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +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 {global as ɵglobal, looseIdentical as ɵlooseIdentical, stringify as ɵstringify} from './util';
|
||||
export {makeDecorator as ɵmakeDecorator} from './util/decorators';
|
||||
export {isObservable as ɵisObservable, isPromise as ɵisPromise, merge as ɵmerge} from './util/lang';
|
||||
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {stringify} from '../util';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -6,8 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {stringify} from '../util';
|
||||
|
||||
import {InjectionToken} from './injection_token';
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
import {wrappedError} from '../error_handler';
|
||||
import {ERROR_ORIGINAL_ERROR, getOriginalError} from '../errors';
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {stringify} from '../util';
|
||||
|
||||
import {ReflectiveInjector} from './reflective_injector';
|
||||
import {ReflectiveKey} from './reflective_key';
|
||||
|
@ -6,8 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {stringify} from '../facade/lang';
|
||||
|
||||
import {stringify} from '../util';
|
||||
import {resolveForwardRef} from './forward_ref';
|
||||
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
../../facade/src
|
@ -6,8 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {stringify} from '../util';
|
||||
|
||||
import {ComponentFactory} from './component_factory';
|
||||
|
||||
|
@ -7,8 +7,9 @@
|
||||
*/
|
||||
|
||||
import {Injector, THROW_IF_NOT_FOUND} from '../di/injector';
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {stringify} from '../util';
|
||||
|
||||
import {ComponentFactory} from './component_factory';
|
||||
import {CodegenComponentFactoryResolver, ComponentFactoryResolver} from './component_factory_resolver';
|
||||
|
||||
|
@ -6,9 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {isPresent, stringify} from '../facade/lang';
|
||||
import {Type, isType} from '../type';
|
||||
import {global} from '../util';
|
||||
import {global, stringify} from '../util';
|
||||
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
|
||||
import {GetterFn, MethodFn, SetterFn} from './types';
|
||||
|
||||
@ -48,7 +47,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
} else {
|
||||
result[i] = [];
|
||||
}
|
||||
if (paramAnnotations && isPresent(paramAnnotations[i])) {
|
||||
if (paramAnnotations && paramAnnotations[i] != null) {
|
||||
result[i] = result[i].concat(paramAnnotations[i]);
|
||||
}
|
||||
}
|
||||
@ -87,7 +86,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
}
|
||||
|
||||
// API for metadata created by invoking the decorators.
|
||||
if (isPresent(this._reflect) && isPresent(this._reflect.getOwnMetadata)) {
|
||||
if (this._reflect != null && this._reflect.getOwnMetadata != null) {
|
||||
const paramAnnotations = this._reflect.getOwnMetadata('parameters', type);
|
||||
const paramTypes = this._reflect.getOwnMetadata('design:paramtypes', type);
|
||||
if (paramTypes || paramAnnotations) {
|
||||
|
@ -24,7 +24,7 @@ declare const Symbol: any;
|
||||
let _symbolIterator: any = null;
|
||||
export function getSymbolIterator(): string|symbol {
|
||||
if (!_symbolIterator) {
|
||||
var Symbol = _global['Symbol'];
|
||||
const Symbol = _global['Symbol'];
|
||||
if (Symbol && Symbol.iterator) {
|
||||
_symbolIterator = Symbol.iterator;
|
||||
} else {
|
||||
@ -45,3 +45,30 @@ export function getSymbolIterator(): string|symbol {
|
||||
export function scheduleMicroTask(fn: Function) {
|
||||
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (token == null) {
|
||||
return '' + token;
|
||||
}
|
||||
|
||||
if (token.overriddenName) {
|
||||
return `${token.overriddenName}`;
|
||||
}
|
||||
|
||||
if (token.name) {
|
||||
return `${token.name}`;
|
||||
}
|
||||
|
||||
const res = token.toString();
|
||||
const newLineIndex = res.indexOf('\n');
|
||||
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
|
||||
}
|
||||
|
@ -6,9 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {global} from '../util';
|
||||
import {global, stringify} from '../util';
|
||||
|
||||
let _nextClassId = 0;
|
||||
const Reflect = global['Reflect'];
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {isDevMode} from '../application_ref';
|
||||
import {looseIdentical} from '../facade/lang';
|
||||
import {looseIdentical} from '../util';
|
||||
|
||||
import {BindingDef, BindingType, DebugContext, NodeData, NodeDef, NodeFlags, RootData, Services, TextData, ViewData, ViewFlags, asElementData, asTextData} from './types';
|
||||
import {checkAndUpdateBinding, getParentRenderElement, sliceErrorStack} from './util';
|
||||
|
@ -10,12 +10,12 @@ import {isDevMode} from '../application_ref';
|
||||
import {WrappedValue, devModeEqual} from '../change_detection/change_detection';
|
||||
import {SimpleChange} from '../change_detection/change_detection_util';
|
||||
import {Injector} from '../di';
|
||||
import {looseIdentical, stringify} from '../facade/lang';
|
||||
import {TemplateRef} from '../linker/template_ref';
|
||||
import {ViewContainerRef} from '../linker/view_container_ref';
|
||||
import {ViewRef} from '../linker/view_ref';
|
||||
import {ViewEncapsulation} from '../metadata/view';
|
||||
import {Renderer, RendererTypeV2} from '../render/api';
|
||||
import {looseIdentical, stringify} from '../util';
|
||||
|
||||
import {expressionChangedAfterItHasBeenCheckedError, isViewDebugError, viewDestroyedError, viewWrappedDebugError} from './errors';
|
||||
import {DebugContext, ElementData, NodeData, NodeDef, NodeFlags, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewState, asElementData, asProviderData, asTextData} from './types';
|
||||
@ -389,4 +389,4 @@ function _toStringWithNull(v: any): string {
|
||||
}
|
||||
|
||||
export const EMPTY_ARRAY: any[] = [];
|
||||
export const EMPTY_MAP: {[key: string]: any} = {};
|
||||
export const EMPTY_MAP: {[key: string]: any} = {};
|
||||
|
@ -11,8 +11,7 @@ import {ReflectiveInjector_} from '@angular/core/src/di/reflective_injector';
|
||||
import {ResolvedReflectiveProvider_} from '@angular/core/src/di/reflective_provider';
|
||||
import {getOriginalError} from '@angular/core/src/errors';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {isPresent, stringify} from '../../src/facade/lang';
|
||||
import {stringify} from '../../src/util';
|
||||
|
||||
class Engine {}
|
||||
|
||||
@ -82,7 +81,7 @@ export function main() {
|
||||
function createInjector(
|
||||
providers: Provider[], parent: ReflectiveInjector = null): ReflectiveInjector_ {
|
||||
const resolvedProviders = ReflectiveInjector.resolve(providers.concat(dynamicProviders));
|
||||
if (isPresent(parent)) {
|
||||
if (parent != null) {
|
||||
return <ReflectiveInjector_>parent.createChildFromResolved(resolvedProviders);
|
||||
} else {
|
||||
return <ReflectiveInjector_>ReflectiveInjector.fromResolvedProviders(resolvedProviders);
|
||||
|
@ -1,63 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
export function main() {
|
||||
describe('Observable', () => {
|
||||
describe('#core', () => {
|
||||
|
||||
it('should call next with values',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
|
||||
const o = new Observable((sink: any /** TODO #9100 */) => { sink.next(1); });
|
||||
|
||||
o.subscribe(v => {
|
||||
expect(v).toEqual(1);
|
||||
async.done();
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should call next and then complete',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
|
||||
const o = new Observable((sink: any /** TODO #9100 */) => {
|
||||
sink.next(1);
|
||||
sink.complete();
|
||||
});
|
||||
let nexted = false;
|
||||
|
||||
o.subscribe(
|
||||
v => { nexted = true; }, null,
|
||||
() => {
|
||||
expect(nexted).toBe(true);
|
||||
async.done();
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should call error with errors',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
|
||||
const o = new Observable((sink: any /** TODO #9100 */) => { sink.error('oh noes!'); });
|
||||
|
||||
o.subscribe(
|
||||
v => {
|
||||
|
||||
},
|
||||
(err) => {
|
||||
expect(err).toEqual('oh noes!');
|
||||
async.done();
|
||||
});
|
||||
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
@ -22,8 +22,7 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
|
||||
import {dispatchEvent, el} from '@angular/platform-browser/testing/browser_util';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {stringify} from '../../src/facade/lang';
|
||||
import {stringify} from '../../src/util';
|
||||
|
||||
const ANCHOR_ELEMENT = new InjectionToken('AnchorElement');
|
||||
|
||||
|
@ -11,9 +11,9 @@ import {Console} from '@angular/core/src/console';
|
||||
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {stringify} from '../../src/facade/lang';
|
||||
import {NgModuleInjector} from '../../src/linker/ng_module_factory';
|
||||
import {clearModulesForTest} from '../../src/linker/ng_module_factory_loader';
|
||||
import {stringify} from '../../src/util';
|
||||
|
||||
class Engine {}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit,
|
||||
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {stringify} from '../../src/facade/lang';
|
||||
import {stringify} from '../../src/util';
|
||||
|
||||
export function main() {
|
||||
describe('Query API', () => {
|
||||
|
@ -10,7 +10,6 @@ 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} from '../../src/facade/lang';
|
||||
import {scheduleMicroTask} from '../../src/util';
|
||||
|
||||
const needsLongerTimers = browserDetection.isSlow || browserDetection.isEdge;
|
||||
@ -159,7 +158,7 @@ export function main() {
|
||||
|
||||
promise.then((_) => {
|
||||
expect(_traces.length).toBe(1);
|
||||
if (isPresent(_traces[0])) {
|
||||
if (_traces[0] != null) {
|
||||
// some browsers don't have stack traces.
|
||||
expect(_traces[0].indexOf('---')).toEqual(-1);
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
../../facade/src
|
@ -6,10 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {CompilerOptions, Component, Directive, InjectionToken, Injector, ModuleWithComponentFactories, NgModule, NgModuleRef, NgZone, Pipe, PlatformRef, Provider, ReflectiveInjector, SchemaMetadata, Type, ɵERROR_COMPONENT_TYPE} from '@angular/core';
|
||||
import {CompilerOptions, Component, Directive, InjectionToken, Injector, ModuleWithComponentFactories, NgModule, NgModuleRef, NgZone, Pipe, PlatformRef, Provider, ReflectiveInjector, SchemaMetadata, Type, ɵERROR_COMPONENT_TYPE, ɵstringify as stringify} from '@angular/core';
|
||||
import {AsyncTestCompleter} from './async_test_completer';
|
||||
import {ComponentFixture} from './component_fixture';
|
||||
import {stringify} from './facade/lang';
|
||||
import {MetadataOverride} from './metadata_override';
|
||||
import {TestingCompiler, TestingCompilerFactory} from './test_compiler';
|
||||
|
||||
|
Reference in New Issue
Block a user