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

@ -150,13 +150,13 @@ export class NgFor implements DoCheck, OnChanges {
}
for (let i = 0, ilen = this._viewContainer.length; i < ilen; i++) {
let viewRef = <EmbeddedViewRef<NgForRow>>this._viewContainer.get(i);
const viewRef = <EmbeddedViewRef<NgForRow>>this._viewContainer.get(i);
viewRef.context.index = i;
viewRef.context.count = ilen;
}
changes.forEachIdentityChange((record: any) => {
let viewRef = <EmbeddedViewRef<NgForRow>>this._viewContainer.get(record.currentIndex);
const viewRef = <EmbeddedViewRef<NgForRow>>this._viewContainer.get(record.currentIndex);
viewRef.context.$implicit = record.item;
});
}

View File

@ -118,7 +118,7 @@ export class NgSwitch {
private _updateDefaultCases(useDefault: boolean) {
if (this._defaultViews && useDefault !== this._defaultUsed) {
this._defaultUsed = useDefault;
for (var i = 0; i < this._defaultViews.length; i++) {
for (let i = 0; i < this._defaultViews.length; i++) {
const defaultView = this._defaultViews[i];
defaultView.enforceState(useDefault);
}

View File

@ -64,19 +64,19 @@ export class HashLocationStrategy extends LocationStrategy {
path(includeHash: boolean = false): string {
// the hash value is always prefixed with a `#`
// and if it is empty then it will stay empty
var path = this._platformLocation.hash;
let path = this._platformLocation.hash;
if (!isPresent(path)) path = '#';
return path.length > 0 ? path.substring(1) : path;
}
prepareExternalUrl(internal: string): string {
var url = Location.joinWithSlash(this._baseHref, internal);
const url = Location.joinWithSlash(this._baseHref, internal);
return url.length > 0 ? ('#' + url) : url;
}
pushState(state: any, title: string, path: string, queryParams: string) {
var url = this.prepareExternalUrl(path + Location.normalizeQueryParams(queryParams));
let url = this.prepareExternalUrl(path + Location.normalizeQueryParams(queryParams));
if (url.length == 0) {
url = this._platformLocation.pathname;
}
@ -84,7 +84,7 @@ export class HashLocationStrategy extends LocationStrategy {
}
replaceState(state: any, title: string, path: string, queryParams: string) {
var url = this.prepareExternalUrl(path + Location.normalizeQueryParams(queryParams));
let url = this.prepareExternalUrl(path + Location.normalizeQueryParams(queryParams));
if (url.length == 0) {
url = this._platformLocation.pathname;
}

View File

@ -156,7 +156,7 @@ export class Location {
if (end.length == 0) {
return start;
}
var slashes = 0;
let slashes = 0;
if (start.endsWith('/')) {
slashes++;
}

View File

@ -79,12 +79,12 @@ export class PathLocationStrategy extends LocationStrategy {
}
pushState(state: any, title: string, url: string, queryParams: string) {
var externalUrl = this.prepareExternalUrl(url + Location.normalizeQueryParams(queryParams));
const externalUrl = this.prepareExternalUrl(url + Location.normalizeQueryParams(queryParams));
this._platformLocation.pushState(state, title, externalUrl);
}
replaceState(state: any, title: string, url: string, queryParams: string) {
var externalUrl = this.prepareExternalUrl(url + Location.normalizeQueryParams(queryParams));
const externalUrl = this.prepareExternalUrl(url + Location.normalizeQueryParams(queryParams));
this._platformLocation.replaceState(state, title, externalUrl);
}

View File

@ -37,7 +37,7 @@ function formatNumber(
}
if (digits) {
let parts = digits.match(_NUMBER_FORMAT_REGEXP);
const parts = digits.match(_NUMBER_FORMAT_REGEXP);
if (parts === null) {
throw new Error(`${digits} is not a valid digit info for number pipes`);
}

View File

@ -65,7 +65,7 @@ export function main() {
it('should add and remove classes based on changes to the expression object', async(() => {
fixture = createTestComponent('<div [ngClass]="objExpr"></div>');
let objExpr = getComponent().objExpr;
const objExpr = getComponent().objExpr;
detectChangesAndExpectClassName('foo');
@ -134,7 +134,7 @@ export function main() {
it('should add and remove classes based on changes to the expression', async(() => {
fixture = createTestComponent('<div [ngClass]="arrExpr"></div>');
let arrExpr = getComponent().arrExpr;
const arrExpr = getComponent().arrExpr;
detectChangesAndExpectClassName('foo');
arrExpr.push('bar');
@ -259,7 +259,7 @@ export function main() {
it('should co-operate with the class attribute', async(() => {
fixture = createTestComponent('<div [ngClass]="objExpr" class="init foo"></div>');
let objExpr = getComponent().objExpr;
const objExpr = getComponent().objExpr;
objExpr['bar'] = true;
detectChangesAndExpectClassName('init foo bar');
@ -273,7 +273,7 @@ export function main() {
it('should co-operate with the interpolated class attribute', async(() => {
fixture = createTestComponent(`<div [ngClass]="objExpr" class="{{'init foo'}}"></div>`);
let objExpr = getComponent().objExpr;
const objExpr = getComponent().objExpr;
objExpr['bar'] = true;
detectChangesAndExpectClassName(`init foo bar`);
@ -288,7 +288,7 @@ export function main() {
it('should co-operate with the class attribute and binding to it', async(() => {
fixture =
createTestComponent(`<div [ngClass]="objExpr" class="init" [class]="'foo'"></div>`);
let objExpr = getComponent().objExpr;
const objExpr = getComponent().objExpr;
objExpr['bar'] = true;
detectChangesAndExpectClassName(`init foo bar`);
@ -304,7 +304,7 @@ export function main() {
const template =
'<div class="init foo" [ngClass]="objExpr" [class.baz]="condition"></div>';
fixture = createTestComponent(template);
let objExpr = getComponent().objExpr;
const objExpr = getComponent().objExpr;
detectChangesAndExpectClassName('init foo baz');
@ -322,7 +322,7 @@ export function main() {
async(() => {
const template = '<div class="init" [ngClass]="objExpr" [class]="strExpr"></div>';
fixture = createTestComponent(template);
let cmp = getComponent();
const cmp = getComponent();
detectChangesAndExpectClassName('init foo');

View File

@ -19,10 +19,10 @@ export function main() {
describe('AsyncPipe', () => {
describe('Observable', () => {
var emitter: EventEmitter<any>;
var pipe: AsyncPipe;
var ref: any;
var message = {};
let emitter: EventEmitter<any>;
let pipe: AsyncPipe;
let ref: any;
const message = {};
beforeEach(() => {
emitter = new EventEmitter();
@ -62,7 +62,7 @@ export function main() {
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
pipe.transform(emitter);
var newEmitter = new EventEmitter();
const newEmitter = new EventEmitter();
expect(pipe.transform(newEmitter)).toBe(null);
emitter.emit(message);
@ -104,14 +104,14 @@ export function main() {
});
describe('Promise', () => {
var message = new Object();
var pipe: AsyncPipe;
var resolve: (result: any) => void;
var reject: (error: any) => void;
var promise: Promise<any>;
var ref: SpyChangeDetectorRef;
const message = new Object();
let pipe: AsyncPipe;
let resolve: (result: any) => void;
let reject: (error: any) => void;
let promise: Promise<any>;
let ref: SpyChangeDetectorRef;
// adds longer timers for passing tests in IE
var timer = (getDOM() && browserDetection.isIE) ? 50 : 10;
const timer = (getDOM() && browserDetection.isIE) ? 50 : 10;
beforeEach(() => {
promise = new Promise((res, rej) => {
@ -154,7 +154,7 @@ export function main() {
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
pipe.transform(promise);
var promise = new Promise<any>(() => {});
promise = new Promise<any>(() => {});
expect(pipe.transform(promise)).toBe(null);
// this should not affect the pipe, so it should return WrappedValue
@ -168,7 +168,7 @@ export function main() {
it('should request a change detection check upon receiving a new value',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var markForCheck = ref.spy('markForCheck');
const markForCheck = ref.spy('markForCheck');
pipe.transform(promise);
resolve(message);
@ -202,14 +202,14 @@ export function main() {
describe('null', () => {
it('should return null when given null', () => {
var pipe = new AsyncPipe(null);
const pipe = new AsyncPipe(null);
expect(pipe.transform(null)).toEqual(null);
});
});
describe('other types', () => {
it('should throw when given an invalid object', () => {
var pipe = new AsyncPipe(null);
const pipe = new AsyncPipe(null);
expect(() => pipe.transform(<any>'some bogus object')).toThrowError();
});
});

View File

@ -62,7 +62,7 @@ export function main() {
describe('transform', () => {
it('should format each component correctly', () => {
let dateFixtures: any = {
const dateFixtures: any = {
'y': '2015',
'yy': '15',
'M': '6',
@ -75,7 +75,7 @@ export function main() {
'EEEE': 'Monday'
};
let isoStringWithoutTimeFixtures: any = {
const isoStringWithoutTimeFixtures: any = {
'y': '2015',
'yy': '15',
'M': '1',
@ -128,7 +128,7 @@ export function main() {
});
it('should format common multi component patterns', () => {
let dateFixtures: any = {
const dateFixtures: any = {
'EEE, M/d/y': 'Mon, 6/15/2015',
'EEE, M/d': 'Mon, 6/15',
'MMM d': 'Jun 15',
@ -157,7 +157,7 @@ export function main() {
});
it('should format with pattern aliases', () => {
let dateFixtures: any = {
const dateFixtures: any = {
'MM/dd/yyyy': '06/15/2015',
'fullDate': 'Monday, June 15, 2015',
'longDate': 'June 15, 2015',

View File

@ -12,10 +12,10 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_in
export function main() {
describe('I18nPluralPipe', () => {
var localization: NgLocalization;
var pipe: I18nPluralPipe;
let localization: NgLocalization;
let pipe: I18nPluralPipe;
var mapping = {
const mapping = {
'=0': 'No messages.',
'=1': 'One message.',
'many': 'Many messages.',
@ -32,27 +32,27 @@ export function main() {
describe('transform', () => {
it('should return 0 text if value is 0', () => {
var val = pipe.transform(0, mapping);
const val = pipe.transform(0, mapping);
expect(val).toEqual('No messages.');
});
it('should return 1 text if value is 1', () => {
var val = pipe.transform(1, mapping);
const val = pipe.transform(1, mapping);
expect(val).toEqual('One message.');
});
it('should return category messages', () => {
var val = pipe.transform(4, mapping);
const val = pipe.transform(4, mapping);
expect(val).toEqual('Many messages.');
});
it('should interpolate the value into the text where indicated', () => {
var val = pipe.transform(6, mapping);
const val = pipe.transform(6, mapping);
expect(val).toEqual('There are 6 messages, that is 6.');
});
it('should use "" if value is undefined', () => {
var val = pipe.transform(void(0), mapping);
const val = pipe.transform(void(0), mapping);
expect(val).toEqual('');
});

View File

@ -13,10 +13,10 @@ import {expect} from '@angular/platform-browser/testing/matchers';
export function main() {
describe('JsonPipe', () => {
var regNewLine = '\n';
var inceptionObj: any;
var inceptionObjString: string;
var pipe: JsonPipe;
const regNewLine = '\n';
let inceptionObj: any;
let inceptionObjString: string;
let pipe: JsonPipe;
function normalize(obj: string): string { return obj.replace(regNewLine, ''); }
@ -39,14 +39,14 @@ export function main() {
() => { expect(pipe.transform(inceptionObj)).toEqual(inceptionObjString); });
it('should return JSON-formatted string even when normalized', () => {
var dream1 = normalize(pipe.transform(inceptionObj));
var dream2 = normalize(inceptionObjString);
const dream1 = normalize(pipe.transform(inceptionObj));
const dream2 = normalize(inceptionObjString);
expect(dream1).toEqual(dream2);
});
it('should return JSON-formatted string similar to Json.stringify', () => {
var dream1 = normalize(pipe.transform(inceptionObj));
var dream2 = normalize(JSON.stringify(inceptionObj, null, 2));
const dream1 = normalize(pipe.transform(inceptionObj));
const dream2 = normalize(JSON.stringify(inceptionObj, null, 2));
expect(dream1).toEqual(dream2);
});
});
@ -63,8 +63,8 @@ export function main() {
});
it('should work with mutable objects', async(() => {
let fixture = TestBed.createComponent(TestComp);
let mutable: number[] = [1];
const fixture = TestBed.createComponent(TestComp);
const mutable: number[] = [1];
fixture.componentInstance.data = mutable;
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('[\n 1\n]');

View File

@ -11,9 +11,9 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_in
export function main() {
describe('LowerCasePipe', () => {
var upper: string;
var lower: string;
var pipe: LowerCasePipe;
let upper: string;
let lower: string;
let pipe: LowerCasePipe;
beforeEach(() => {
lower = 'something';
@ -23,14 +23,14 @@ export function main() {
describe('transform', () => {
it('should return lowercase', () => {
var val = pipe.transform(upper);
const val = pipe.transform(upper);
expect(val).toEqual(lower);
});
it('should lowercase when there is a new value', () => {
var val = pipe.transform(upper);
const val = pipe.transform(upper);
expect(val).toEqual(lower);
var val2 = pipe.transform('WAT');
const val2 = pipe.transform('WAT');
expect(val2).toEqual('wat');
});

View File

@ -13,7 +13,7 @@ import {browserDetection} from '@angular/platform-browser/testing/browser_util';
export function main() {
describe('Number pipes', () => {
describe('DecimalPipe', () => {
var pipe: DecimalPipe;
let pipe: DecimalPipe;
beforeEach(() => { pipe = new DecimalPipe('en-US'); });
@ -44,7 +44,7 @@ export function main() {
});
describe('PercentPipe', () => {
var pipe: PercentPipe;
let pipe: PercentPipe;
beforeEach(() => { pipe = new PercentPipe('en-US'); });
@ -60,7 +60,7 @@ export function main() {
});
describe('CurrencyPipe', () => {
var pipe: CurrencyPipe;
let pipe: CurrencyPipe;
beforeEach(() => { pipe = new CurrencyPipe('en-US'); });

View File

@ -13,9 +13,9 @@ import {expect} from '@angular/platform-browser/testing/matchers';
export function main() {
describe('SlicePipe', () => {
var list: number[];
var str: string;
var pipe: SlicePipe;
let list: number[];
let str: string;
let pipe: SlicePipe;
beforeEach(() => {
list = [1, 2, 3, 4, 5];
@ -93,8 +93,8 @@ export function main() {
});
it('should work with mutable arrays', async(() => {
let fixture = TestBed.createComponent(TestComp);
let mutable: number[] = [1, 2];
const fixture = TestBed.createComponent(TestComp);
const mutable: number[] = [1, 2];
fixture.componentInstance.data = mutable;
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('2');

View File

@ -11,9 +11,9 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_in
export function main() {
describe('UpperCasePipe', () => {
var upper: string;
var lower: string;
var pipe: UpperCasePipe;
let upper: string;
let lower: string;
let pipe: UpperCasePipe;
beforeEach(() => {
lower = 'something';
@ -24,14 +24,14 @@ export function main() {
describe('transform', () => {
it('should return uppercase', () => {
var val = pipe.transform(lower);
const val = pipe.transform(lower);
expect(val).toEqual(upper);
});
it('should uppercase when there is a new value', () => {
var val = pipe.transform(lower);
const val = pipe.transform(lower);
expect(val).toEqual(upper);
var val2 = pipe.transform('wat');
const val2 = pipe.transform('wat');
expect(val2).toEqual('WAT');
});

View File

@ -34,8 +34,8 @@ export class SpyLocation implements Location {
path(): string { return this._history[this._historyIndex].path; }
isCurrentPathEqualTo(path: string, query: string = ''): boolean {
var givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
var currPath =
const givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
const currPath =
this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path();
return currPath == givenPath + (query.length > 0 ? ('?' + query) : '');
@ -66,12 +66,12 @@ export class SpyLocation implements Location {
this._history.push(new LocationState(path, query));
this._historyIndex = this._history.length - 1;
var locationState = this._history[this._historyIndex - 1];
const locationState = this._history[this._historyIndex - 1];
if (locationState.path == path && locationState.query == query) {
return;
}
var url = path + (query.length > 0 ? ('?' + query) : '');
const url = path + (query.length > 0 ? ('?' + query) : '');
this.urlChanges.push(url);
this._subject.emit({'url': url, 'pop': false});
}
@ -79,7 +79,7 @@ export class SpyLocation implements Location {
replaceState(path: string, query: string = '') {
path = this.prepareExternalUrl(path);
var history = this._history[this._historyIndex];
const history = this._history[this._historyIndex];
if (history.path == path && history.query == query) {
return;
}
@ -87,7 +87,7 @@ export class SpyLocation implements Location {
history.path = path;
history.query = query;
var url = path + (query.length > 0 ? ('?' + query) : '');
const url = path + (query.length > 0 ? ('?' + query) : '');
this.urlChanges.push('replace: ' + url);
}

View File

@ -44,20 +44,20 @@ export class MockLocationStrategy extends LocationStrategy {
pushState(ctx: any, title: string, path: string, query: string): void {
this.internalTitle = title;
var url = path + (query.length > 0 ? ('?' + query) : '');
const url = path + (query.length > 0 ? ('?' + query) : '');
this.internalPath = url;
var externalUrl = this.prepareExternalUrl(url);
const externalUrl = this.prepareExternalUrl(url);
this.urlChanges.push(externalUrl);
}
replaceState(ctx: any, title: string, path: string, query: string): void {
this.internalTitle = title;
var url = path + (query.length > 0 ? ('?' + query) : '');
const url = path + (query.length > 0 ? ('?' + query) : '');
this.internalPath = url;
var externalUrl = this.prepareExternalUrl(url);
const externalUrl = this.prepareExternalUrl(url);
this.urlChanges.push('replace: ' + externalUrl);
}
@ -68,7 +68,7 @@ export class MockLocationStrategy extends LocationStrategy {
back(): void {
if (this.urlChanges.length > 0) {
this.urlChanges.pop();
var nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
const nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
this.simulatePopState(nextUrl);
}
}