This module is used for route extraction by the
GuessPlugin. The module exports several functions:
npm i guess-parser --save-dev
detect(path: string)- Detects the project type and returns metadata. For the currently supported projects see the
parseRoutes(path: string)- Extracts the routes of the application in
path. Internally uses the
parseAngularRoutes(tsconfig: string)- Extracts the routes of an Angular application. As arguments the function accepts path to the
tsconfig.jsonfile of the project.
parseReactJSXRoutes(path: string)- Extracts the routes from React JSX project. See the supported syntax below.
parseReactTSXRoutes(tsconfig: string)- Extracts the routes from React TypeScript projects which uses JSX by
tsconfig.jsonfile. See the supported syntax below.
Because of the produced summaries by the Angular compiler the Angular parser supports most Angular CLI applications as well as most starters.
Because of the dynamic nature of React and lack of standard route definition syntax, only applications using the following convention can be successfully parsed:
<Router =><div ="App"><Link ="/intro">Intro</Link><Link ="/main">Main</Link><div><Switch><Redirect = ="/" ="/intro" /><Route ="/intro" = /><Route ="/main" = /></Switch></div></div></Router>
Currently, there are several important conventions:
- Support only for JSX syntax
- Support only for
- The path attribute of the
<Route/>element must have value of type string literal.
- The lazy-loaded components should have dynamic import with the following structure of the AST:
AsyncComponent) with a single argument
- The type of the argument should be an
- The arrow function should have an expression as body (e.g.
- To the
CallExpressionshould be passed a
StringLiteralwhich points to the lazy-loaded module
Contributions aiming to extend the supported syntax are very welcome!