cleanup(router): enable noImplicitAny and noImplicntReturns

This commit is contained in:
vsavkin 2016-06-15 16:45:19 -07:00
parent cdbf67ee05
commit 4450e7b246
15 changed files with 154 additions and 133 deletions

View File

@ -1,4 +1,5 @@
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';
import {of } from 'rxjs/observable/of'; import {of } from 'rxjs/observable/of';
import {Route, RouterConfig} from './config'; import {Route, RouterConfig} from './config';
@ -21,9 +22,10 @@ export function applyRedirects(urlTree: UrlTree, config: RouterConfig): Observab
urlTree, new UrlSegment([], {[PRIMARY_OUTLET]: new UrlSegment(e.paths, {})})); urlTree, new UrlSegment([], {[PRIMARY_OUTLET]: new UrlSegment(e.paths, {})}));
} else if (e instanceof NoMatch) { } else if (e instanceof NoMatch) {
return new Observable<UrlTree>( return new Observable<UrlTree>(
obs => obs.error(new Error(`Cannot match any routes: '${e.segment}'`))); (obs: Observer<UrlTree>) =>
obs.error(new Error(`Cannot match any routes: '${e.segment}'`)));
} else { } else {
return new Observable<UrlTree>(obs => obs.error(e)); return new Observable<UrlTree>((obs: Observer<UrlTree>) => obs.error(e));
} }
} }
} }
@ -128,7 +130,11 @@ function matchPathsWithParamsAgainstRoute(
} }
} }
function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) { function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]): {
consumedPaths: UrlPathWithParams[],
lastChild: number,
positionalParamSegments: {[k: string]: UrlPathWithParams}
} {
if (route.index || route.path === '' || route.path === '/') { if (route.index || route.path === '' || route.path === '/') {
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) { if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
throw new NoMatch(); throw new NoMatch();
@ -139,8 +145,8 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
const path = route.path.startsWith('/') ? route.path.substring(1) : route.path; const path = route.path.startsWith('/') ? route.path.substring(1) : route.path;
const parts = path.split('/'); const parts = path.split('/');
const positionalParamSegments = {}; const positionalParamSegments: {[k: string]: UrlPathWithParams} = {};
const consumedPaths = []; const consumedPaths: UrlPathWithParams[] = [];
let currentIndex = 0; let currentIndex = 0;

View File

@ -13,7 +13,9 @@ export const ROUTER_OPTIONS = new OpaqueToken('ROUTER_OPTIONS');
export interface ExtraOptions { enableTracing?: boolean; } export interface ExtraOptions { enableTracing?: boolean; }
export function setupRouter( export function setupRouter(
ref, resolver, urlSerializer, outletMap, location, injector, config, opts) { ref: ApplicationRef, resolver: ComponentResolver, urlSerializer: UrlSerializer,
outletMap: RouterOutletMap, location: Location, injector: Injector, config: RouterConfig,
opts: ExtraOptions) {
if (ref.componentTypes.length == 0) { if (ref.componentTypes.length == 0) {
throw new Error('Bootstrap at least one component before injecting Router.'); throw new Error('Bootstrap at least one component before injecting Router.');
} }
@ -38,15 +40,15 @@ export function setupRouterInitializer(injector: Injector) {
// https://github.com/angular/angular/issues/9101 // https://github.com/angular/angular/issues/9101
// Delay the router instantiation to avoid circular dependency (ApplicationRef -> // Delay the router instantiation to avoid circular dependency (ApplicationRef ->
// APP_INITIALIZER -> Router) // APP_INITIALIZER -> Router)
setTimeout(_ => { setTimeout(() => {
const appRef = injector.get(ApplicationRef); const appRef = injector.get(ApplicationRef);
if (appRef.componentTypes.length == 0) { if (appRef.componentTypes.length == 0) {
appRef.registerBootstrapListener((_) => { injector.get(Router).initialNavigation(); }); appRef.registerBootstrapListener(() => { injector.get(Router).initialNavigation(); });
} else { } else {
injector.get(Router).initialNavigation(); injector.get(Router).initialNavigation();
} }
}, 0); }, 0);
return _ => null; return (): any => null;
} }
/** /**
@ -83,7 +85,7 @@ export function provideRouter(_config: RouterConfig, _opts: ExtraOptions): any[]
}, },
RouterOutletMap, RouterOutletMap,
{provide: ActivatedRoute, useFactory: (r) => r.routerState.root, deps: [Router]}, {provide: ActivatedRoute, useFactory: (r: Router) => r.routerState.root, deps: [Router]},
// Trigger initial navigation // Trigger initial navigation
{provide: APP_INITIALIZER, multi: true, useFactory: setupRouterInitializer, deps: [Injector]} {provide: APP_INITIALIZER, multi: true, useFactory: setupRouterInitializer, deps: [Injector]}

View File

@ -39,11 +39,11 @@ function tree(
function replaceSegment( function replaceSegment(
current: UrlSegment, oldSegment: UrlSegment, newSegment: UrlSegment): UrlSegment { current: UrlSegment, oldSegment: UrlSegment, newSegment: UrlSegment): UrlSegment {
const children: {[key: string]: UrlSegment} = {}; const children: {[key: string]: UrlSegment} = {};
forEach(current.children, (c, k) => { forEach(current.children, (c: UrlSegment, outletName: string) => {
if (c === oldSegment) { if (c === oldSegment) {
children[k] = newSegment; children[outletName] = newSegment;
} else { } else {
children[k] = replaceSegment(c, oldSegment, newSegment); children[outletName] = replaceSegment(c, oldSegment, newSegment);
} }
}); });
return new UrlSegment(current.pathsWithParams, children); return new UrlSegment(current.pathsWithParams, children);
@ -66,7 +66,7 @@ function normalizeCommands(commands: any[]): NormalizedNavigationCommands {
let numberOfDoubleDots = 0; let numberOfDoubleDots = 0;
let isAbsolute = false; let isAbsolute = false;
const res = []; const res: any[] = [];
for (let i = 0; i < commands.length; ++i) { for (let i = 0; i < commands.length; ++i) {
const c = commands[i]; const c = commands[i];
@ -164,7 +164,7 @@ function updateSegmentChildren(
const outlet = getOutlet(commands); const outlet = getOutlet(commands);
const children: {[key: string]: UrlSegment} = {}; const children: {[key: string]: UrlSegment} = {};
children[outlet] = updateSegment(segment.children[outlet], startIndex, commands); children[outlet] = updateSegment(segment.children[outlet], startIndex, commands);
forEach(segment.children, (child, childOutlet) => { forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
if (childOutlet !== outlet) { if (childOutlet !== outlet) {
children[childOutlet] = child; children[childOutlet] = child;
} }
@ -224,7 +224,7 @@ function createNewSegment(segment: UrlSegment, startIndex: number, commands: any
function stringify(params: {[key: string]: any}): {[key: string]: string} { function stringify(params: {[key: string]: any}): {[key: string]: string} {
const res: {[key: string]: string} = {}; const res: {[key: string]: string} = {};
forEach(params, (v, k) => res[k] = `${v}`); forEach(params, (v: any, k: string) => res[k] = `${v}`);
return res; return res;
} }

View File

@ -1,5 +1,6 @@
import {Type} from '@angular/core'; import {Type} from '@angular/core';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';
import {of } from 'rxjs/observable/of'; import {of } from 'rxjs/observable/of';
import {Route, RouterConfig} from './config'; import {Route, RouterConfig} from './config';
@ -25,9 +26,11 @@ export function recognize(
} catch (e) { } catch (e) {
if (e instanceof NoMatch) { if (e instanceof NoMatch) {
return new Observable<RouterStateSnapshot>( return new Observable<RouterStateSnapshot>(
obs => obs.error(new Error(`Cannot match any routes: '${e.segment}'`))); (obs: Observer<RouterStateSnapshot>) =>
obs.error(new Error(`Cannot match any routes: '${e.segment}'`)));
} else { } else {
return new Observable<RouterStateSnapshot>(obs => obs.error(e)); return new Observable<RouterStateSnapshot>(
(obs: Observer<RouterStateSnapshot>) => obs.error(e));
} }
} }
} }
@ -119,7 +122,7 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
const path = route.path.startsWith('/') ? route.path.substring(1) : route.path; const path = route.path.startsWith('/') ? route.path.substring(1) : route.path;
const parts = path.split('/'); const parts = path.split('/');
const posParameters: {[key: string]: any} = {}; const posParameters: {[key: string]: any} = {};
const consumedPaths = []; const consumedPaths: UrlPathWithParams[] = [];
let currentIndex = 0; let currentIndex = 0;
@ -147,11 +150,11 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
} }
function checkOutletNameUniqueness(nodes: TreeNode<ActivatedRouteSnapshot>[]): void { function checkOutletNameUniqueness(nodes: TreeNode<ActivatedRouteSnapshot>[]): void {
const names = {}; const names: {[k: string]: ActivatedRouteSnapshot} = {};
nodes.forEach(n => { nodes.forEach(n => {
let routeWithSameOutletName = names[n.value.outlet]; let routeWithSameOutletName = names[n.value.outlet];
if (routeWithSameOutletName) { if (routeWithSameOutletName) {
const p = routeWithSameOutletName.urlSegments.map(s => s.toString()).join('/'); const p = routeWithSameOutletName.url.map(s => s.toString()).join('/');
const c = n.value.url.map(s => s.toString()).join('/'); const c = n.value.url.map(s => s.toString()).join('/');
throw new Error(`Two segments cannot have the same outlet name: '${p}' and '${c}'.`); throw new Error(`Two segments cannot have the same outlet name: '${p}' and '${c}'.`);
} }

View File

@ -265,8 +265,8 @@ export class Router {
} }
return new Promise((resolvePromise, rejectPromise) => { return new Promise((resolvePromise, rejectPromise) => {
let updatedUrl; let updatedUrl: UrlTree;
let state; let state: RouterState;
applyRedirects(url, this.config) applyRedirects(url, this.config)
.mergeMap(u => { .mergeMap(u => {
updatedUrl = u; updatedUrl = u;
@ -293,7 +293,7 @@ export class Router {
.check(this.outletMap); .check(this.outletMap);
}) })
.forEach((shouldActivate) => { .forEach((shouldActivate: boolean) => {
if (!shouldActivate || id !== this.navigationId) { if (!shouldActivate || id !== this.navigationId) {
this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url))); this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url)));
return Promise.resolve(false); return Promise.resolve(false);
@ -311,6 +311,7 @@ export class Router {
this.location.go(path); this.location.go(path);
} }
} }
return Promise.resolve(true);
}) })
.then( .then(
() => { () => {
@ -335,7 +336,7 @@ class CanDeactivate {
} }
class GuardChecks { class GuardChecks {
private checks = []; private checks: Array<CanActivate|CanDeactivate> = [];
constructor( constructor(
private future: RouterStateSnapshot, private curr: RouterStateSnapshot, private future: RouterStateSnapshot, private curr: RouterStateSnapshot,
private injector: Injector) {} private injector: Injector) {}
@ -368,7 +369,9 @@ class GuardChecks {
this.traverseRoutes(c, prevChildren[c.value.outlet], outletMap); this.traverseRoutes(c, prevChildren[c.value.outlet], outletMap);
delete prevChildren[c.value.outlet]; delete prevChildren[c.value.outlet];
}); });
forEach(prevChildren, (v, k) => this.deactivateOutletAndItChildren(v, outletMap._outlets[k])); forEach(
prevChildren,
(v: any, k: string) => this.deactivateOutletAndItChildren(v, outletMap._outlets[k]));
} }
traverseRoutes( traverseRoutes(
@ -392,7 +395,7 @@ class GuardChecks {
private deactivateOutletAndItChildren(route: ActivatedRouteSnapshot, outlet: RouterOutlet): void { private deactivateOutletAndItChildren(route: ActivatedRouteSnapshot, outlet: RouterOutlet): void {
if (outlet && outlet.isActivated) { if (outlet && outlet.isActivated) {
forEach(outlet.outletMap._outlets, (v, k) => { forEach(outlet.outletMap._outlets, (v: RouterOutlet) => {
if (v.isActivated) { if (v.isActivated) {
this.deactivateOutletAndItChildren(v.activatedRoute.snapshot, v); this.deactivateOutletAndItChildren(v.activatedRoute.snapshot, v);
} }
@ -461,7 +464,9 @@ class ActivateRoutes {
this.activateRoutes(c, prevChildren[c.value.outlet], outletMap); this.activateRoutes(c, prevChildren[c.value.outlet], outletMap);
delete prevChildren[c.value.outlet]; delete prevChildren[c.value.outlet];
}); });
forEach(prevChildren, (v, k) => this.deactivateOutletAndItChildren(outletMap._outlets[k])); forEach(
prevChildren,
(v: any, k: string) => this.deactivateOutletAndItChildren(outletMap._outlets[k]));
} }
activateRoutes( activateRoutes(
@ -495,7 +500,8 @@ class ActivateRoutes {
private deactivateOutletAndItChildren(outlet: RouterOutlet): void { private deactivateOutletAndItChildren(outlet: RouterOutlet): void {
if (outlet && outlet.isActivated) { if (outlet && outlet.isActivated) {
forEach(outlet.outletMap._outlets, (v, k) => this.deactivateOutletAndItChildren(v)); forEach(
outlet.outletMap._outlets, (v: RouterOutlet) => this.deactivateOutletAndItChildren(v));
outlet.deactivate(); outlet.deactivate();
} }
} }
@ -512,7 +518,7 @@ function pushQueryParamsAndFragment(state: RouterState): void {
} }
function nodeChildrenAsMap(node: TreeNode<any>) { function nodeChildrenAsMap(node: TreeNode<any>) {
return node ? node.children.reduce((m, c) => { return node ? node.children.reduce((m: any, c: TreeNode<any>) => {
m[c.value.outlet] = c; m[c.value.outlet] = c;
return m; return m;
}, {}) : {}; }, {}) : {};

View File

@ -43,8 +43,8 @@ export function serializePaths(segment: UrlSegment): string {
function serializeSegment(segment: UrlSegment, root: boolean): string { function serializeSegment(segment: UrlSegment, root: boolean): string {
if (segment.children[PRIMARY_OUTLET] && root) { if (segment.children[PRIMARY_OUTLET] && root) {
const primary = serializeSegment(segment.children[PRIMARY_OUTLET], false); const primary = serializeSegment(segment.children[PRIMARY_OUTLET], false);
const children = []; const children: string[] = [];
forEach(segment.children, (v, k) => { forEach(segment.children, (v: UrlSegment, k: string) => {
if (k !== PRIMARY_OUTLET) { if (k !== PRIMARY_OUTLET) {
children.push(`${k}:${serializeSegment(v, false)}`); children.push(`${k}:${serializeSegment(v, false)}`);
} }
@ -56,7 +56,7 @@ function serializeSegment(segment: UrlSegment, root: boolean): string {
} }
} else if (segment.children[PRIMARY_OUTLET] && !root) { } else if (segment.children[PRIMARY_OUTLET] && !root) {
const children = [serializeSegment(segment.children[PRIMARY_OUTLET], false)]; const children = [serializeSegment(segment.children[PRIMARY_OUTLET], false)];
forEach(segment.children, (v, k) => { forEach(segment.children, (v: UrlSegment, k: string) => {
if (k !== PRIMARY_OUTLET) { if (k !== PRIMARY_OUTLET) {
children.push(`${k}:${serializeSegment(v, false)}`); children.push(`${k}:${serializeSegment(v, false)}`);
} }
@ -71,15 +71,15 @@ function serializeChildren(segment: UrlSegment) {
if (segment.children[PRIMARY_OUTLET]) { if (segment.children[PRIMARY_OUTLET]) {
const primary = serializePaths(segment.children[PRIMARY_OUTLET]); const primary = serializePaths(segment.children[PRIMARY_OUTLET]);
const secondary = []; const secondary: string[] = [];
forEach(segment.children, (v, k) => { forEach(segment.children, (v: UrlSegment, k: string) => {
if (k !== PRIMARY_OUTLET) { if (k !== PRIMARY_OUTLET) {
secondary.push(`${k}:${serializePaths(v)}${serializeChildren(v)}`); secondary.push(`${k}:${serializePaths(v)}${serializeChildren(v)}`);
} }
}); });
const secondaryStr = secondary.length > 0 ? `(${secondary.join('//')})` : ''; const secondaryStr = secondary.length > 0 ? `(${secondary.join('//')})` : '';
const primaryChildren = serializeChildren(segment.children[PRIMARY_OUTLET]); const primaryChildren = serializeChildren(segment.children[PRIMARY_OUTLET]);
const primaryChildrenStr = primaryChildren ? `/${primaryChildren}` : ''; const primaryChildrenStr: string = primaryChildren ? `/${primaryChildren}` : '';
return `${primary}${secondaryStr}${primaryChildrenStr}`; return `${primary}${secondaryStr}${primaryChildrenStr}`;
} else { } else {
return ''; return '';
@ -103,7 +103,7 @@ class Pair<A, B> {
constructor(public first: A, public second: B) {} constructor(public first: A, public second: B) {}
} }
function pairs<T>(obj: {[key: string]: T}): Pair<string, T>[] { function pairs<T>(obj: {[key: string]: T}): Pair<string, T>[] {
const res = []; const res: Pair<string, T>[] = [];
for (let prop in obj) { for (let prop in obj) {
if (obj.hasOwnProperty(prop)) { if (obj.hasOwnProperty(prop)) {
res.push(new Pair<string, T>(prop, obj[prop])); res.push(new Pair<string, T>(prop, obj[prop]));
@ -260,7 +260,7 @@ class UrlParser {
while (!this.peekStartsWith(')') && this.remaining.length > 0) { while (!this.peekStartsWith(')') && this.remaining.length > 0) {
let path = matchPathWithParams(this.remaining); let path = matchPathWithParams(this.remaining);
let outletName; let outletName: string;
if (path.indexOf(':') > -1) { if (path.indexOf(':') > -1) {
outletName = path.substr(0, path.indexOf(':')); outletName = path.substr(0, path.indexOf(':'));
this.capture(outletName); this.capture(outletName);

View File

@ -71,7 +71,7 @@ export class UrlSegment {
public parent: UrlSegment = null; public parent: UrlSegment = null;
constructor( constructor(
public pathsWithParams: UrlPathWithParams[], public children: {[key: string]: UrlSegment}) { public pathsWithParams: UrlPathWithParams[], public children: {[key: string]: UrlSegment}) {
forEach(children, (v, k) => v.parent = this); forEach(children, (v: any, k: any) => v.parent = this);
} }
toString(): string { return serializePaths(this); } toString(): string { return serializePaths(this); }
@ -102,12 +102,12 @@ export function equalPath(a: UrlPathWithParams[], b: UrlPathWithParams[]): boole
export function mapChildren(segment: UrlSegment, fn: (v: UrlSegment, k: string) => UrlSegment): export function mapChildren(segment: UrlSegment, fn: (v: UrlSegment, k: string) => UrlSegment):
{[name: string]: UrlSegment} { {[name: string]: UrlSegment} {
const newChildren: {[name: string]: UrlSegment} = {}; const newChildren: {[name: string]: UrlSegment} = {};
forEach(segment.children, (child, childOutlet) => { forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
if (childOutlet === PRIMARY_OUTLET) { if (childOutlet === PRIMARY_OUTLET) {
newChildren[childOutlet] = fn(child, childOutlet); newChildren[childOutlet] = fn(child, childOutlet);
} }
}); });
forEach(segment.children, (child, childOutlet) => { forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
if (childOutlet !== PRIMARY_OUTLET) { if (childOutlet !== PRIMARY_OUTLET) {
newChildren[childOutlet] = fn(child, childOutlet); newChildren[childOutlet] = fn(child, childOutlet);
} }
@ -117,13 +117,13 @@ export function mapChildren(segment: UrlSegment, fn: (v: UrlSegment, k: string)
export function mapChildrenIntoArray<T>( export function mapChildrenIntoArray<T>(
segment: UrlSegment, fn: (v: UrlSegment, k: string) => T[]): T[] { segment: UrlSegment, fn: (v: UrlSegment, k: string) => T[]): T[] {
let res = []; let res: T[] = [];
forEach(segment.children, (child, childOutlet) => { forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
if (childOutlet === PRIMARY_OUTLET) { if (childOutlet === PRIMARY_OUTLET) {
res = res.concat(fn(child, childOutlet)); res = res.concat(fn(child, childOutlet));
} }
}); });
forEach(segment.children, (child, childOutlet) => { forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
if (childOutlet !== PRIMARY_OUTLET) { if (childOutlet !== PRIMARY_OUTLET) {
res = res.concat(fn(child, childOutlet)); res = res.concat(fn(child, childOutlet));
} }

View File

@ -1,11 +1,11 @@
export function shallowEqual(a: {[x: string]: any}, b: {[x: string]: any}): boolean { export function shallowEqual(a: {[x: string]: any}, b: {[x: string]: any}): boolean {
var k1 = Object.keys(a); const k1 = Object.keys(a);
var k2 = Object.keys(b); const k2 = Object.keys(b);
if (k1.length != k2.length) { if (k1.length != k2.length) {
return false; return false;
} }
var key; let key: string;
for (var i = 0; i < k1.length; i++) { for (let i = 0; i < k1.length; i++) {
key = k1[i]; key = k1[i];
if (a[key] !== b[key]) { if (a[key] !== b[key]) {
return false; return false;
@ -15,7 +15,7 @@ export function shallowEqual(a: {[x: string]: any}, b: {[x: string]: any}): bool
} }
export function flatten<T>(a: T[][]): T[] { export function flatten<T>(a: T[][]): T[] {
const target = []; const target: T[] = [];
for (let i = 0; i < a.length; ++i) { for (let i = 0; i < a.length; ++i) {
for (let j = 0; j < a[i].length; ++j) { for (let j = 0; j < a[i].length; ++j) {
target.push(a[i][j]); target.push(a[i][j]);

View File

@ -8,7 +8,7 @@ describe('applyRedirects', () => {
it("should return the same url tree when no redirects", () => { it("should return the same url tree when no redirects", () => {
checkRedirect([ checkRedirect([
{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]} {path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}
], "/a/b", t => { ], "/a/b", (t:UrlTree) => {
compareTrees(t, tree('/a/b')); compareTrees(t, tree('/a/b'));
}); });
}); });
@ -17,7 +17,7 @@ describe('applyRedirects', () => {
checkRedirect([ checkRedirect([
{path: 'a/b', redirectTo: 'a/b/c'}, {path: 'a/b', redirectTo: 'a/b/c'},
{path: '**', component: ComponentC} {path: '**', component: ComponentC}
], "/a/b", t => { ], "/a/b", (t:UrlTree) => {
compareTrees(t, tree('/a/b/c')); compareTrees(t, tree('/a/b/c'));
}); });
}); });
@ -26,7 +26,7 @@ describe('applyRedirects', () => {
checkRedirect([ checkRedirect([
{path: 'a/:aid/b/:bid', redirectTo: 'newa/:aid/newb/:bid'}, {path: 'a/:aid/b/:bid', redirectTo: 'newa/:aid/newb/:bid'},
{path: '**', component: ComponentC} {path: '**', component: ComponentC}
], "/a/1/b/2", t => { ], "/a/1/b/2", (t:UrlTree) => {
compareTrees(t, tree('/newa/1/newb/2')); compareTrees(t, tree('/newa/1/newb/2'));
}); });
}); });
@ -43,7 +43,7 @@ describe('applyRedirects', () => {
checkRedirect([ checkRedirect([
{path: 'a/:id', redirectTo: 'd/a/:id/e'}, {path: 'a/:id', redirectTo: 'd/a/:id/e'},
{path: '**', component: ComponentC} {path: '**', component: ComponentC}
], "/a;p1=1/1;p2=2", t => { ], "/a;p1=1/1;p2=2", (t:UrlTree) => {
compareTrees(t, tree('/d/a;p1=1/1;p2=2/e')); compareTrees(t, tree('/d/a;p1=1/1;p2=2/e'));
}); });
}); });
@ -53,7 +53,7 @@ describe('applyRedirects', () => {
{path: 'a/:id', redirectTo: 'd/a/:id/e'}, {path: 'a/:id', redirectTo: 'd/a/:id/e'},
{path: 'c/d', component: ComponentA, outlet: 'aux'}, {path: 'c/d', component: ComponentA, outlet: 'aux'},
{path: '**', component: ComponentC} {path: '**', component: ComponentC}
], "/a/1(aux:c/d)", t => { ], "/a/1(aux:c/d)", (t:UrlTree) => {
compareTrees(t, tree('/d/a/1/e(aux:c/d)')); compareTrees(t, tree('/d/a/1/e(aux:c/d)'));
}); });
}); });
@ -63,7 +63,7 @@ describe('applyRedirects', () => {
{path: 'a/:id', component: ComponentA}, {path: 'a/:id', component: ComponentA},
{path: 'c/d', redirectTo: 'f/c/d/e', outlet: 'aux'}, {path: 'c/d', redirectTo: 'f/c/d/e', outlet: 'aux'},
{path: '**', component: ComponentC, outlet: 'aux'} {path: '**', component: ComponentC, outlet: 'aux'}
], "/a/1(aux:c/d)", t => { ], "/a/1(aux:c/d)", (t:UrlTree) => {
compareTrees(t, tree('/a/1(aux:f/c/d/e)')); compareTrees(t, tree('/a/1(aux:f/c/d/e)'));
}); });
}); });
@ -74,7 +74,7 @@ describe('applyRedirects', () => {
{path: 'b', component: ComponentB}, {path: 'b', component: ComponentB},
]}, ]},
{path: 'c', redirectTo: 'a'} {path: 'c', redirectTo: 'a'}
], "c/b", t => { ], "c/b", (t:UrlTree) => {
compareTrees(t, tree('a/b')); compareTrees(t, tree('a/b'));
}); });
}); });
@ -85,7 +85,7 @@ describe('applyRedirects', () => {
{path: 'b', component: ComponentB}, {path: 'b', component: ComponentB},
]}, ]},
{path: '', redirectTo: 'a'} {path: '', redirectTo: 'a'}
], "b", t => { ], "b", (t:UrlTree) => {
compareTrees(t, tree('a/b')); compareTrees(t, tree('a/b'));
}); });
}); });
@ -96,7 +96,7 @@ describe('applyRedirects', () => {
{path: 'b', component: ComponentB}, {path: 'b', component: ComponentB},
]}, ]},
{path: '', redirectTo: '/a/b'} {path: '', redirectTo: '/a/b'}
], "", t => { ], "", (t:UrlTree) => {
compareTrees(t, tree('a/b')); compareTrees(t, tree('a/b'));
}); });
}); });
@ -108,7 +108,7 @@ describe('applyRedirects', () => {
{path: '', redirectTo: 'b'} {path: '', redirectTo: 'b'}
]}, ]},
{path: '', redirectTo: 'a'} {path: '', redirectTo: 'a'}
], "", t => { ], "", (t:UrlTree) => {
compareTrees(t, tree('a/b')); compareTrees(t, tree('a/b'));
}); });
}); });
@ -120,7 +120,7 @@ describe('applyRedirects', () => {
{path: '', redirectTo: 'b'} {path: '', redirectTo: 'b'}
]}, ]},
{path: 'a', redirectTo: ''} {path: 'a', redirectTo: ''}
], "a", t => { ], "a", (t:UrlTree) => {
compareTrees(t, tree('b')); compareTrees(t, tree('b'));
}); });
}); });
@ -144,7 +144,7 @@ describe('applyRedirects', () => {
checkRedirect([ checkRedirect([
{path: '404', component: ComponentA}, {path: '404', component: ComponentA},
{path: '**', redirectTo: '/404'}, {path: '**', redirectTo: '/404'},
], "/a/1(aux:c/d)", t => { ], "/a/1(aux:c/d)", (t:UrlTree) => {
compareTrees(t, tree('/404')); compareTrees(t, tree('/404'));
}); });
}); });
@ -155,7 +155,7 @@ describe('applyRedirects', () => {
{path: 'b/:id', redirectTo: '/global/:id'} {path: 'b/:id', redirectTo: '/global/:id'}
]}, ]},
{path: '**', component: ComponentC} {path: '**', component: ComponentC}
], "/a/b/1", t => { ], "/a/b/1", (t:UrlTree) => {
compareTrees(t, tree('/global/1')); compareTrees(t, tree('/global/1'));
}); });
}); });

View File

@ -56,7 +56,7 @@ function advanceNode(node: TreeNode<ActivatedRoute>): void {
} }
function createState(config: RouterConfig, url: string): RouterStateSnapshot { function createState(config: RouterConfig, url: string): RouterStateSnapshot {
let res; let res: RouterStateSnapshot;
recognize(RootComponent, config, tree(url), url).forEach(s => res = s); recognize(RootComponent, config, tree(url), url).forEach(s => res = s);
return res; return res;
} }

View File

@ -1,7 +1,7 @@
import {DefaultUrlSerializer} from '../src/url_serializer'; import {DefaultUrlSerializer} from '../src/url_serializer';
import {UrlTree} from '../src/url_tree'; import {UrlTree} from '../src/url_tree';
import {Params, PRIMARY_OUTLET} from '../src/shared'; import {Params, PRIMARY_OUTLET} from '../src/shared';
import {ActivatedRouteSnapshot} from '../src/router_state'; import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state';
import {RouterConfig} from '../src/config'; import {RouterConfig} from '../src/config';
import {recognize} from '../src/recognize'; import {recognize} from '../src/recognize';
@ -11,7 +11,7 @@ describe('recognize', () => {
{ {
path: 'a', component: ComponentA path: 'a', component: ComponentA
} }
], "a", s => { ], "a", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.root, "", {}, RootComponent); checkActivatedRoute(s.root, "", {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
}); });
@ -22,7 +22,7 @@ describe('recognize', () => {
{ path: 'a', component: ComponentA }, { path: 'a', component: ComponentA },
{ path: 'b', component: ComponentB, outlet: 'left' }, { path: 'b', component: ComponentB, outlet: 'left' },
{ path: 'c', component: ComponentC, outlet: 'right' } { path: 'c', component: ComponentC, outlet: 'right' }
], "a(left:b//right:c)", s => { ], "a(left:b//right:c)", (s:RouterStateSnapshot) => {
const c = s.children(s.root); const c = s.children(s.root);
checkActivatedRoute(c[0], "a", {}, ComponentA); checkActivatedRoute(c[0], "a", {}, ComponentA);
checkActivatedRoute(c[1], "b", {}, ComponentB, 'left'); checkActivatedRoute(c[1], "b", {}, ComponentB, 'left');
@ -58,7 +58,7 @@ describe('recognize', () => {
{ path: '/a/b', component: ComponentA, children: [ { path: '/a/b', component: ComponentA, children: [
{path: 'c', component: ComponentC} {path: 'c', component: ComponentC}
] }, ] },
], url, "a/b/c").subscribe(s => { ], url, "a/b/c").subscribe((s:RouterStateSnapshot) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
@ -76,7 +76,7 @@ describe('recognize', () => {
checkRecognize([ checkRecognize([
{path: 'a', component: ComponentA, children: [{path: ':id', component: ComponentB}]}, {path: 'a', component: ComponentA, children: [{path: ':id', component: ComponentB}]},
{path: 'a/:id', component: ComponentC} {path: 'a/:id', component: ComponentC}
], "a/paramA", s => { ], "a/paramA", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.root, "", {}, RootComponent); checkActivatedRoute(s.root, "", {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "paramA", {id: 'paramA'}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "paramA", {id: 'paramA'}, ComponentB);
@ -85,7 +85,7 @@ describe('recognize', () => {
checkRecognize([ checkRecognize([
{path: 'a', component: ComponentA}, {path: 'a', component: ComponentA},
{path: 'a/:id', component: ComponentC} {path: 'a/:id', component: ComponentC}
], "a/paramA", s => { ], "a/paramA", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.root, "", {}, RootComponent); checkActivatedRoute(s.root, "", {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root), "a/paramA", {id: 'paramA'}, ComponentC); checkActivatedRoute(s.firstChild(s.root), "a/paramA", {id: 'paramA'}, ComponentC);
}); });
@ -96,7 +96,7 @@ describe('recognize', () => {
{ path: 'a', component: ComponentA }, { path: 'a', component: ComponentA },
{ path: 'b', component: ComponentB, outlet: 'left' }, { path: 'b', component: ComponentB, outlet: 'left' },
{ path: 'b', component: ComponentC, outlet: 'right' } { path: 'b', component: ComponentC, outlet: 'right' }
], "a(right:b)", s => { ], "a(right:b)", (s:RouterStateSnapshot) => {
const c = s.children(s.root); const c = s.children(s.root);
checkActivatedRoute(c[0], "a", {}, ComponentA); checkActivatedRoute(c[0], "a", {}, ComponentA);
checkActivatedRoute(c[1], "b", {}, ComponentC, 'right'); checkActivatedRoute(c[1], "b", {}, ComponentC, 'right');
@ -108,7 +108,7 @@ describe('recognize', () => {
{ path: 'a', component: ComponentA }, { path: 'a', component: ComponentA },
{ path: 'b', component: ComponentB, outlet: 'left' }, { path: 'b', component: ComponentB, outlet: 'left' },
{ path: 'c', component: ComponentC, outlet: 'right' } { path: 'c', component: ComponentC, outlet: 'right' }
], "a(left:b(right:c))", s => { ], "a(left:b(right:c))", (s:RouterStateSnapshot) => {
const c = s.children(s.root); const c = s.children(s.root);
checkActivatedRoute(c[0], "a", {}, ComponentA); checkActivatedRoute(c[0], "a", {}, ComponentA);
checkActivatedRoute(c[1], "b", {}, ComponentB, 'left'); checkActivatedRoute(c[1], "b", {}, ComponentB, 'left');
@ -122,7 +122,7 @@ describe('recognize', () => {
{ path: 'b', component: ComponentB }, { path: 'b', component: ComponentB },
{ path: 'c', component: ComponentC, outlet: 'left' } { path: 'c', component: ComponentC, outlet: 'left' }
] }, ] },
], "a/(b//left:c)", s => { ], "a/(b//left:c)", (s:RouterStateSnapshot) => {
const c = s.children(<any>s.firstChild(s.root)); const c = s.children(<any>s.firstChild(s.root));
checkActivatedRoute(c[0], "b", {}, ComponentB, PRIMARY_OUTLET); checkActivatedRoute(c[0], "b", {}, ComponentB, PRIMARY_OUTLET);
checkActivatedRoute(c[1], "c", {}, ComponentC, 'left'); checkActivatedRoute(c[1], "c", {}, ComponentC, 'left');
@ -134,7 +134,7 @@ describe('recognize', () => {
{ path: 'a', component: ComponentA }, { path: 'a', component: ComponentA },
{ path: 'c', component: ComponentC, outlet: 'c' }, { path: 'c', component: ComponentC, outlet: 'c' },
{ path: 'b', component: ComponentB, outlet: 'b' } { path: 'b', component: ComponentB, outlet: 'b' }
], "a(c:c//b:b)", s => { ], "a(c:c//b:b)", (s:RouterStateSnapshot) => {
const c = s.children(s.root); const c = s.children(s.root);
checkActivatedRoute(c[0], "a", {}, ComponentA); checkActivatedRoute(c[0], "a", {}, ComponentA);
checkActivatedRoute(c[1], "b", {}, ComponentB, 'b'); checkActivatedRoute(c[1], "b", {}, ComponentB, 'b');
@ -150,7 +150,7 @@ describe('recognize', () => {
] ]
}, },
{ path: 'c', component: ComponentC, outlet: 'left' } { path: 'c', component: ComponentC, outlet: 'left' }
], "a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)", s => { ], "a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)", (s:RouterStateSnapshot) => {
const c = s.children(s.root); const c = s.children(s.root);
checkActivatedRoute(c[0], "a", {a1: '11', a2: '22'}, ComponentA); checkActivatedRoute(c[0], "a", {a1: '11', a2: '22'}, ComponentA);
checkActivatedRoute(s.firstChild(<any>c[0]), "b", {b1: '111', b2: '222'}, ComponentB); checkActivatedRoute(s.firstChild(<any>c[0]), "b", {b1: '111', b2: '222'}, ComponentB);
@ -162,7 +162,7 @@ describe('recognize', () => {
it("should support root index routes", () => { it("should support root index routes", () => {
checkRecognize([ checkRecognize([
{index: true, component: ComponentA} {index: true, component: ComponentA}
], "", s => { ], "", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
}); });
}); });
@ -170,7 +170,7 @@ describe('recognize', () => {
it("should support nested root index routes", () => { it("should support nested root index routes", () => {
checkRecognize([ checkRecognize([
{index: true, component: ComponentA, children: [{index: true, component: ComponentB}]} {index: true, component: ComponentA, children: [{index: true, component: ComponentB}]}
], "", s => { ], "", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
}); });
@ -181,7 +181,7 @@ describe('recognize', () => {
{path: 'a', component: ComponentA, children: [ {path: 'a', component: ComponentA, children: [
{index: true, component: ComponentB} {index: true, component: ComponentB}
]} ]}
], "a", s => { ], "a", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
}); });
@ -197,7 +197,7 @@ describe('recognize', () => {
} }
] ]
} }
], "c/10", s => { ], "c/10", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
checkActivatedRoute( checkActivatedRoute(
@ -208,7 +208,7 @@ describe('recognize', () => {
xit("should pass parameters to every nested index route (case with non-index route)", () => { xit("should pass parameters to every nested index route (case with non-index route)", () => {
checkRecognize([ checkRecognize([
{path: 'a', component: ComponentA, children: [{index: true, component: ComponentB}]} {path: 'a', component: ComponentA, children: [{index: true, component: ComponentB}]}
], "/a;a=1", s => { ], "/a;a=1", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB);
}); });
@ -219,7 +219,7 @@ describe('recognize', () => {
it("should support root index routes", () => { it("should support root index routes", () => {
recognize(RootComponent, [ recognize(RootComponent, [
{path: '', component: ComponentA} {path: '', component: ComponentA}
], tree(""), "").forEach(s => { ], tree(""), "").forEach((s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
}); });
}); });
@ -227,7 +227,7 @@ describe('recognize', () => {
it("should support nested root index routes", () => { it("should support nested root index routes", () => {
recognize(RootComponent, [ recognize(RootComponent, [
{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]} {path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}
], tree(""), "").forEach(s => { ], tree(""), "").forEach((s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
}); });
@ -237,7 +237,7 @@ describe('recognize', () => {
const url = tree(""); const url = tree("");
recognize(RootComponent, [ recognize(RootComponent, [
{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]} {path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}
], url, "").forEach(s => { ], url, "").forEach((s:RouterStateSnapshot) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
@ -256,7 +256,7 @@ describe('recognize', () => {
{path: 'a', component: ComponentA, children: [ {path: 'a', component: ComponentA, children: [
{path: '', component: ComponentB} {path: '', component: ComponentB}
]} ]}
], tree("a"), "a").forEach(s => { ], tree("a"), "a").forEach((s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
}); });
@ -272,7 +272,7 @@ describe('recognize', () => {
} }
] ]
} }
], tree("c/10"), "c/10").forEach(s => { ], tree("c/10"), "c/10").forEach((s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
checkActivatedRoute( checkActivatedRoute(
@ -283,7 +283,7 @@ describe('recognize', () => {
xit("should pass parameters to every nested index route (case with non-index route)", () => { xit("should pass parameters to every nested index route (case with non-index route)", () => {
recognize(RootComponent, [ recognize(RootComponent, [
{path: 'a', component: ComponentA, children: [{path: '', component: ComponentB}]} {path: 'a', component: ComponentA, children: [{path: '', component: ComponentB}]}
], tree("/a;a=1"), "/a;a=1").forEach(s => { ], tree("/a;a=1"), "/a;a=1").forEach((s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB); checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB);
}); });
@ -294,7 +294,7 @@ describe('recognize', () => {
it("should support simple wildcards", () => { it("should support simple wildcards", () => {
checkRecognize([ checkRecognize([
{path: '**', component: ComponentA} {path: '**', component: ComponentA}
], "a/b/c/d;a1=11", s => { ], "a/b/c/d;a1=11", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "a/b/c/d", {a1:'11'}, ComponentA); checkActivatedRoute(s.firstChild(s.root), "a/b/c/d", {a1:'11'}, ComponentA);
}); });
}); });
@ -303,7 +303,7 @@ describe('recognize', () => {
describe("query parameters", () => { describe("query parameters", () => {
it("should support query params", () => { it("should support query params", () => {
const config = [{path: 'a', component: ComponentA}]; const config = [{path: 'a', component: ComponentA}];
checkRecognize(config, "a?q=11", s => { checkRecognize(config, "a?q=11", (s:RouterStateSnapshot) => {
expect(s.queryParams).toEqual({q: '11'}); expect(s.queryParams).toEqual({q: '11'});
}); });
}); });
@ -312,7 +312,7 @@ describe('recognize', () => {
describe("fragment", () => { describe("fragment", () => {
it("should support fragment", () => { it("should support fragment", () => {
const config = [{path: 'a', component: ComponentA}]; const config = [{path: 'a', component: ComponentA}];
checkRecognize(config, "a#f1", s => { checkRecognize(config, "a#f1", (s:RouterStateSnapshot) => {
expect(s.fragment).toEqual("f1"); expect(s.fragment).toEqual("f1");
}); });
}); });
@ -324,7 +324,7 @@ describe('recognize', () => {
{ path: 'a', component: ComponentA }, { path: 'a', component: ComponentA },
{ path: 'b', component: ComponentB, outlet: 'aux' }, { path: 'b', component: ComponentB, outlet: 'aux' },
{ path: 'c', component: ComponentC, outlet: 'aux' } { path: 'c', component: ComponentC, outlet: 'aux' }
], tree("a(aux:b//aux:c)"), "a(aux:b//aux:c)").subscribe((_) => {}, s => { ], tree("a(aux:b//aux:c)"), "a(aux:b//aux:c)").subscribe((_) => {}, (s:RouterStateSnapshot) => {
expect(s.toString()).toContain("Two segments cannot have the same outlet name: 'aux:b' and 'aux:c'."); expect(s.toString()).toContain("Two segments cannot have the same outlet name: 'aux:b' and 'aux:c'.");
}); });
}); });
@ -332,7 +332,7 @@ describe('recognize', () => {
it("should error when no matching routes", () => { it("should error when no matching routes", () => {
recognize(RootComponent, [ recognize(RootComponent, [
{ path: 'a', component: ComponentA } { path: 'a', component: ComponentA }
], tree("invalid"), "invalid").subscribe((_) => {}, s => { ], tree("invalid"), "invalid").subscribe((_) => {}, (s:RouterStateSnapshot) => {
expect(s.toString()).toContain("Cannot match any routes"); expect(s.toString()).toContain("Cannot match any routes");
}); });
}); });
@ -340,7 +340,7 @@ describe('recognize', () => {
it("should error when no matching routes (too short)", () => { it("should error when no matching routes (too short)", () => {
recognize(RootComponent, [ recognize(RootComponent, [
{ path: 'a/:id', component: ComponentA } { path: 'a/:id', component: ComponentA }
], tree("a"), "a").subscribe((_) => {}, s => { ], tree("a"), "a").subscribe((_) => {}, (s:RouterStateSnapshot) => {
expect(s.toString()).toContain("Cannot match any routes"); expect(s.toString()).toContain("Cannot match any routes");
}); });
}); });

View File

@ -16,6 +16,7 @@ import {
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
import { ComponentResolver } from '@angular/core'; import { ComponentResolver } from '@angular/core';
import { Location } from '@angular/common';
import { SpyLocation } from '@angular/common/testing'; import { SpyLocation } from '@angular/common/testing';
import { UrlSerializer, DefaultUrlSerializer, RouterOutletMap, Router, ActivatedRoute, ROUTER_DIRECTIVES, Params, import { UrlSerializer, DefaultUrlSerializer, RouterOutletMap, Router, ActivatedRoute, ROUTER_DIRECTIVES, Params,
RouterStateSnapshot, ActivatedRouteSnapshot, CanActivate, CanDeactivate, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError, RoutesRecognized, RouterConfig } from '../src/index'; RouterStateSnapshot, ActivatedRouteSnapshot, CanActivate, CanDeactivate, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError, RoutesRecognized, RouterConfig } from '../src/index';
@ -37,19 +38,19 @@ describe("Integration", () => {
{provide: Location, useClass: SpyLocation}, {provide: Location, useClass: SpyLocation},
{ {
provide: Router, provide: Router,
useFactory: (resolver, urlSerializer, outletMap, location, injector) => { useFactory: (resolver:ComponentResolver, urlSerializer:UrlSerializer, outletMap:RouterOutletMap, location:Location, injector:Injector) => {
const r = new Router(RootCmp, resolver, urlSerializer, outletMap, location, injector, config); const r = new Router(RootCmp, resolver, urlSerializer, outletMap, location, injector, config);
r.initialNavigation(); r.initialNavigation();
return r; return r;
}, },
deps: [ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector] deps: [ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector]
}, },
{provide: ActivatedRoute, useFactory: (r) => r.routerState.root, deps: [Router]}, {provide: ActivatedRoute, useFactory: (r:Router) => r.routerState.root, deps: [Router]},
]; ];
}); });
it('should navigate with a provided config', it('should navigate with a provided config',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -61,7 +62,7 @@ describe("Integration", () => {
it('should update location when navigating', it('should update location when navigating',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -80,7 +81,7 @@ describe("Integration", () => {
}))); })));
it('should navigate back and forward', it('should navigate back and forward',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -109,7 +110,7 @@ describe("Integration", () => {
}))); })));
it('should navigate when locations changes', it('should navigate when locations changes',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -122,14 +123,14 @@ describe("Integration", () => {
router.navigateByUrl('/team/22/user/victor'); router.navigateByUrl('/team/22/user/victor');
advance(fixture); advance(fixture);
location.simulateHashChange("/team/22/user/fedor"); (<any>location).simulateHashChange("/team/22/user/fedor");
advance(fixture); advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { user fedor, right: }'); expect(fixture.debugElement.nativeElement).toHaveText('team 22 { user fedor, right: }');
}))); })));
it('should update the location when the matched route does not change', it('should update the location when the matched route does not change',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -149,7 +150,7 @@ describe("Integration", () => {
}))); })));
it('should support secondary routes', it('should support secondary routes',
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -168,7 +169,7 @@ describe("Integration", () => {
}))); })));
it('should deactivate outlets', it('should deactivate outlets',
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -189,7 +190,7 @@ describe("Integration", () => {
}))); })));
it('should deactivate nested outlets', it('should deactivate nested outlets',
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -211,7 +212,7 @@ describe("Integration", () => {
}))); })));
it('should set query params and fragment', it('should set query params and fragment',
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -229,7 +230,7 @@ describe("Integration", () => {
}))); })));
it('should push params only when they change', it('should push params only when they change',
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -255,7 +256,7 @@ describe("Integration", () => {
}))); })));
it('should work when navigating to /', it('should work when navigating to /',
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -276,7 +277,7 @@ describe("Integration", () => {
}))); })));
it("should cancel in-flight navigations", it("should cancel in-flight navigations",
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -284,7 +285,7 @@ describe("Integration", () => {
{ path: '/user/:name', component: UserCmp } { path: '/user/:name', component: UserCmp }
]); ]);
const recordedEvents = []; const recordedEvents:any = [];
router.events.forEach(e => recordedEvents.push(e)); router.events.forEach(e => recordedEvents.push(e));
router.navigateByUrl('/user/init'); router.navigateByUrl('/user/init');
@ -292,7 +293,7 @@ describe("Integration", () => {
const user = fixture.debugElement.children[1].componentInstance; const user = fixture.debugElement.children[1].componentInstance;
let r1, r2; let r1:any, r2:any;
router.navigateByUrl('/user/victor').then(_ => r1 = _); router.navigateByUrl('/user/victor').then(_ => r1 = _);
router.navigateByUrl('/user/fedor').then(_ => r2 = _); router.navigateByUrl('/user/fedor').then(_ => r2 = _);
advance(fixture); advance(fixture);
@ -318,7 +319,7 @@ describe("Integration", () => {
}))); })));
it("should handle failed navigations gracefully", it("should handle failed navigations gracefully",
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -326,10 +327,10 @@ describe("Integration", () => {
{ path: '/user/:name', component: UserCmp } { path: '/user/:name', component: UserCmp }
]); ]);
const recordedEvents = []; const recordedEvents:any = [];
router.events.forEach(e => recordedEvents.push(e)); router.events.forEach(e => recordedEvents.push(e));
let e; let e:any;
router.navigateByUrl('/invalid').catch(_ => e = _); router.navigateByUrl('/invalid').catch(_ => e = _);
advance(fixture); advance(fixture);
expect(e.message).toContain("Cannot match any routes"); expect(e.message).toContain("Cannot match any routes");
@ -350,7 +351,7 @@ describe("Integration", () => {
}))); })));
it('should replace state when path is equal to current path', it('should replace state when path is equal to current path',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -377,7 +378,7 @@ describe("Integration", () => {
describe("router links", () => { describe("router links", () => {
it("should support string router links", it("should support string router links",
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -401,7 +402,7 @@ describe("Integration", () => {
}))); })));
it("should support absolute router links", it("should support absolute router links",
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -425,7 +426,7 @@ describe("Integration", () => {
}))); })));
it("should support relative router links", it("should support relative router links",
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -451,7 +452,7 @@ describe("Integration", () => {
}))); })));
it("should support top-level link", it("should support top-level link",
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
let fixture = tcb.createFakeAsync(AbsoluteLinkCmp); let fixture = tcb.createFakeAsync(AbsoluteLinkCmp);
advance(fixture); advance(fixture);
@ -459,7 +460,7 @@ describe("Integration", () => {
}))); })));
it("should support query params and fragments", it("should support query params and fragments",
fakeAsync(inject([Router, Location, TestComponentBuilder], (router, location, tcb) => { fakeAsync(inject([Router, Location, TestComponentBuilder], (router:Router, location:Location, tcb:TestComponentBuilder) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -486,7 +487,7 @@ describe("Integration", () => {
}); });
describe("redirects", () => { describe("redirects", () => {
it("should work", fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { it("should work", fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -506,11 +507,11 @@ describe("Integration", () => {
describe("CanActivate", () => { describe("CanActivate", () => {
describe("should not activate a route when CanActivate returns false", () => { describe("should not activate a route when CanActivate returns false", () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
{provide: 'alwaysFalse', useValue: (a, b) => false} {provide: 'alwaysFalse', useValue: (a:any, b:any) => false}
]); ]);
it('works', it('works',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -531,7 +532,7 @@ describe("Integration", () => {
]); ]);
it('works', it('works',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -556,7 +557,7 @@ describe("Integration", () => {
beforeEachProviders(() => [AlwaysTrue]); beforeEachProviders(() => [AlwaysTrue]);
it('works', it('works',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -579,7 +580,7 @@ describe("Integration", () => {
]); ]);
it('works', it('works',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -607,7 +608,7 @@ describe("Integration", () => {
it('works', it('works',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -632,7 +633,7 @@ describe("Integration", () => {
}))); })));
it('works with a nested route', it('works with a nested route',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -671,7 +672,7 @@ describe("Integration", () => {
beforeEachProviders(() => [AlwaysTrue]); beforeEachProviders(() => [AlwaysTrue]);
it('works', it('works',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -698,7 +699,7 @@ describe("Integration", () => {
]); ]);
it('works', it('works',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -719,7 +720,7 @@ describe("Integration", () => {
describe("routerActiveLink", () => { describe("routerActiveLink", () => {
it("should set the class when the link is active (exact = true)", it("should set the class when the link is active (exact = true)",
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -746,7 +747,7 @@ describe("Integration", () => {
}))); })));
it("should set the class on a parent element when the link is active (exact = true)", it("should set the class on a parent element when the link is active (exact = true)",
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);
@ -773,7 +774,7 @@ describe("Integration", () => {
}))); })));
it("should set the class when the link is active (exact = false)", it("should set the class when the link is active (exact = false)",
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => { fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
const fixture = tcb.createFakeAsync(RootCmp); const fixture = tcb.createFakeAsync(RootCmp);
advance(fixture); advance(fixture);

View File

@ -5,7 +5,8 @@
"noEmitOnError": false, "noEmitOnError": false,
"module": "commonjs", "module": "commonjs",
"target": "es5", "target": "es5",
"noImplicitAny": false, "noImplicitAny": true,
"noImplicitReturns": true,
"outDir": "dist", "outDir": "dist",
"rootDir": ".", "rootDir": ".",
"inlineSourceMap": true, "inlineSourceMap": true,

View File

@ -4,7 +4,8 @@
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"module": "commonjs", "module": "commonjs",
"target": "es5", "target": "es5",
"noImplicitAny": false, "noImplicitAny": true,
"noImplicitReturns": true,
"outDir": "dist", "outDir": "dist",
"rootDir": "src", "rootDir": "src",
"inlineSourceMap": true, "inlineSourceMap": true,

View File

@ -3,7 +3,8 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"target": "es6", "target": "es6",
"noImplicitAny": false, "noImplicitAny": true,
"noImplicitReturns": true,
"outDir": "dist/esm", "outDir": "dist/esm",
"rootDir": "src", "rootDir": "src",
"inlineSourceMap": true, "inlineSourceMap": true,