Skip to content

Commit 84a57b7

Browse files
committed
refactor(ivy): create lazy route keys that are similar to ngtools lazy routes
This will make it easier to retrieve routes for specific entry points in `listLazyRoutes()` (which is necessary for CLI integration but not yet implemented).
1 parent 0035ca1 commit 84a57b7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/compiler-cli/src/ngtsc/routing/src/analyzer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {ModuleResolver} from '../../imports';
1212
import {PartialEvaluator} from '../../partial_evaluator';
1313

1414
import {scanForRouteEntryPoints} from './lazy';
15-
import {RouterEntryPointManager} from './route';
15+
import {RouterEntryPointManager, entryPointKeyFor} from './route';
1616

1717
export interface NgModuleRawRouteData {
1818
sourceFile: ts.SourceFile;
@@ -38,9 +38,9 @@ export class NgModuleRouteAnalyzer {
3838

3939
add(sourceFile: ts.SourceFile, moduleName: string, imports: ts.Expression|null,
4040
exports: ts.Expression|null, providers: ts.Expression|null): void {
41-
const key = `${sourceFile.fileName}#${moduleName}`;
41+
const key = entryPointKeyFor(sourceFile.fileName, moduleName);
4242
if (this.modules.has(key)) {
43-
throw new Error(`Double route analyzing ${key}`);
43+
throw new Error(`Double route analyzing for '${key}'.`);
4444
}
4545
this.modules.set(
4646
key, {

packages/compiler-cli/src/ngtsc/routing/src/route.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ export class RouterEntryPointManager {
4444
}
4545

4646
fromNgModule(sf: ts.SourceFile, moduleName: string): RouterEntryPoint {
47-
const absoluteFile = sf.fileName;
48-
const key = `${absoluteFile}#${moduleName}`;
47+
const key = entryPointKeyFor(sf.fileName, moduleName);
4948
if (!this.map.has(key)) {
50-
this.map.set(key, new RouterEntryPointImpl(absoluteFile, moduleName));
49+
this.map.set(key, new RouterEntryPointImpl(sf.fileName, moduleName));
5150
}
5251
return this.map.get(key) !;
5352
}
5453
}
54+
55+
export function entryPointKeyFor(filePath: string, moduleName: string): string {
56+
// Drop the extension to be compatible with how cli calls `listLazyRoutes(entryRoute)`.
57+
return `${filePath.replace(/\.tsx?$/i, '')}#${moduleName}`;
58+
}

0 commit comments

Comments
 (0)