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}`; +}