-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(routing): path wrongly resolved during routing analysis
- Loading branch information
1 parent
8d67d27
commit 1722ca3
Showing
5 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ const traverse = require('traverse'); | |
const ast = new Project(); | ||
|
||
export class RouterParserUtil { | ||
public scannedFiles: any[] = []; | ||
private routes: any[] = []; | ||
private incompleteRoutes = []; | ||
private modules = []; | ||
|
@@ -595,15 +596,21 @@ export class RouterParserUtil { | |
if (foundWithAliasInImports) { | ||
if (typeof searchedImport !== 'undefined') { | ||
const routePathIsBad = path => { | ||
return typeof ast.getSourceFile(path) == 'undefined'; | ||
let result = true; | ||
this.scannedFiles.forEach(scannedFile => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vogloblinsky
Author
Contributor
|
||
if (path === scannedFile.path) { | ||
result = false; | ||
} | ||
}); | ||
return result; | ||
}; | ||
|
||
const getIndicesOf = (searchStr, str, caseSensitive) => { | ||
var searchStrLen = searchStr.length; | ||
const searchStrLen = searchStr.length; | ||
if (searchStrLen == 0) { | ||
return []; | ||
} | ||
var startIndex = 0, | ||
let startIndex = 0, | ||
index, | ||
indices = []; | ||
if (!caseSensitive) { | ||
|
2 changes: 2 additions & 0 deletions
2
test/fixtures/todomvc-ng2-simple-routing/src/app/app-routing.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/fixtures/todomvc-ng2-simple-routing/src/app/login.routes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const LOGIN = [ | ||
{ | ||
path: 'login', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@vogloblinsky I'm not into the very details here, but do you just want to see if at least one entry has this condition (
path === scannedFile.path
)? Because then I would recommend usingthis.scannedFiles.find((scannedFile) => path === scannedFile.path)
because that's better to read and also better in performance (because theforEach
will continue searching in all array entries, even if already one entry was found and so it's already clear that the result will be false :)