From f358188ec165e6dc716cca9291b1a797e0e2af9d Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 30 Jan 2019 11:47:53 +0200 Subject: [PATCH] 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 --- .../compiler-cli/src/ngtsc/routing/src/analyzer.ts | 6 +++--- packages/compiler-cli/src/ngtsc/routing/src/route.ts | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/routing/src/analyzer.ts b/packages/compiler-cli/src/ngtsc/routing/src/analyzer.ts index 5757055788..4443affdd2 100644 --- a/packages/compiler-cli/src/ngtsc/routing/src/analyzer.ts +++ b/packages/compiler-cli/src/ngtsc/routing/src/analyzer.ts @@ -12,7 +12,7 @@ import {ModuleResolver} from '../../imports'; import {PartialEvaluator} from '../../partial_evaluator'; import {scanForRouteEntryPoints} from './lazy'; -import {RouterEntryPointManager} from './route'; +import {RouterEntryPointManager, entryPointKeyFor} from './route'; export interface NgModuleRawRouteData { sourceFile: ts.SourceFile; @@ -38,9 +38,9 @@ export class NgModuleRouteAnalyzer { add(sourceFile: ts.SourceFile, moduleName: string, imports: ts.Expression|null, 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)) { - throw new Error(`Double route analyzing ${key}`); + throw new Error(`Double route analyzing for '${key}'.`); } this.modules.set( key, { diff --git a/packages/compiler-cli/src/ngtsc/routing/src/route.ts b/packages/compiler-cli/src/ngtsc/routing/src/route.ts index 8218fe4eb2..8c8a5bb7af 100644 --- a/packages/compiler-cli/src/ngtsc/routing/src/route.ts +++ b/packages/compiler-cli/src/ngtsc/routing/src/route.ts @@ -47,11 +47,15 @@ export class RouterEntryPointManager { } fromNgModule(sf: ts.SourceFile, moduleName: string): RouterEntryPoint { - const absoluteFile = sf.fileName; - const key = `${absoluteFile}#${moduleName}`; + const key = entryPointKeyFor(sf.fileName, moduleName); 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) !; } } + +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}`; +}