@@ -1534,37 +1534,71 @@ export class RouterParserUtil {
15341534 public cleanCallExpressions ( sourceFile : SourceFile ) : SourceFile {
15351535 const file = sourceFile ;
15361536
1537- // Find all variable declarations with Routes type
1538- const variableDeclarations = sourceFile . getVariableDeclarations ( ) ;
1539- const routesVariableDeclarations = variableDeclarations . filter ( ( v ) => {
1540- const type = v . compilerNode . type ;
1537+ const isRouteVariableDeclaration = ( declaration ) : boolean => {
1538+ const declarationType = declaration . compilerNode . type ;
1539+ if ( ! declarationType ) {
1540+ return false ;
1541+ }
1542+
1543+ if (
1544+ ts . isTypeReferenceNode ( declarationType ) &&
1545+ declarationType . typeName
1546+ ) {
1547+ const typeName = declarationType . typeName . getText ( ) ;
1548+ if ( typeName === "Routes" || typeName . endsWith ( ".Routes" ) ) {
1549+ return true ;
1550+ }
1551+
1552+ if (
1553+ ( typeName === "Array" || typeName === "ReadonlyArray" ) &&
1554+ declarationType . typeArguments &&
1555+ declarationType . typeArguments . length === 1
1556+ ) {
1557+ const routeType = declarationType . typeArguments [ 0 ] ;
1558+ if (
1559+ ts . isTypeReferenceNode ( routeType ) &&
1560+ routeType . typeName
1561+ ) {
1562+ const routeTypeName = routeType . typeName . getText ( ) ;
1563+ if (
1564+ routeTypeName === "Route" ||
1565+ routeTypeName . endsWith ( ".Route" )
1566+ ) {
1567+ return true ;
1568+ }
1569+ }
1570+ }
1571+ }
1572+
15411573 if (
1542- typeof type !== "undefined" &&
1543- ts . isTypeReferenceNode ( type ) &&
1544- typeof type . typeName !== "undefined"
1574+ ts . isArrayTypeNode ( declarationType ) &&
1575+ ts . isTypeReferenceNode ( declarationType . elementType ) &&
1576+ declarationType . elementType . typeName
15451577 ) {
1546- return ( type . typeName as ts . Identifier ) . text === "Routes" ;
1578+ const elementTypeName = declarationType . elementType . typeName . getText ( ) ;
1579+ if (
1580+ elementTypeName === "Route" ||
1581+ elementTypeName . endsWith ( ".Route" )
1582+ ) {
1583+ return true ;
1584+ }
15471585 }
1586+
15481587 return false ;
1549- } ) ;
1588+ } ;
15501589
1551- if ( routesVariableDeclarations . length === 0 ) {
1552- return file ;
1553- }
1590+ const routesVariableDeclarations = sourceFile
1591+ . getVariableDeclarations ( )
1592+ . filter ( ( declaration ) => isRouteVariableDeclaration ( declaration ) ) ;
15541593
1555- // Process all Routes variable declarations
15561594 for ( const variableDeclaration of routesVariableDeclarations ) {
15571595 const initializer = variableDeclaration . getInitializer ( ) ;
1558- if ( ! initializer ) {
1559- continue ;
1560- }
1596+ if ( ! initializer ) continue ;
15611597
15621598 for ( const callExpr of initializer . getDescendantsOfKind (
15631599 SyntaxKind . CallExpression ,
15641600 ) ) {
1565- if ( callExpr . wasForgotten ( ) ) {
1566- continue ;
1567- }
1601+ if ( callExpr . wasForgotten ( ) ) continue ;
15681602 callExpr . replaceWithText ( ( writer ) =>
15691603 writer . quote ( callExpr . getText ( ) ) ,
15701604 ) ;
0 commit comments