Skip to content

Commit 592dea3

Browse files
committed
fix(router): handle issues #1363 and #1366
closes #1363 closes #1366
1 parent 02d2311 commit 592dea3

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎src/utils/router-parser.util.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ export class RouterParserUtil {
129129
.replace(
130130
/"?loadComponent"?:\(\)=>import\(["'`]([^"'`]+)["'`]\)\."?then"?\(\(?["']?\w+["']?\)?"?=>(?:["']?\w+["']?\.)?"?(\w+)"?\)/g,
131131
'loadComponent:"$1#$2"',
132+
)
133+
.replace(
134+
/"?loadComponent"?:\(\)=>import\(["'`]([^"'`]+)["'`]\)(?!\."?then"?\()/g,
135+
'loadComponent:"$1#default"',
132136
);
133137

134138
// Step 1: Convert template literal interpolations to bare identifiers

‎test/src/utils/router-parser.util.spec.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ describe("Utils - RouterParserUtil", () => {
185185
expect(result).not.to.include("[Function]");
186186
});
187187

188+
it('should convert loadComponent default-export syntax to "path#default" string (issue #1363)', () => {
189+
const result = routerParser.cleanRawRoute(
190+
"[{path:'faq',loadComponent:()=>import('./pages/faq/faq.component')}]",
191+
);
192+
expect(result).to.include(
193+
'loadComponent:"./pages/faq/faq.component#default"',
194+
);
195+
expect(result).not.to.include("[Function]");
196+
});
197+
188198
// ── CodeGenerator output format (issue #1546) ────────────────────────
189199
// CodeGenerator wraps identifiers in double quotes and produces:
190200
// "loadComponent":()=>import("path")."then"("m"=>"m"."Module")
@@ -632,6 +642,46 @@ const routes: Route[] = [
632642
]);
633643
});
634644

645+
it("should keep unresolved enum member references in data arrays JSON5-parseable (issue #1366)", () => {
646+
const project = new Project({ useInMemoryFileSystem: true });
647+
const sourceFile = project.createSourceFile(
648+
"/tmp/feature-routing-1366.module.ts",
649+
`
650+
import { Routes } from "@angular/router";
651+
import { PermissionCode } from "@shared/permissions";
652+
653+
const routes: Routes = [
654+
{
655+
path: "",
656+
component: "MapPageComponent",
657+
data: {
658+
permissions: [PermissionCode.Map_View]
659+
}
660+
}
661+
];
662+
`,
663+
);
664+
665+
routerParser.cleanFileSpreads(sourceFile);
666+
routerParser.cleanCallExpressions(sourceFile);
667+
routerParser.cleanFileDynamics(sourceFile);
668+
669+
const initializer = sourceFile
670+
.getVariableDeclarationOrThrow("routes")
671+
.getInitializerOrThrow().compilerNode;
672+
const generated = new CodeGenerator().generate(initializer);
673+
const cleaned = routerParser.cleanRawRoute(generated);
674+
675+
let parsed: any;
676+
expect(() => {
677+
parsed = require("json5").parse(cleaned);
678+
}).not.to.throw();
679+
680+
expect(parsed[0].data.permissions).to.deep.equal([
681+
"PermissionCode.Map_View",
682+
]);
683+
});
684+
635685
it("should allow resolve callbacks using inject() in feature Route[] declarations (issue #1433)", () => {
636686
const project = new Project({ useInMemoryFileSystem: true });
637687
const sourceFile = project.createSourceFile(

0 commit comments

Comments
 (0)