ngxtension / ngxtension-platform

Utilities for Angular

Home Page:https://ngxtension.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid output that can't compile for convert-di-to-inject with local and "public" dependencies

timdeschryver opened this issue Β· comments

πŸ‘‹ thanks for this great library. Last week I've used the schematic to migrate our codebase to move away from constructors to inject. I stumbled across this edge case, resulting in a project that couldn't be compiled anymore after running the convert-di-to-inject migration.

If a dependency is used within the constructor AND outside of it, the this. keyword isn't prefixed within the constructor. If the dependency is only used within the constructor this isn't a problem as the dependency will be created as a variable within the constructor.

The following output already shows this behavior (myService.doSomething(); needs to be this.myService.doSomething();)

https://github.com/ngxtension/ngxtension-platform/blob/16b66e514dcff6fd440f12d799d44a6e098f9ee6/libs/plugin/src/generators/convert-di-to-inject/__snapshots__/generator.spec.ts.snap#L48C1-L81C6

This can be fixed by moving the commented code to the else block if the dependency is used outside the ctor.

https://github.com/ngxtension/ngxtension-platform/blob/16b66e514dcff6fd440f12d799d44a6e098f9ee6/libs/plugin/src/generators/convert-di-to-inject/generator.ts#L211C1-L230C13

If you want I can create a PR for this.