refactor(): use const and let instead of var

This commit is contained in:
Joao Dias
2016-11-12 14:08:58 +01:00
committed by Victor Berchet
parent 73593d4bf3
commit 77ee27c59e
435 changed files with 4637 additions and 4663 deletions

View File

@ -15,7 +15,7 @@ export class AnimationViewContext {
private _players = new ViewAnimationMap();
onAllActiveAnimationsDone(callback: () => any): void {
var activeAnimationPlayers = this._players.getAllPlayers();
const activeAnimationPlayers = this._players.getAllPlayers();
// we check for the length to avoid having GroupAnimationPlayer
// issue an unnecessary microtask when zero players are passed in
if (activeAnimationPlayers.length) {
@ -35,7 +35,7 @@ export class AnimationViewContext {
if (removeAllAnimations) {
this._players.findAllPlayersByElement(element).forEach(player => player.destroy());
} else {
var player = this._players.find(element, animationName);
const player = this._players.find(element, animationName);
if (player) {
player.destroy();
}

View File

@ -107,11 +107,11 @@ export class ComponentFactory<C> {
create(
injector: Injector, projectableNodes: any[][] = null,
rootSelectorOrNode: string|any = null): ComponentRef<C> {
var vu: ViewUtils = injector.get(ViewUtils);
const vu: ViewUtils = injector.get(ViewUtils);
if (!projectableNodes) {
projectableNodes = [];
}
var hostView: AppView<any> = new this._viewClass(vu, null, null, null);
const hostView: AppView<any> = new this._viewClass(vu, null, null, null);
return hostView.createHostView(rootSelectorOrNode, injector, projectableNodes);
}
}

View File

@ -42,7 +42,7 @@ export class CodegenComponentFactoryResolver implements ComponentFactoryResolver
constructor(factories: ComponentFactory<any>[], private _parent: ComponentFactoryResolver) {
for (let i = 0; i < factories.length; i++) {
let factory = factories[i];
const factory = factories[i];
this._factories.set(factory.componentType, factory);
}
}

View File

@ -31,14 +31,14 @@ export class DebugContext implements RenderDebugInfo {
get context() { return this._view.context; }
get component() {
var staticNodeInfo = this._staticNodeInfo;
const staticNodeInfo = this._staticNodeInfo;
if (isPresent(staticNodeInfo) && isPresent(staticNodeInfo.componentToken)) {
return this.injector.get(staticNodeInfo.componentToken);
}
return null;
}
get componentRenderElement() {
var componentView = this._view;
let componentView = this._view;
while (isPresent(componentView.parentView) && componentView.type !== ViewType.COMPONENT) {
componentView = <DebugAppView<any>>componentView.parentView;
}
@ -53,17 +53,17 @@ export class DebugContext implements RenderDebugInfo {
}
}
get providerTokens(): any[] {
var staticNodeInfo = this._staticNodeInfo;
const staticNodeInfo = this._staticNodeInfo;
return isPresent(staticNodeInfo) ? staticNodeInfo.providerTokens : null;
}
get source(): string {
return `${this._view.componentType.templateUrl}:${this._tplRow}:${this._tplCol}`;
}
get references(): {[key: string]: any} {
var varValues: {[key: string]: string} = {};
var staticNodeInfo = this._staticNodeInfo;
const varValues: {[key: string]: string} = {};
const staticNodeInfo = this._staticNodeInfo;
if (isPresent(staticNodeInfo)) {
var refs = staticNodeInfo.refTokens;
const refs = staticNodeInfo.refTokens;
Object.keys(refs).forEach(refName => {
const refToken = refs[refName];
let varValue: any;

View File

@ -65,7 +65,7 @@ export class NgModuleFactory<T> {
if (!parentInjector) {
parentInjector = Injector.NULL;
}
var instance = new this._injectorClass(parentInjector);
const instance = new this._injectorClass(parentInjector);
instance.create();
return instance;
}
@ -95,7 +95,7 @@ export abstract class NgModuleInjector<T> extends CodegenComponentFactoryResolve
if (token === Injector || token === ComponentFactoryResolver) {
return this;
}
var result = this.getInternal(token, _UNDEFINED);
const result = this.getInternal(token, _UNDEFINED);
return result === _UNDEFINED ? this.parent.get(token, notFoundValue) : result;
}

View File

@ -23,7 +23,7 @@ let moduleFactories = new Map<string, NgModuleFactory<any>>();
* @experimental
*/
export function registerModuleFactory(id: string, factory: NgModuleFactory<any>) {
let existing = moduleFactories.get(id);
const existing = moduleFactories.get(id);
if (existing) {
throw new Error(`Duplicate module registered for ${id
} - ${existing.moduleType.name} vs ${factory.moduleType.name}`);
@ -42,7 +42,7 @@ export function clearModulesForTest() {
* @experimental
*/
export function getModuleFactory(id: string): NgModuleFactory<any> {
let factory = moduleFactories.get(id);
const factory = moduleFactories.get(id);
if (!factory) throw new Error(`No module with ID ${id} loaded`);
return factory;
}

View File

@ -59,7 +59,9 @@ export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
private loadAndCompile(path: string): Promise<NgModuleFactory<any>> {
let [module, exportName] = path.split(_SEPARATOR);
if (exportName === undefined) exportName = 'default';
if (exportName === undefined) {
exportName = 'default';
}
return System.import(module)
.then((module: any) => module[exportName])

View File

@ -23,7 +23,7 @@ import {ViewRef_} from './view_ref';
import {ViewType} from './view_type';
import {ViewUtils, addToArray} from './view_utils';
var _scope_check: WtfScopeFn = wtfCreateScope(`AppView#check(ascii id)`);
const _scope_check: WtfScopeFn = wtfCreateScope(`AppView#check(ascii id)`);
/**
* @experimental
@ -150,9 +150,9 @@ export abstract class AppView<T> {
if (this.cdMode === ChangeDetectorStatus.Destroyed) {
return;
}
var hostElement = this.type === ViewType.COMPONENT ? this.parentElement : null;
const hostElement = this.type === ViewType.COMPONENT ? this.parentElement : null;
if (this.disposables) {
for (var i = 0; i < this.disposables.length; i++) {
for (let i = 0; i < this.disposables.length; i++) {
this.disposables[i]();
}
}
@ -266,7 +266,7 @@ export abstract class AppView<T> {
case ViewType.COMPONENT:
if (this.parentView.type === ViewType.HOST) {
const nodes = this.parentView._hostProjectableNodes[ngContentIndex] || [];
for (var i = 0; i < nodes.length; i++) {
for (let i = 0; i < nodes.length; i++) {
cb(nodes[i], c);
}
} else {
@ -293,7 +293,7 @@ export abstract class AppView<T> {
dirtyParentQueriesInternal(): void {}
detectChanges(throwOnChange: boolean): void {
var s = _scope_check(this.clazz);
const s = _scope_check(this.clazz);
if (this.cdMode === ChangeDetectorStatus.Checked ||
this.cdMode === ChangeDetectorStatus.Errored ||
this.cdMode === ChangeDetectorStatus.Detached)
@ -429,7 +429,7 @@ export class DebugAppView<T> extends AppView<T> {
}
eventHandler<E, R>(cb: (eventName: string, event?: E) => R): (eventName: string, event?: E) => R {
var superHandler = super.eventHandler(cb);
const superHandler = super.eventHandler(cb);
return (eventName: string, event?: any) => {
this._resetDebug();
try {

View File

@ -39,7 +39,7 @@ export class ViewContainer {
detectChangesInNestedViews(throwOnChange: boolean): void {
if (this.nestedViews) {
for (var i = 0; i < this.nestedViews.length; i++) {
for (let i = 0; i < this.nestedViews.length; i++) {
this.nestedViews[i].detectChanges(throwOnChange);
}
}
@ -47,7 +47,7 @@ export class ViewContainer {
destroyNestedViews(): void {
if (this.nestedViews) {
for (var i = 0; i < this.nestedViews.length; i++) {
for (let i = 0; i < this.nestedViews.length; i++) {
this.nestedViews[i].destroy();
}
}
@ -55,16 +55,16 @@ export class ViewContainer {
visitNestedViewRootNodes<C>(cb: (node: any, ctx: C) => void, c: C): void {
if (this.nestedViews) {
for (var i = 0; i < this.nestedViews.length; i++) {
for (let i = 0; i < this.nestedViews.length; i++) {
this.nestedViews[i].visitRootNodesInternal(cb, c);
}
}
}
mapNestedViews(nestedViewClass: any, callback: Function): any[] {
var result: any[] = [];
const result: any[] = [];
if (this.nestedViews) {
for (var i = 0; i < this.nestedViews.length; i++) {
for (let i = 0; i < this.nestedViews.length; i++) {
const nestedView = this.nestedViews[i];
if (nestedView.clazz === nestedViewClass) {
result.push(callback(nestedView));
@ -72,7 +72,7 @@ export class ViewContainer {
}
}
if (this.projectedViews) {
for (var i = 0; i < this.projectedViews.length; i++) {
for (let i = 0; i < this.projectedViews.length; i++) {
const projectedView = this.projectedViews[i];
if (projectedView.clazz === nestedViewClass) {
result.push(callback(projectedView));
@ -83,11 +83,11 @@ export class ViewContainer {
}
moveView(view: AppView<any>, currentIndex: number) {
var previousIndex = this.nestedViews.indexOf(view);
const previousIndex = this.nestedViews.indexOf(view);
if (view.type === ViewType.COMPONENT) {
throw new Error(`Component views can't be moved!`);
}
var nestedViews = this.nestedViews;
let nestedViews = this.nestedViews;
if (nestedViews == null) {
nestedViews = [];
this.nestedViews = nestedViews;
@ -102,7 +102,7 @@ export class ViewContainer {
if (view.type === ViewType.COMPONENT) {
throw new Error(`Component views can't be moved!`);
}
var nestedViews = this.nestedViews;
let nestedViews = this.nestedViews;
if (nestedViews == null) {
nestedViews = [];
this.nestedViews = nestedViews;

View File

@ -133,7 +133,7 @@ export class ViewContainerRef_ implements ViewContainerRef {
get(index: number): ViewRef { return this._element.nestedViews[index].ref; }
get length(): number {
var views = this._element.nestedViews;
const views = this._element.nestedViews;
return isPresent(views) ? views.length : 0;
}
@ -147,7 +147,7 @@ export class ViewContainerRef_ implements ViewContainerRef {
// to the methods below.
createEmbeddedView<C>(templateRef: TemplateRef<C>, context: C = null, index: number = -1):
EmbeddedViewRef<C> {
var viewRef: EmbeddedViewRef<any> = templateRef.createEmbeddedView(context);
const viewRef: EmbeddedViewRef<any> = templateRef.createEmbeddedView(context);
this.insert(viewRef, index);
return viewRef;
}
@ -159,9 +159,9 @@ export class ViewContainerRef_ implements ViewContainerRef {
createComponent<C>(
componentFactory: ComponentFactory<C>, index: number = -1, injector: Injector = null,
projectableNodes: any[][] = null): ComponentRef<C> {
var s = this._createComponentInContainerScope();
var contextInjector = injector || this._element.parentInjector;
var componentRef = componentFactory.create(contextInjector, projectableNodes);
const s = this._createComponentInContainerScope();
const contextInjector = injector || this._element.parentInjector;
const componentRef = componentFactory.create(contextInjector, projectableNodes);
this.insert(componentRef.hostView, index);
return wtfLeave(s, componentRef);
}
@ -171,17 +171,17 @@ export class ViewContainerRef_ implements ViewContainerRef {
// TODO(i): refactor insert+remove into move
insert(viewRef: ViewRef, index: number = -1): ViewRef {
var s = this._insertScope();
const s = this._insertScope();
if (index == -1) index = this.length;
var viewRef_ = <ViewRef_<any>>viewRef;
const viewRef_ = <ViewRef_<any>>viewRef;
this._element.attachView(viewRef_.internalView, index);
return wtfLeave(s, viewRef_);
}
move(viewRef: ViewRef, currentIndex: number): ViewRef {
var s = this._insertScope();
const s = this._insertScope();
if (currentIndex == -1) return;
var viewRef_ = <ViewRef_<any>>viewRef;
const viewRef_ = <ViewRef_<any>>viewRef;
this._element.moveView(viewRef_.internalView, currentIndex);
return wtfLeave(s, viewRef_);
}

View File

@ -346,7 +346,7 @@ export function createRenderElement(
renderer: Renderer, parentElement: any, name: string, attrs: InlineArray<string>,
debugInfo?: RenderDebugInfo): any {
const el = renderer.createElement(parentElement, name, debugInfo);
for (var i = 0; i < attrs.length; i += 2) {
for (let i = 0; i < attrs.length; i += 2) {
renderer.setElementAttribute(el, attrs.get(i), attrs.get(i + 1));
}
return el;
@ -355,10 +355,10 @@ export function createRenderElement(
export function selectOrCreateRenderHostElement(
renderer: Renderer, elementName: string, attrs: InlineArray<string>,
rootSelectorOrNode: string | any, debugInfo?: RenderDebugInfo): any {
var hostElement: any;
let hostElement: any;
if (isPresent(rootSelectorOrNode)) {
hostElement = renderer.selectRootElement(rootSelectorOrNode, debugInfo);
for (var i = 0; i < attrs.length; i += 2) {
for (let i = 0; i < attrs.length; i += 2) {
renderer.setElementAttribute(hostElement, attrs.get(i), attrs.get(i + 1));
}
} else {
@ -371,7 +371,7 @@ export function subscribeToRenderElement(
view: AppView<any>, element: any, eventNamesAndTargets: InlineArray<string>,
listener: (eventName: string, event: any) => any) {
const disposables = createEmptyInlineArray(eventNamesAndTargets.length / 2);
for (var i = 0; i < eventNamesAndTargets.length; i += 2) {
for (let i = 0; i < eventNamesAndTargets.length; i += 2) {
const eventName = eventNamesAndTargets.get(i);
const eventTarget = eventNamesAndTargets.get(i + 1);
let disposable: Function;
@ -387,7 +387,7 @@ export function subscribeToRenderElement(
}
function disposeInlineArray(disposables: InlineArray<Function>) {
for (var i = 0; i < disposables.length; i++) {
for (let i = 0; i < disposables.length; i++) {
disposables.get(i)();
}
}