diff --git a/src/utils/router-parser.util.ts b/src/utils/router-parser.util.ts index 5fb87957..52ee5b44 100644 --- a/src/utils/router-parser.util.ts +++ b/src/utils/router-parser.util.ts @@ -23,9 +23,9 @@ export class RouterParserUtil { private cleanModulesTree; private modulesWithRoutes = []; private transformAngular8ImportSyntax = - /(['"]loadChildren['"]:)\(\)(:[^)]+?)?=>"import\((\\'|'|")([^'"]+?)(\\'|'|")\)\.then\(\(?\w+?\)?=>\S+?\.([^)]+?)\)(\\'|'|")/g; + /(['"]loadChildren['"]:)\(\)(:[^)]+?)?=>"import\((\\'|'|"|`)([^'"]+?)(\\'|'|"|`)\)\.then\(\(?\w+?\)?=>\S+?\.([^)]+?)\)(\\'|'|")/g; private transformAngular8ImportSyntaxAsyncAwait = - /(['"]loadChildren['"]:)\(\)(:[^)]+?)?=>\("import\((\\'|'|")([^'"]+?)(\\'|'|")\)"\)\.['"]([^)]+?)['"]/g; + /(['"]loadChildren['"]:)\(\)(:[^)]+?)?=>\("import\((\\'|'|"|`)([^'"]+?)(\\'|'|"|`)\)"\)\.['"]([^)]+?)['"]/g; private static instance: RouterParserUtil; private constructor() {} @@ -594,8 +594,7 @@ export class RouterParserUtil { if (foundWithAliasInImports) { if (typeof searchedImport !== 'undefined') { - - const routePathIsBad = (path) => { + const routePathIsBad = path => { return typeof ast.getSourceFile(path) == 'undefined'; }; @@ -604,7 +603,9 @@ export class RouterParserUtil { if (searchStrLen == 0) { return []; } - var startIndex = 0, index, indices = []; + var startIndex = 0, + index, + indices = []; if (!caseSensitive) { str = str.toLowerCase(); searchStr = searchStr.toLowerCase(); @@ -614,22 +615,28 @@ export class RouterParserUtil { startIndex = index + searchStrLen; } return indices; - } + }; const dirNamePath = path.dirname(file.getFilePath()); const searchedImportPath = searchedImport.getModuleSpecifierValue(); const leadingFilePath = searchedImportPath.split('/').shift(); - let importPath = path.resolve(dirNamePath + '/' + searchedImport.getModuleSpecifierValue() + '.ts'); + let importPath = path.resolve( + dirNamePath + '/' + searchedImport.getModuleSpecifierValue() + '.ts' + ); if (routePathIsBad(importPath)) { let leadingIndices = getIndicesOf(leadingFilePath, importPath, true); - if (leadingIndices.length > 1) { // Nested route fixes + if (leadingIndices.length > 1) { + // Nested route fixes let startIndex = leadingIndices[0]; - let endIndex = leadingIndices[leadingIndices.length -1]; - importPath = importPath.slice(0, startIndex) + importPath.slice(endIndex); - } else { // Top level route fixes - importPath = path.dirname(dirNamePath) + '/' + searchedImportPath + '.ts'; + let endIndex = leadingIndices[leadingIndices.length - 1]; + importPath = + importPath.slice(0, startIndex) + importPath.slice(endIndex); + } else { + // Top level route fixes + importPath = + path.dirname(dirNamePath) + '/' + searchedImportPath + '.ts'; } } const sourceFileImport = diff --git a/test/fixtures/todomvc-ng2-simple-routing-standard-async/src/app/app-routing.module.ts b/test/fixtures/todomvc-ng2-simple-routing-standard-async/src/app/app-routing.module.ts index c2e7db65..8be2bc1f 100644 --- a/test/fixtures/todomvc-ng2-simple-routing-standard-async/src/app/app-routing.module.ts +++ b/test/fixtures/todomvc-ng2-simple-routing-standard-async/src/app/app-routing.module.ts @@ -3,6 +3,7 @@ import { Routes, RouterModule } from '@angular/router'; export const APP_ROUTES: Routes = [ { path: 'about', loadChildren: async () => (await import('./about/about.module')).AboutModule }, + { path: 'toto', loadChildren: async () => (await import(`./toto/toto.module`)).TotoModule }, { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: '**', redirectTo: 'home', pathMatch: 'full' } ];