cleanup: fix type errors when compiling with strictNullChecks enabled
This commit is contained in:
parent
1f98519380
commit
1a4e911b8b
|
@ -110,7 +110,8 @@ function matchIndex(config: Route[], url: TreeNode<UrlSegment>): 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<UrlSegment>): MatchResult |
|
|||
const path = route.path.startsWith("/") ? route.path.substring(1) : route.path;
|
||||
if (path === "**") {
|
||||
const consumedUrl = [];
|
||||
let u = url;
|
||||
let u:TreeNode<UrlSegment>|null = url;
|
||||
while (u) {
|
||||
consumedUrl.push(u.value);
|
||||
u = first(u.children);
|
||||
|
|
|
@ -12,53 +12,53 @@ export class Tree<T> {
|
|||
}
|
||||
|
||||
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<T>): boolean { return _contains(this._root, tree._root); }
|
||||
contains(tree: Tree<T>): boolean { return contains(this._root, tree._root); }
|
||||
}
|
||||
|
||||
export function rootNode<T>(tree: Tree<T>): TreeNode<T> {
|
||||
return tree._root;
|
||||
}
|
||||
|
||||
function _findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> | null {
|
||||
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> | 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<T>(expected: T, c: TreeNode<T>, collected: TreeNode<T>[]): TreeNode<T>[] {
|
||||
function findPath<T>(expected: T, c: TreeNode<T>, collected: TreeNode<T>[]): TreeNode<T>[] {
|
||||
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<T>(tree: TreeNode<T>, subtree: TreeNode<T>): boolean {
|
||||
function contains<T>(tree: TreeNode<T>, subtree: TreeNode<T>): 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;
|
||||
|
|
Loading…
Reference in New Issue