ngxtension / ngxtension-platform

Utilities for Angular
https://ngxtension.netlify.app/
MIT License
532 stars 77 forks source link

Compile error after running the inject migration #443

Closed timdeschryver closed 2 days ago

timdeschryver commented 5 days ago

The inject migration only updates the first usage when a property get's assigned in the ctor. See the below snippets for an example.

Input:

    import { Component } from '@angular/core';

    @Component({
      template: ''
    })
    export class MyComponent {
      depOne$: Observable<string>;
      depTwo$: Observable<string>;
      depThree$: Observable<string>;
      depFour$: Observable<string>;

      constructor(private service: Service) {
        this.depOne$ = service.depOne$;
        this.depTwo$ = service.depTwo$;
        this.depThree$ = this.service.depThree$;
        this.depFour$ = service.depFour$;
      }
    }

Expected output:

    import { Component, inject } from '@angular/core';

    @Component({
      template: ''
    })
    export class MyComponent {
      private service = inject(Service);
      depOne$: Observable<string>;
      depTwo$: Observable<string>;
      depThree$: Observable<string>;
      depFour$: Observable<string>;

      constructor() {
        this.depOne$ = this.service.depOne$;
        this.depTwo$ = this.service.depTwo$;
        this.depThree$ = this.service.depThree$;
        this.depFour$ = this.service.depFour$;
      }
    }

Received output:

    import { Component, inject } from '@angular/core';

    @Component({
      template: ''
    })
    export class MyComponent {
      private service = inject(Service);
      depOne$: Observable<string>;
      depTwo$: Observable<string>;
      depThree$: Observable<string>;
      depFour$: Observable<string>;

      constructor() {
        this.depOne$ = this.service.depOne$;
        this.depTwo$ = service.depTwo$;
                       ~~~~~~~ throws error, migration doesn't add this keyword
        this.depThree$ = this.service.depThree$;
        this.depFour$ = service.depFour$;
                       ~~~~~~~ throws error, migration doesn't add this keyword
      }
    }