@@ -313,6 +313,43 @@ const routes: Routes = [
313313 } ) ;
314314 } ) ;
315315
316+ describe ( "cleanCallExpressions() — function calls in route values (issue #1293)" , ( ) => {
317+ it ( "should allow JSON5.parse when path is defined by a function call" , ( ) => {
318+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
319+ const sourceFile = project . createSourceFile (
320+ "/tmp/routes-1293.ts" ,
321+ `
322+ import { Routes } from "@angular/router";
323+ export function homePageRoutePath(): string {
324+ return "";
325+ }
326+ const routes: Routes = [
327+ {
328+ path: homePageRoutePath(),
329+ component: "HomePageComponent"
330+ }
331+ ];
332+ ` ,
333+ ) ;
334+
335+ routerParser . cleanCallExpressions ( sourceFile ) ;
336+ routerParser . cleanFileDynamics ( sourceFile ) ;
337+
338+ const initializer = sourceFile
339+ . getVariableDeclarationOrThrow ( "routes" )
340+ . getInitializerOrThrow ( ) . compilerNode ;
341+ const generated = new CodeGenerator ( ) . generate ( initializer ) ;
342+ const cleaned = routerParser . cleanRawRoute ( generated ) ;
343+
344+ let parsed : any ;
345+ expect ( ( ) => {
346+ parsed = require ( "json5" ) . parse ( cleaned ) ;
347+ } ) . not . to . throw ( ) ;
348+
349+ expect ( parsed [ 0 ] . path ) . to . equal ( "homePageRoutePath()" ) ;
350+ } ) ;
351+ } ) ;
352+
316353 // ── cleanFileSpreads() — path alias resolution (issue #1545) ─────────────
317354
318355 describe ( "cleanFileSpreads() — path alias resolution (issue #1545)" , ( ) => {
@@ -346,6 +383,52 @@ export const routes: Routes = [...missingRoutes];`,
346383 }
347384 } ) ;
348385
386+ it ( "should not throw when spread uses a function call expression (issue #1317)" , ( ) => {
387+ const warnStub = sinon . stub ( logger , "warn" ) ;
388+ try {
389+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
390+ const sourceFile = project . createSourceFile (
391+ "/tmp/test-spread-call-routes.ts" ,
392+ `import { Routes } from '@angular/router';
393+ const communicationCommonRoutes = () => [{ path: 'communication' }];
394+ export const routes: Routes = [{ path: 'root', children: [...communicationCommonRoutes(), { path: 'fallback' }] }];` ,
395+ { overwrite : true } ,
396+ ) ;
397+
398+ expect ( ( ) =>
399+ routerParser . cleanFileSpreads ( sourceFile ) ,
400+ ) . not . to . throw ( ) ;
401+ expect ( sourceFile . getText ( ) ) . to . contain (
402+ "...communicationCommonRoutes()" ,
403+ ) ;
404+ expect ( warnStub . called ) . to . equal ( true ) ;
405+ } finally {
406+ warnStub . restore ( ) ;
407+ }
408+ } ) ;
409+
410+ it ( "should not throw when spread uses a property-access call expression (issue #1293)" , ( ) => {
411+ const warnStub = sinon . stub ( logger , "warn" ) ;
412+ try {
413+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
414+ const sourceFile = project . createSourceFile (
415+ "/tmp/test-spread-map-routes.ts" ,
416+ `import { Routes } from '@angular/router';
417+ const langs = ['en', 'pl'];
418+ export const routes: Routes = [{ path: 'root', children: [...langs.map(lang => ({ path: lang }))] }];` ,
419+ { overwrite : true } ,
420+ ) ;
421+
422+ expect ( ( ) =>
423+ routerParser . cleanFileSpreads ( sourceFile ) ,
424+ ) . not . to . throw ( ) ;
425+ expect ( sourceFile . getText ( ) ) . to . contain ( "...langs.map" ) ;
426+ expect ( warnStub . called ) . to . equal ( true ) ;
427+ } finally {
428+ warnStub . restore ( ) ;
429+ }
430+ } ) ;
431+
349432 it ( "should resolve a path alias from tsconfig.paths and inline the spread without crashing (issue #1545)" , ( ) => {
350433 Configuration . mainData . tsconfig = path . join (
351434 fixtureRoot ,
0 commit comments