Skip to content

Commit aa8f538

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 d05168e commit aa8f538

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -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 = this.entryPointManager.keyFor(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
@@ -30,6 +30,11 @@ export class RouterEntryPointManager {
3030

3131
constructor(private moduleResolver: ModuleResolver) {}
3232

33+
keyFor(filePath: string, moduleName: string): string {
34+
// Drop the extension to be compatible with how cli calls `listLazyRoutes(entryRoute)`.
35+
return `${filePath.replace(/\.tsx?$/i, '')}#${moduleName}`;
36+
}
37+
3338
resolveLoadChildrenIdentifier(loadChildrenIdentifier: string, context: ts.SourceFile):
3439
RouterEntryPoint|null {
3540
const [relativeFile, moduleName] = loadChildrenIdentifier.split('#');
@@ -44,10 +49,9 @@ export class RouterEntryPointManager {
4449
}
4550

4651
fromNgModule(sf: ts.SourceFile, moduleName: string): RouterEntryPoint {
47-
const absoluteFile = sf.fileName;
48-
const key = `${absoluteFile}#${moduleName}`;
52+
const key = this.keyFor(sf.fileName, moduleName);
4953
if (!this.map.has(key)) {
50-
this.map.set(key, new RouterEntryPointImpl(absoluteFile, moduleName));
54+
this.map.set(key, new RouterEntryPointImpl(sf.fileName, moduleName));
5155
}
5256
return this.map.get(key) !;
5357
}

0 commit comments

Comments
 (0)