Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): various fixes for missing-injectable migration #33286

Conversation

@devversion
Copy link
Member

devversion commented Oct 21, 2019

See individual commits.

@devversion devversion requested a review from angular/fw-core as a code owner Oct 21, 2019
@ngbot ngbot bot modified the milestone: needsTriage Oct 21, 2019
@googlebot googlebot added the cla: yes label Oct 21, 2019
@devversion devversion force-pushed the devversion:refactor/core-missing-injectable-forward-ref branch from 02c4c04 to ad5a3c6 Oct 21, 2019
@devversion devversion force-pushed the devversion:refactor/core-missing-injectable-forward-ref branch 2 times, most recently from 246f661 to a80d60b Oct 21, 2019
@devversion devversion changed the title refactor(core): missing-injectable migration should handle forwardRef refactor(core): various fixes for missing-injectable migration Oct 22, 2019
@devversion devversion force-pushed the devversion:refactor/core-missing-injectable-forward-ref branch 2 times, most recently from e6e6d58 to 483c4d4 Oct 22, 2019
@devversion devversion requested a review from angular/fw-integration as a code owner Oct 22, 2019
@alxhub
alxhub approved these changes Oct 24, 2019
@@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {forwardRefResolver} from '@angular/compiler-cli/src/ngtsc/annotations/src/util';

This comment has been minimized.

Copy link
@alxhub

alxhub Oct 24, 2019

Contributor

We really need to put this in a better place...

This comment has been minimized.

Copy link
@devversion

devversion Oct 24, 2019

Author Member

Agreed. It currently is somewhat odd to import from the annotations build package.

@alxhub

This comment has been minimized.

Copy link
Contributor

alxhub commented Oct 24, 2019

devversion added 3 commits Oct 21, 2019
Currently the migration is unable to migrate instances where
the provider definition uses `forwardRef`. Since this is a
common pattern, we should support that from within the migration.

The solution to the problem is adding a foreign function resolver
to the `PartialEvaluator`. This basically matches the usage of
the static evaluation that is used by the ngtsc annotations.
…with "useExisting"

We should not migrate the reference from `useExisting`. This is because
developers can only use the `useExisting` value as a token. e.g.

```ts
@NgModule({
  providers: [
    {provide: AppRippleConfig, useValue: rippleOptions},
    {provide: MAT_RIPPLE_OPTIONS, useExisting: AppRippleConfig},
  ]
})
export class AppModule {}
```

In the case above, nothing should be decorated with `@Injectable`. The
`AppRippleConfig` class is just used as a token for injection.
…tions

Currently the `missing-injectable` migration seems to add
`@Injectable()` to third-party classes in type definitions.

This not an issue in general since we do not generate broken code
by inserting a decorator into a type definition file. Though, we can
avoid adding the decorator since it won't have any effect and in
general we should not write to non source files of the compilation unit.
@devversion devversion force-pushed the devversion:refactor/core-missing-injectable-forward-ref branch from 483c4d4 to 4656cae Oct 24, 2019
@AndrewKushnir

This comment has been minimized.

Copy link
Contributor

AndrewKushnir commented Oct 25, 2019

FYI, g3 presubmit looks good.

AndrewKushnir added a commit that referenced this pull request Oct 25, 2019
…with "useExisting" (#33286)

We should not migrate the reference from `useExisting`. This is because
developers can only use the `useExisting` value as a token. e.g.

```ts
@NgModule({
  providers: [
    {provide: AppRippleConfig, useValue: rippleOptions},
    {provide: MAT_RIPPLE_OPTIONS, useExisting: AppRippleConfig},
  ]
})
export class AppModule {}
```

In the case above, nothing should be decorated with `@Injectable`. The
`AppRippleConfig` class is just used as a token for injection.

PR Close #33286
AndrewKushnir added a commit that referenced this pull request Oct 25, 2019
…tions (#33286)

Currently the `missing-injectable` migration seems to add
`@Injectable()` to third-party classes in type definitions.

This not an issue in general since we do not generate broken code
by inserting a decorator into a type definition file. Though, we can
avoid adding the decorator since it won't have any effect and in
general we should not write to non source files of the compilation unit.

PR Close #33286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.