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

@ -29,9 +29,9 @@ class CustomValidatorDirective implements Validator {
function asyncValidator(expected: any /** TODO #9100 */, timeout = 0) {
return (c: any /** TODO #9100 */) => {
var resolve: (result: any) => void;
var promise = new Promise(res => { resolve = res; });
var res = c.value != expected ? {'async': true} : null;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const res = c.value != expected ? {'async': true} : null;
if (timeout == 0) {
resolve(res);
} else {
@ -43,13 +43,13 @@ function asyncValidator(expected: any /** TODO #9100 */, timeout = 0) {
export function main() {
describe('Form Directives', () => {
var defaultAccessor: DefaultValueAccessor;
let defaultAccessor: DefaultValueAccessor;
beforeEach(() => { defaultAccessor = new DefaultValueAccessor(null, null); });
describe('shared', () => {
describe('selectValueAccessor', () => {
var dir: NgControl;
let dir: NgControl;
beforeEach(() => { dir = <any>new SpyNgControl(); });
@ -60,14 +60,14 @@ export function main() {
() => { expect(selectValueAccessor(dir, [defaultAccessor])).toEqual(defaultAccessor); });
it('should return checkbox accessor when provided', () => {
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
const checkboxAccessor = new CheckboxControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [
defaultAccessor, checkboxAccessor
])).toEqual(checkboxAccessor);
});
it('should return select accessor when provided', () => {
var selectAccessor = new SelectControlValueAccessor(null, null);
const selectAccessor = new SelectControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [
defaultAccessor, selectAccessor
])).toEqual(selectAccessor);
@ -81,14 +81,14 @@ export function main() {
});
it('should throw when more than one build-in accessor is provided', () => {
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
var selectAccessor = new SelectControlValueAccessor(null, null);
const checkboxAccessor = new CheckboxControlValueAccessor(null, null);
const selectAccessor = new SelectControlValueAccessor(null, null);
expect(() => selectValueAccessor(dir, [checkboxAccessor, selectAccessor])).toThrowError();
});
it('should return custom accessor when provided', () => {
var customAccessor = new SpyValueAccessor();
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
const customAccessor = new SpyValueAccessor();
const checkboxAccessor = new CheckboxControlValueAccessor(null, null);
expect(selectValueAccessor(dir, <any>[defaultAccessor, customAccessor, checkboxAccessor]))
.toEqual(customAccessor);
});
@ -102,22 +102,22 @@ export function main() {
});
it('should throw when more than one custom accessor is provided', () => {
var customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
const customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError();
});
});
describe('composeValidators', () => {
it('should compose functions', () => {
var dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
var dummy2 = (_: any /** TODO #9100 */) => ({'dummy2': true});
var v = composeValidators([dummy1, dummy2]);
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
const dummy2 = (_: any /** TODO #9100 */) => ({'dummy2': true});
const v = composeValidators([dummy1, dummy2]);
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'dummy2': true});
});
it('should compose validator directives', () => {
var dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
var v = composeValidators([dummy1, new CustomValidatorDirective()]);
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
const v = composeValidators([dummy1, new CustomValidatorDirective()]);
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'custom': true});
});
});
@ -228,7 +228,7 @@ export function main() {
});
describe('addFormGroup', () => {
var matchingPasswordsValidator = (g: any /** TODO #9100 */) => {
const matchingPasswordsValidator = (g: any /** TODO #9100 */) => {
if (g.controls['password'].value != g.controls['passwordConfirm'].value) {
return {'differentPasswords': true};
} else {
@ -237,7 +237,7 @@ export function main() {
};
it('should set up validator', fakeAsync(() => {
var group = new FormGroupName(
const group = new FormGroupName(
form, [matchingPasswordsValidator], [asyncValidator('expected')]);
group.name = 'passwords';
form.addFormGroup(group);
@ -283,8 +283,8 @@ export function main() {
});
it('should set up a sync validator', () => {
var formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
var f = new FormGroupDirective([formValidator], []);
const formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
const f = new FormGroupDirective([formValidator], []);
f.form = formModel;
f.ngOnChanges({'form': new SimpleChange(null, null)});
@ -292,7 +292,7 @@ export function main() {
});
it('should set up an async validator', fakeAsync(() => {
var f = new FormGroupDirective([], [asyncValidator('expected')]);
const f = new FormGroupDirective([], [asyncValidator('expected')]);
f.form = formModel;
f.ngOnChanges({'form': new SimpleChange(null, null)});
@ -304,10 +304,10 @@ export function main() {
});
describe('NgForm', () => {
var form: any /** TODO #9100 */;
var formModel: FormGroup;
var loginControlDir: any /** TODO #9100 */;
var personControlGroupDir: any /** TODO #9100 */;
let form: any /** TODO #9100 */;
let formModel: FormGroup;
let loginControlDir: any /** TODO #9100 */;
let personControlGroupDir: any /** TODO #9100 */;
beforeEach(() => {
form = new NgForm([], []);
@ -378,8 +378,8 @@ export function main() {
});
it('should set up sync validator', fakeAsync(() => {
var formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
var f = new NgForm([formValidator], []);
const formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
const f = new NgForm([formValidator], []);
tick();
@ -387,7 +387,7 @@ export function main() {
}));
it('should set up async validator', fakeAsync(() => {
var f = new NgForm([], [asyncValidator('expected')]);
const f = new NgForm([], [asyncValidator('expected')]);
tick();
@ -396,13 +396,13 @@ export function main() {
});
describe('FormGroupName', () => {
var formModel: any /** TODO #9100 */;
var controlGroupDir: any /** TODO #9100 */;
let formModel: any /** TODO #9100 */;
let controlGroupDir: any /** TODO #9100 */;
beforeEach(() => {
formModel = new FormGroup({'login': new FormControl(null)});
var parent = new FormGroupDirective([], []);
const parent = new FormGroupDirective([], []);
parent.form = new FormGroup({'group': formModel});
controlGroupDir = new FormGroupName(parent, [], []);
controlGroupDir.name = 'group';
@ -436,8 +436,8 @@ export function main() {
});
describe('FormArrayName', () => {
var formModel: FormArray;
var formArrayDir: FormArrayName;
let formModel: FormArray;
let formArrayDir: FormArrayName;
beforeEach(() => {
const parent = new FormGroupDirective([], []);
@ -473,9 +473,9 @@ export function main() {
});
describe('FormControlDirective', () => {
var controlDir: any /** TODO #9100 */;
var control: any /** TODO #9100 */;
var checkProperties = function(control: any /** TODO #9100 */) {
let controlDir: any /** TODO #9100 */;
let control: any /** TODO #9100 */;
const checkProperties = function(control: any /** TODO #9100 */) {
expect(controlDir.control).toBe(control);
expect(controlDir.value).toBe(control.value);
expect(controlDir.valid).toBe(control.valid);
@ -512,7 +512,7 @@ export function main() {
});
it('should reexport new control properties', () => {
var newControl = new FormControl(null);
const newControl = new FormControl(null);
controlDir.form = newControl;
controlDir.ngOnChanges({'form': new SimpleChange(control, newControl)});
@ -636,13 +636,13 @@ export function main() {
});
describe('FormControlName', () => {
var formModel: any /** TODO #9100 */;
var controlNameDir: any /** TODO #9100 */;
let formModel: any /** TODO #9100 */;
let controlNameDir: any /** TODO #9100 */;
beforeEach(() => {
formModel = new FormControl('name');
var parent = new FormGroupDirective([], []);
const parent = new FormGroupDirective([], []);
parent.form = new FormGroup({'name': formModel});
controlNameDir = new FormControlName(parent, [], [], [defaultAccessor]);
controlNameDir.name = 'name';

View File

@ -16,10 +16,10 @@ import {Validators} from '../src/validators';
export function main() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: AbstractControl) => {
var resolve: (result: any) => void;
var promise = new Promise(res => { resolve = res; });
var t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
var res = c.value != expected ? {'async': true} : null;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
if (t == 0) {
resolve(res);
@ -527,8 +527,8 @@ export function main() {
const simpleValidator = (c: FormArray) =>
c.controls[0].value != 'correct' ? {'broken': true} : null;
var c = new FormControl(null);
var g = new FormArray([c], simpleValidator);
const c = new FormControl(null);
const g = new FormArray([c], simpleValidator);
c.setValue('correct');
@ -633,7 +633,7 @@ export function main() {
it('should fire an event after the control\'s observable fired an event',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var controlCallbackIsCalled = false;
let controlCallbackIsCalled = false;
c1.valueChanges.subscribe({next: (value: any) => { controlCallbackIsCalled = true; }});

View File

@ -19,7 +19,7 @@ export function main() {
beforeEach(() => { b = new FormBuilder(); });
it('should create controls from a value', () => {
var g = b.group({'login': 'some value'});
const g = b.group({'login': 'some value'});
expect(g.controls['login'].value).toEqual('some value');
});
@ -32,7 +32,7 @@ export function main() {
});
it('should create controls from an array', () => {
var g = b.group(
const g = b.group(
{'login': ['some value'], 'password': ['some value', syncValidator, asyncValidator]});
expect(g.controls['login'].value).toEqual('some value');
@ -42,7 +42,7 @@ export function main() {
});
it('should use controls', () => {
var g = b.group({'login': b.control('some value', syncValidator, asyncValidator)});
const g = b.group({'login': b.control('some value', syncValidator, asyncValidator)});
expect(g.controls['login'].value).toEqual('some value');
expect(g.controls['login'].validator).toBe(syncValidator);
@ -50,7 +50,7 @@ export function main() {
});
it('should create groups with a custom validator', () => {
var g = b.group(
const g = b.group(
{'login': 'some value'}, {'validator': syncValidator, 'asyncValidator': asyncValidator});
expect(g.validator).toBe(syncValidator);
@ -58,8 +58,8 @@ export function main() {
});
it('should create control arrays', () => {
var c = b.control('three');
var a = b.array(
const c = b.control('three');
const a = b.array(
['one', ['two', syncValidator], c, b.array(['four'])], syncValidator, asyncValidator);
expect(a.value).toEqual(['one', 'two', 'three', ['four']]);

View File

@ -17,10 +17,10 @@ import {FormArray} from '../src/model';
export function main() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: FormControl) => {
var resolve: (result: any) => void;
var promise = new Promise(res => { resolve = res; });
var t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
var res = c.value != expected ? {'async': true} : null;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
if (t == 0) {
resolve(res);
@ -33,7 +33,7 @@ export function main() {
}
function asyncValidatorReturningObservable(c: FormControl) {
var e = new EventEmitter();
const e = new EventEmitter();
Promise.resolve(null).then(() => { e.emit({'async': true}); });
return e;
}
@ -616,9 +616,9 @@ export function main() {
}));
it('should fire an event after the status has been updated to pending', fakeAsync(() => {
var c = new FormControl('old', Validators.required, asyncValidator('expected'));
const c = new FormControl('old', Validators.required, asyncValidator('expected'));
var log: any[] /** TODO #9100 */ = [];
const log: any[] /** TODO #9100 */ = [];
c.valueChanges.subscribe({next: (value: any) => log.push(`value: '${value}'`)});
c.statusChanges.subscribe({next: (status: any) => log.push(`status: '${status}'`)});

View File

@ -16,10 +16,10 @@ import {isPresent} from '../src/facade/lang';
export function main() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: AbstractControl) => {
var resolve: (result: any) => void;
var promise = new Promise(res => { resolve = res; });
var t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
var res = c.value != expected ? {'async': true} : null;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
if (t == 0) {
resolve(res);
@ -32,7 +32,7 @@ export function main() {
}
function asyncValidatorReturningObservable(c: FormControl) {
var e = new EventEmitter();
const e = new EventEmitter();
Promise.resolve(null).then(() => { e.emit({'async': true}); });
return e;
}
@ -92,8 +92,8 @@ export function main() {
const simpleValidator = (c: FormGroup) =>
c.controls['one'].value != 'correct' ? {'broken': true} : null;
var c = new FormControl(null);
var g = new FormGroup({'one': c}, simpleValidator);
const c = new FormControl(null);
const g = new FormGroup({'one': c}, simpleValidator);
c.setValue('correct');

View File

@ -1826,9 +1826,9 @@ class MyInput implements ControlValueAccessor {
function uniqLoginAsyncValidator(expectedValue: string) {
return (c: AbstractControl) => {
var resolve: (result: any) => void;
var promise = new Promise(res => { resolve = res; });
var res = (c.value == expectedValue) ? null : {'uniqLogin': true};
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const res = (c.value == expectedValue) ? null : {'uniqLogin': true};
resolve(res);
return promise;
};

View File

@ -510,11 +510,11 @@ export function main() {
fixture.componentInstance.val = 4;
fixture.detectChanges();
tick();
let input = fixture.debugElement.query(By.css('input'));
const input = fixture.debugElement.query(By.css('input'));
expect(input.nativeElement.value).toBe('4');
fixture.detectChanges();
tick();
let newVal = '4';
const newVal = '4';
input.triggerEventHandler('input', {target: {value: newVal}});
tick();
// view -> model

View File

@ -156,8 +156,8 @@ export function main() {
describe('composeAsync', () => {
function asyncValidator(expected: any /** TODO #9100 */, response: any /** TODO #9100 */) {
return (c: any /** TODO #9100 */) => {
var emitter = new EventEmitter();
var res = c.value != expected ? response : null;
const emitter = new EventEmitter();
const res = c.value != expected ? response : null;
Promise.resolve(null).then(() => {
emitter.emit(res);
// this is required because of a bug in ObservableWrapper
@ -174,11 +174,11 @@ export function main() {
() => { expect(Validators.composeAsync(null)).toBeNull(); });
it('should collect errors from all the validators', fakeAsync(() => {
var c = Validators.composeAsync([
const c = Validators.composeAsync([
asyncValidator('expected', {'one': true}), asyncValidator('expected', {'two': true})
]);
var value: any /** TODO #9100 */ = null;
let value: any /** TODO #9100 */ = null;
(<Promise<any>>c(new FormControl('invalid'))).then(v => value = v);
tick(1);
@ -198,9 +198,9 @@ export function main() {
}));
it('should return null when no errors', fakeAsync(() => {
var c = Validators.composeAsync([asyncValidator('expected', {'one': true})]);
const c = Validators.composeAsync([asyncValidator('expected', {'one': true})]);
var value: any /** TODO #9100 */ = null;
let value: any /** TODO #9100 */ = null;
(<Promise<any>>c(new FormControl('expected'))).then(v => value = v);
tick(1);
@ -208,9 +208,9 @@ export function main() {
}));
it('should ignore nulls', fakeAsync(() => {
var c = Validators.composeAsync([asyncValidator('expected', {'one': true}), null]);
const c = Validators.composeAsync([asyncValidator('expected', {'one': true}), null]);
var value: any /** TODO #9100 */ = null;
let value: any /** TODO #9100 */ = null;
(<Promise<any>>c(new FormControl('invalid'))).then(v => value = v);
tick(1);