mgechev / ngast

Parser for Angular projects.

Home Page:https://mgechev.github.io/ngast/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support lazy routes in ProjectSymbols?

irustm opened this issue · comments

{ path: routesNames.heroes.basePath, loadChildren: () => import('./modules/heroes/heroes.module').then(m => m.HeroesModule) },
const projectSymbols = new ProjectSymbols(
    projectPath,
    resourceResolver,
    e => (parseError = e)
);

I get that error

Error during template compile of 'AppRoutingModule'
Reference to a local (non-exported) symbols are not supported in decorators but 'routes' was referenced
Consider exporting 'routes'.

Do you have any plans to do lazy routes support?

If not, I'd like to do it.

The lack of lazy-loaded module support that you found is just a part of the story. All the primitives from the compiler that ngast steps on will be gone once we move from view engine. This would require rewrite of the library.

Since ngast returns objects of types defined in view engine, after a rewrite, all the projects would have to adapt to the new abstractions.

Hi @mgechev, do you have any plan to rewrite this library to solve this issue?

Unfortunately, I will not have the bandwidth for this anytime soon.

Hi @mgechev what would be the process to upgrade the library ? I don't know the arcanes of the new engine yet, but I would love to give it a try.
Do you have some documentation / source-code reference to share, to know where to start ?
Thanks for the awesome work so far !

Hello @mgechev following my message above, so far I understood that most updates to do are in the folder render3 of @angular/compiler.
Here are the upgrade I found so far:

  • Use parseTemplate to get the latest Template AST strcucture
  • Use makeBindingParser to get the BindingParser
  • Use listLazyRoutes to get the lazy loaded routes of a module
  • Use createWorkspaceHost and the tsConfig option to manage monorepo projects

I'm not sure if I'm going on the right direction. It looks like that AotCompiler already create the bridge between render2 & render3 and includes the lazy route. Any feedback would be most appreciated 😅.

parseTemplate seems usable in this case. There are other pieces of metadata that we need to collect which are not covered in the list above.

Ok, I'll continue my investigation then 🕵️‍♂️ !
Is it ok if I open a draft PR if I've got some working progress ?

@GrandSchtroumpf

Hi! any ideas about the ngtsc-routes tests ? I see the fixture has been added, but no tests. And such an example will give out an error

  describe('ngtsc-routes', () => {
    let workspace: WorkspaceSymbols;
    const folder = getFolder('ngtsc-routes');

    beforeEach(() => workspace = new WorkspaceSymbols(`${folder}/tsconfig.json`));

    it('Should find all lazy routes', () => {
      const lazyRoutes = workspace.routeAnalyzer.listLazyRoutes();
      expect(lazyRoutes.length).toBe(2);
    });
  });

We're not using the route parsing implementation from ngtsc because we found it incomplete. If you need route parsing, you can look at guess-parser.

Here's an example. Maybe we can close this issue?

Thanks!