@@ -117,9 +117,7 @@ function findRoutesArrayToMigrate(sourceFile: ts.SourceFile, typeChecker: ts.Typ
117
117
}
118
118
}
119
119
}
120
- }
121
-
122
- if ( ts . isVariableDeclaration ( node ) ) {
120
+ } else if ( ts . isVariableDeclaration ( node ) ) {
123
121
if ( isAngularRoutesArray ( node , typeChecker ) ) {
124
122
const initializer = node . initializer ;
125
123
if (
@@ -140,6 +138,37 @@ function findRoutesArrayToMigrate(sourceFile: ts.SourceFile, typeChecker: ts.Typ
140
138
} ) ;
141
139
}
142
140
}
141
+ } else if ( ts . isExportAssignment ( node ) ) {
142
+ // Handles `export default routes`, `export default [...]` and `export default [...] as Routes`
143
+ let expression = node . expression ;
144
+
145
+ if ( ts . isAsExpression ( expression ) ) {
146
+ expression = expression . expression ;
147
+ }
148
+
149
+ if ( ts . isArrayLiteralExpression ( expression ) ) {
150
+ routesArrays . push ( {
151
+ routeFilePath : sourceFile . fileName ,
152
+ array : expression ,
153
+ routeFileImports : sourceFile . statements . filter ( ts . isImportDeclaration ) ,
154
+ } ) ;
155
+ } else if ( ts . isIdentifier ( expression ) ) {
156
+ manageRoutesExportedByDefault ( routesArrays , typeChecker , expression , sourceFile ) ;
157
+ }
158
+ } else if ( ts . isExportDeclaration ( node ) ) {
159
+ // Handles cases like `export { routes as default }`
160
+ if ( node . exportClause && ts . isNamedExports ( node . exportClause ) ) {
161
+ for ( const specifier of node . exportClause . elements ) {
162
+ if ( specifier . name . text === 'default' ) {
163
+ manageRoutesExportedByDefault (
164
+ routesArrays ,
165
+ typeChecker ,
166
+ specifier . propertyName ?? specifier . name ,
167
+ sourceFile ,
168
+ ) ;
169
+ }
170
+ }
171
+ }
143
172
}
144
173
145
174
node . forEachChild ( walk ) ;
@@ -325,6 +354,31 @@ function createLoadComponentPropertyAssignment(
325
354
) ;
326
355
}
327
356
357
+ const manageRoutesExportedByDefault = (
358
+ routesArrays : RouteData [ ] ,
359
+ typeChecker : ts . TypeChecker ,
360
+ expression : ts . Expression ,
361
+ sourceFile : ts . SourceFile ,
362
+ ) => {
363
+ const symbol = typeChecker . getSymbolAtLocation ( expression ) ;
364
+ if ( ! symbol ?. declarations ) {
365
+ return ;
366
+ }
367
+ for ( const declaration of symbol . declarations ) {
368
+ if (
369
+ ts . isVariableDeclaration ( declaration ) &&
370
+ declaration . initializer &&
371
+ ts . isArrayLiteralExpression ( declaration . initializer )
372
+ ) {
373
+ routesArrays . push ( {
374
+ routeFilePath : sourceFile . fileName ,
375
+ array : declaration . initializer ,
376
+ routeFileImports : sourceFile . statements . filter ( ts . isImportDeclaration ) ,
377
+ } ) ;
378
+ }
379
+ }
380
+ } ;
381
+
328
382
// import('./path)
329
383
const createImportCallExpression = ( componentImportPath : string ) =>
330
384
ts . factory . createCallExpression ( ts . factory . createIdentifier ( 'import' ) , undefined , [
0 commit comments