refactor(ivy): create lazy route keys that are similar to ngtools lazy routes (#28542)

This will make it easier to retrieve routes for specific entry points in
`listLazyRoutes()` (which is necessary for CLI integration but not yet
implemented).

PR Close #28542
This commit is contained in:
George Kalpakas 2019-01-30 11:47:53 +02:00 committed by Miško Hevery
parent 5db3a6b198
commit f358188ec1
2 changed files with 10 additions and 6 deletions

View File

@ -12,7 +12,7 @@ import {ModuleResolver} from '../../imports';
import {PartialEvaluator} from '../../partial_evaluator'; import {PartialEvaluator} from '../../partial_evaluator';
import {scanForRouteEntryPoints} from './lazy'; import {scanForRouteEntryPoints} from './lazy';
import {RouterEntryPointManager} from './route'; import {RouterEntryPointManager, entryPointKeyFor} from './route';
export interface NgModuleRawRouteData { export interface NgModuleRawRouteData {
sourceFile: ts.SourceFile; sourceFile: ts.SourceFile;
@ -38,9 +38,9 @@ export class NgModuleRouteAnalyzer {
add(sourceFile: ts.SourceFile, moduleName: string, imports: ts.Expression|null, add(sourceFile: ts.SourceFile, moduleName: string, imports: ts.Expression|null,
exports: ts.Expression|null, providers: ts.Expression|null): void { exports: ts.Expression|null, providers: ts.Expression|null): void {
const key = `${sourceFile.fileName}#${moduleName}`; const key = entryPointKeyFor(sourceFile.fileName, moduleName);
if (this.modules.has(key)) { if (this.modules.has(key)) {
throw new Error(`Double route analyzing ${key}`); throw new Error(`Double route analyzing for '${key}'.`);
} }
this.modules.set( this.modules.set(
key, { key, {

View File

@ -47,11 +47,15 @@ export class RouterEntryPointManager {
} }
fromNgModule(sf: ts.SourceFile, moduleName: string): RouterEntryPoint { fromNgModule(sf: ts.SourceFile, moduleName: string): RouterEntryPoint {
const absoluteFile = sf.fileName; const key = entryPointKeyFor(sf.fileName, moduleName);
const key = `${absoluteFile}#${moduleName}`;
if (!this.map.has(key)) { if (!this.map.has(key)) {
this.map.set(key, new RouterEntryPointImpl(absoluteFile, moduleName)); this.map.set(key, new RouterEntryPointImpl(sf.fileName, moduleName));
} }
return this.map.get(key) !; return this.map.get(key) !;
} }
} }
export function entryPointKeyFor(filePath: string, moduleName: string): string {
// Drop the extension to be compatible with how cli calls `listLazyRoutes(entryRoute)`.
return `${filePath.replace(/\.tsx?$/i, '')}#${moduleName}`;
}