From 1a4e911b8bf3c36db75581ee507eccd7570572c4 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 24 May 2016 13:22:49 -0700 Subject: [PATCH] cleanup: fix type errors when compiling with strictNullChecks enabled --- modules/@angular/router/src/recognize.ts | 5 +++-- modules/@angular/router/src/tree.ts | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/@angular/router/src/recognize.ts b/modules/@angular/router/src/recognize.ts index ee5b4e62d3..c94581be91 100644 --- a/modules/@angular/router/src/recognize.ts +++ b/modules/@angular/router/src/recognize.ts @@ -110,7 +110,8 @@ function matchIndex(config: Route[], url: TreeNode): MatchResult | n for (let r of config) { if (r.index) { const outlet = r.outlet ? r.outlet : PRIMARY_OUTLET; - return new MatchResult(r.component, r.children, [], {}, [url], [], outlet); + const children = r.children ? r.children : []; + return new MatchResult(r.component, children, [], {}, [url], [], outlet); } } return null; @@ -122,7 +123,7 @@ function matchWithParts(route: Route, url: TreeNode): MatchResult | const path = route.path.startsWith("/") ? route.path.substring(1) : route.path; if (path === "**") { const consumedUrl = []; - let u = url; + let u:TreeNode|null = url; while (u) { consumedUrl.push(u.value); u = first(u.children); diff --git a/modules/@angular/router/src/tree.ts b/modules/@angular/router/src/tree.ts index 0d904bce6b..f70040115f 100644 --- a/modules/@angular/router/src/tree.ts +++ b/modules/@angular/router/src/tree.ts @@ -12,53 +12,53 @@ export class Tree { } children(t: T): T[] { - const n = _findNode(t, this._root); + const n = findNode(t, this._root); return n ? n.children.map(t => t.value) : []; } firstChild(t: T): T | null { - const n = _findNode(t, this._root); + const n = findNode(t, this._root); return n && n.children.length > 0 ? n.children[0].value : null; } - pathFromRoot(t: T): T[] { return _findPath(t, this._root, []).map(s => s.value); } + pathFromRoot(t: T): T[] { return findPath(t, this._root, []).map(s => s.value); } - contains(tree: Tree): boolean { return _contains(this._root, tree._root); } + contains(tree: Tree): boolean { return contains(this._root, tree._root); } } export function rootNode(tree: Tree): TreeNode { return tree._root; } -function _findNode(expected: T, c: TreeNode): TreeNode | null { +function findNode(expected: T, c: TreeNode): TreeNode | null { if (expected === c.value) return c; for (let cc of c.children) { - const r = _findNode(expected, cc); + const r = findNode(expected, cc); if (r) return r; } return null; } -function _findPath(expected: T, c: TreeNode, collected: TreeNode[]): TreeNode[] { +function findPath(expected: T, c: TreeNode, collected: TreeNode[]): TreeNode[] { collected.push(c); if (expected === c.value) return collected; for (let cc of c.children) { const cloned = collected.slice(0); - const r = _findPath(expected, cc, cloned); + const r = findPath(expected, cc, cloned); if (r) return r; } return []; } -function _contains(tree: TreeNode, subtree: TreeNode): boolean { +function contains(tree: TreeNode, subtree: TreeNode): boolean { if (tree.value !== subtree.value) return false; for (let subtreeNode of subtree.children) { const s = tree.children.filter(child => child.value === subtreeNode.value); if (s.length === 0) return false; - if (!_contains(s[0], subtreeNode)) return false; + if (!contains(s[0], subtreeNode)) return false; } return true;