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

@ -404,7 +404,7 @@ function addEmptySegmentsToChildrenIfNeeded(
segmentGroup: UrlSegmentGroup, slicedSegments: UrlSegment[], routes: Route[],
children: {[name: string]: UrlSegmentGroup}): {[name: string]: UrlSegmentGroup} {
const res: {[name: string]: UrlSegmentGroup} = {};
for (let r of routes) {
for (const r of routes) {
if (emptyPathRedirect(segmentGroup, slicedSegments, r) && !children[getOutlet(r)]) {
res[getOutlet(r)] = new UrlSegmentGroup([], {});
}
@ -416,7 +416,7 @@ function createChildrenForEmptySegments(
routes: Route[], primarySegmentGroup: UrlSegmentGroup): {[name: string]: UrlSegmentGroup} {
const res: {[name: string]: UrlSegmentGroup} = {};
res[PRIMARY_OUTLET] = primarySegmentGroup;
for (let r of routes) {
for (const r of routes) {
if (r.path === '' && getOutlet(r) !== PRIMARY_OUTLET) {
res[getOutlet(r)] = new UrlSegmentGroup([], {});
}

View File

@ -124,7 +124,7 @@ function normalizeCommands(commands: any[]): NormalizedNavigationCommands {
if (i === 0) {
const parts = c.split('/');
for (let j = 0; j < parts.length; ++j) {
let cc = parts[j];
const cc = parts[j];
if (j == 0 && cc == '.') { // './a'
// skip it
@ -204,7 +204,7 @@ function updateSegmentGroup(
const m = prefixedWith(segmentGroup, startIndex, commands);
const slicedCommands = commands.slice(m.commandIndex);
if (m.match && m.pathIndex < segmentGroup.segments.length) {
var g = new UrlSegmentGroup(segmentGroup.segments.slice(0, m.pathIndex), {});
const g = new UrlSegmentGroup(segmentGroup.segments.slice(0, m.pathIndex), {});
g.children[PRIMARY_OUTLET] =
new UrlSegmentGroup(segmentGroup.segments.slice(m.pathIndex), segmentGroup.children);
return updateSegmentGroupChildren(g, 0, slicedCommands);

View File

@ -83,7 +83,7 @@ class Recognizer {
processSegment(
config: Route[], segmentGroup: UrlSegmentGroup, pathIndex: number, segments: UrlSegment[],
outlet: string): TreeNode<ActivatedRouteSnapshot>[] {
for (let r of config) {
for (const r of config) {
try {
return this.processSegmentAgainstRoute(r, segmentGroup, pathIndex, segments, outlet);
} catch (e) {
@ -188,7 +188,7 @@ function match(segmentGroup: UrlSegmentGroup, route: Route, segments: UrlSegment
function checkOutletNameUniqueness(nodes: TreeNode<ActivatedRouteSnapshot>[]): void {
const names: {[k: string]: ActivatedRouteSnapshot} = {};
nodes.forEach(n => {
let routeWithSameOutletName = names[n.value.outlet];
const routeWithSameOutletName = names[n.value.outlet];
if (routeWithSameOutletName) {
const p = routeWithSameOutletName.url.map(s => s.toString()).join('/');
const c = n.value.url.map(s => s.toString()).join('/');
@ -251,7 +251,7 @@ function addEmptyPathsToChildrenIfNeeded(
segmentGroup: UrlSegmentGroup, slicedSegments: UrlSegment[], routes: Route[],
children: {[name: string]: UrlSegmentGroup}): {[name: string]: UrlSegmentGroup} {
const res: {[name: string]: UrlSegmentGroup} = {};
for (let r of routes) {
for (const r of routes) {
if (emptyPathMatch(segmentGroup, slicedSegments, r) && !children[getOutlet(r)]) {
const s = new UrlSegmentGroup([], {});
s._sourceSegment = segmentGroup;
@ -270,7 +270,7 @@ function createChildrenForEmptyPaths(
primarySegment._sourceSegment = segmentGroup;
primarySegment._segmentIndexShift = consumedSegments.length;
for (let r of routes) {
for (const r of routes) {
if (r.path === '' && getOutlet(r) !== PRIMARY_OUTLET) {
const s = new UrlSegmentGroup([], {});
s._sourceSegment = segmentGroup;

View File

@ -1169,7 +1169,7 @@ function nodeChildrenAsMap(node: TreeNode<any>) {
}
function getOutlet(outletMap: RouterOutletMap, route: ActivatedRoute): RouterOutlet {
let outlet = outletMap._outlets[route.outlet];
const outlet = outletMap._outlets[route.outlet];
if (!outlet) {
const componentName = (<any>route.component).name;
if (route.outlet === PRIMARY_OUTLET) {

View File

@ -94,7 +94,7 @@ export class RouterPreloader {
private processRoutes(injector: Injector, routes: Routes): Observable<void> {
const res: Observable<any>[] = [];
for (let c of routes) {
for (const c of routes) {
// we already have the config loaded, just recurce
if (c.loadChildren && !c.canLoad && (<any>c)._loadedConfig) {
const childConfig = (<any>c)._loadedConfig;

View File

@ -31,7 +31,7 @@ function equalQueryParams(
function equalSegmentGroups(container: UrlSegmentGroup, containee: UrlSegmentGroup): boolean {
if (!equalPath(container.segments, containee.segments)) return false;
if (container.numberOfChildren !== containee.numberOfChildren) return false;
for (let c in containee.children) {
for (const c in containee.children) {
if (!container.children[c]) return false;
if (!equalSegmentGroups(container.children[c], containee.children[c])) return false;
}
@ -58,7 +58,7 @@ function containsSegmentGroupHelper(
} else if (container.segments.length === containeePaths.length) {
if (!equalPath(container.segments, containeePaths)) return false;
for (let c in containee.children) {
for (const c in containee.children) {
if (!container.children[c]) return false;
if (!containsSegmentGroup(container.children[c], containee.children[c])) return false;
}
@ -380,7 +380,7 @@ class Pair<A, B> {
}
function pairs<T>(obj: {[key: string]: T}): Pair<string, T>[] {
const res: Pair<string, T>[] = [];
for (let prop in obj) {
for (const prop in obj) {
if (obj.hasOwnProperty(prop)) {
res.push(new Pair<string, T>(prop, obj[prop]));
}
@ -443,7 +443,7 @@ class UrlParser {
this.capture('/');
}
let paths: any[] = [];
const paths: any[] = [];
if (!this.peekStartsWith('(')) {
paths.push(this.parseSegments());
}
@ -543,7 +543,7 @@ class UrlParser {
let value: any = '';
if (this.peekStartsWith('=')) {
this.capture('=');
var valueMatch = matchUrlQueryParamValue(this.remaining);
const valueMatch = matchUrlQueryParamValue(this.remaining);
if (valueMatch) {
value = valueMatch;
this.capture(value);

View File

@ -64,15 +64,15 @@ export function and(bools: boolean[]): boolean {
}
export function merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key: string]: V} {
var m: {[key: string]: V} = {};
const m: {[key: string]: V} = {};
for (var attr in m1) {
for (const attr in m1) {
if (m1.hasOwnProperty(attr)) {
m[attr] = m1[attr];
}
}
for (var attr in m2) {
for (const attr in m2) {
if (m2.hasOwnProperty(attr)) {
m[attr] = m2[attr];
}
@ -83,7 +83,7 @@ export function merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key:
export function forEach<K, V>(
map: {[key: string]: V}, callback: /*(V, K) => void*/ Function): void {
for (var prop in map) {
for (const prop in map) {
if (map.hasOwnProperty(prop)) {
callback(map[prop], prop);
}

View File

@ -57,7 +57,7 @@ export class Tree<T> {
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> {
if (expected === c.value) return c;
for (let cc of c.children) {
for (const cc of c.children) {
const r = findNode(expected, cc);
if (r) return r;
}
@ -68,7 +68,7 @@ function findPath<T>(expected: T, c: TreeNode<T>, collected: TreeNode<T>[]): Tre
collected.push(c);
if (expected === c.value) return collected;
for (let cc of c.children) {
for (const cc of c.children) {
const cloned = collected.slice(0);
const r = findPath(expected, cc, cloned);
if (r.length > 0) return r;

View File

@ -826,10 +826,10 @@ describe('Integration', () => {
expect(primaryCmp.route.snapshot.data).toEqual({one: 1, two: 2, three: 3, four: 4});
expect(rightCmp.route.snapshot.data).toEqual({one: 1, two: 2, five: 5, six: 6});
let primaryRecorded: any[] = [];
const primaryRecorded: any[] = [];
primaryCmp.route.data.forEach((rec: any) => primaryRecorded.push(rec));
let rightRecorded: any[] = [];
const rightRecorded: any[] = [];
rightCmp.route.data.forEach((rec: any) => rightRecorded.push(rec));
router.navigateByUrl('/parent/2');
@ -850,7 +850,7 @@ describe('Integration', () => {
router.resetConfig(
[{path: 'simple', component: SimpleCmp, resolve: {error: 'resolveError'}}]);
let recordedEvents: any[] = [];
const recordedEvents: any[] = [];
router.events.subscribe(e => recordedEvents.push(e));
let e: any = null;
@ -878,7 +878,7 @@ describe('Integration', () => {
]
}]);
let e: any = null;
const e: any = null;
router.navigateByUrl('/parent/child1');
advance(fixture);
@ -899,7 +899,7 @@ describe('Integration', () => {
resolve: {numberOfUrlSegments: 'numberOfUrlSegments'}
}]);
let e: any = null;
const e: any = null;
router.navigateByUrl('/one/two');
advance(fixture);
const cmp = fixture.debugElement.children[1].componentInstance;
@ -2278,7 +2278,7 @@ describe('Integration', () => {
]
}]);
let events: any[] = [];
const events: any[] = [];
router.events.subscribe(e => events.push(e));
// supported URL
@ -2336,7 +2336,7 @@ describe('Integration', () => {
]
}]);
let events: any[] = [];
const events: any[] = [];
router.events.subscribe(e => events.push(e));
location.go('/include/user/kate(aux:excluded)');

View File

@ -56,7 +56,7 @@ export class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {
*/
set stubbedModules(modules: {[path: string]: any}) {
const res: {[path: string]: any} = {};
for (let t of Object.keys(modules)) {
for (const t of Object.keys(modules)) {
res[t] = this.compiler.compileModuleAsync(modules[t]);
}
this._stubbedModules = res;