-
Notifications
You must be signed in to change notification settings - Fork 26.6k
fix(core): undecorated-classes-with-decorated-fields migration does not decorate derived classes #35339
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
Conversation
3c485da
to
2a6e547
Compare
1c406ad
to
ea27239
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of nits, but otherwise LGTM.
...atics/migrations/undecorated-classes-with-decorated-fields/google3/tslint_update_recorder.ts
Show resolved
Hide resolved
packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/transform.ts
Show resolved
Hide resolved
Moves the `findBaseClassDeclarations` method into the shared schematic utilities. This method will be useful for future migrations, and for planned changes to the `undecorated-classes-with-decorated-fields` migration.
The import manager has been created for both the `missing-injectable` and `undecorated-classes-with-di` migration. Both initial PRs brought in the manager class, so the manager is duplicated in the schematics. In order to reduce this duplication, and to expose the manager to other schematics/migrations, we move it into the shared schematic utils.
…ot decorate derived classes The `undecorated-classes-with-decorated-fields` migration has been introduced with 904a201, but misses logic for decorating derived classes of undecorated classes which use Angular features. Example scenario: ```ts export abstract class MyBaseClass { @input() someInput = true; } export abstract class BaseClassTwo extends MyBaseClass {} @component(...) export class MyButton extends BaseClassTwo {} ``` Both abstract classes would need to be migrated. Previously, the migration only added `@Directive()` to `MyBaseClass`, but with this change, it also decorates `BaseClassTwo`. This is necessary because the Angular Compiler requires `BaseClassTwo` to have a directive definition when it flattens the directive metadata for `MyButton` in order to perform type checking. Technically, not decorating `BaseClassTwo` does not break at runtime. We basically want to enforce consistent use of `@Directive` to simplify the mental model. [See the migration guide](https://angular.io/guide/migration-undecorated-classes#migrating-classes-that-use-field-decorators). Fixes angular#34376.
…lds migration We don't have an integration test for the `undecorated-classes-with-decorated-fields migration. For consistency and to cover for the latest changes, we add it to the `ng update` integration test.
…act classes In version 10, undecorated base classes that use Angular features need to be decorated explicitly with `@Directive()`. Additionally, derived classes of abstract directives need to be decorated. The migration already handles this for undecorated classes that are not explicitly decorated, but since in V9, abstract directives can be used, we also need to handle this for explicitly decorated abstract directives. e.g. ``` @directive() export class Base {...} // needs to be decorated by migration when updating from v9 to v10 export class Wrapped extends Base {} @component(...) export class Cmp extends Wrapped {} ```
ea27239
to
304c0df
Compare
@alxhub A similar discussion came up for this in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reviewed-for: integration-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reviewed-for: dev-infra
Caretaker: Can you please run presubmit for this? I'm unsure whether schematic code is synced into g3. If it is not, then we should update the bot to exclude the folder. |
The import manager has been created for both the `missing-injectable` and `undecorated-classes-with-di` migration. Both initial PRs brought in the manager class, so the manager is duplicated in the schematics. In order to reduce this duplication, and to expose the manager to other schematics/migrations, we move it into the shared schematic utils. PR Close #35339
…ot decorate derived classes (#35339) The `undecorated-classes-with-decorated-fields` migration has been introduced with 904a201, but misses logic for decorating derived classes of undecorated classes which use Angular features. Example scenario: ```ts export abstract class MyBaseClass { @input() someInput = true; } export abstract class BaseClassTwo extends MyBaseClass {} @component(...) export class MyButton extends BaseClassTwo {} ``` Both abstract classes would need to be migrated. Previously, the migration only added `@Directive()` to `MyBaseClass`, but with this change, it also decorates `BaseClassTwo`. This is necessary because the Angular Compiler requires `BaseClassTwo` to have a directive definition when it flattens the directive metadata for `MyButton` in order to perform type checking. Technically, not decorating `BaseClassTwo` does not break at runtime. We basically want to enforce consistent use of `@Directive` to simplify the mental model. [See the migration guide](https://angular.io/guide/migration-undecorated-classes#migrating-classes-that-use-field-decorators). Fixes #34376. PR Close #35339
…act classes (#35339) In version 10, undecorated base classes that use Angular features need to be decorated explicitly with `@Directive()`. Additionally, derived classes of abstract directives need to be decorated. The migration already handles this for undecorated classes that are not explicitly decorated, but since in V9, abstract directives can be used, we also need to handle this for explicitly decorated abstract directives. e.g. ``` @directive() export class Base {...} // needs to be decorated by migration when updating from v9 to v10 export class Wrapped extends Base {} @component(...) export class Cmp extends Wrapped {} ``` PR Close #35339
The import manager has been created for both the `missing-injectable` and `undecorated-classes-with-di` migration. Both initial PRs brought in the manager class, so the manager is duplicated in the schematics. In order to reduce this duplication, and to expose the manager to other schematics/migrations, we move it into the shared schematic utils. PR Close #35339
…ot decorate derived classes (#35339) The `undecorated-classes-with-decorated-fields` migration has been introduced with 904a201, but misses logic for decorating derived classes of undecorated classes which use Angular features. Example scenario: ```ts export abstract class MyBaseClass { @input() someInput = true; } export abstract class BaseClassTwo extends MyBaseClass {} @component(...) export class MyButton extends BaseClassTwo {} ``` Both abstract classes would need to be migrated. Previously, the migration only added `@Directive()` to `MyBaseClass`, but with this change, it also decorates `BaseClassTwo`. This is necessary because the Angular Compiler requires `BaseClassTwo` to have a directive definition when it flattens the directive metadata for `MyButton` in order to perform type checking. Technically, not decorating `BaseClassTwo` does not break at runtime. We basically want to enforce consistent use of `@Directive` to simplify the mental model. [See the migration guide](https://angular.io/guide/migration-undecorated-classes#migrating-classes-that-use-field-decorators). Fixes #34376. PR Close #35339
…act classes (#35339) In version 10, undecorated base classes that use Angular features need to be decorated explicitly with `@Directive()`. Additionally, derived classes of abstract directives need to be decorated. The migration already handles this for undecorated classes that are not explicitly decorated, but since in V9, abstract directives can be used, we also need to handle this for explicitly decorated abstract directives. e.g. ``` @directive() export class Base {...} // needs to be decorated by migration when updating from v9 to v10 export class Wrapped extends Base {} @component(...) export class Cmp extends Wrapped {} ``` PR Close #35339
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The
undecorated-classes-with-decorated-fields
migration has beenintroduced with 904a201, but misses logic for decorating derived classes
of undecorated classes which use Angular features. Example scenario:
Both abstract classes would need to be migrated. Previously, the migration
only added
@Directive()
toMyBaseClass
, but with this change, it alsodecorates
BaseClassTwo
.This is necessary because the Angular Compiler requires
BaseClassTwo
tohave a directive definition when it flattens the directive metadata for
MyButton
in order to perform type checking. Technically, not decoratingBaseClassTwo
does not break at runtime because the inherit definition featurewalks up the prototype chain. Though we want to enforce consistent use of
@Directive
to simplify the mental model. See the migration guide for motivation.Fixes #34376.
Note: It should be easier and less verbose to to review the commits individually.