angular/packages/compiler-cli/ngcc/src/migrations
Alex Rickabaugh b381497126 feat(ngcc): add a migration for undecorated child classes (#33362)
In Angular View Engine, there are two kinds of decorator inheritance:

1) both the parent and child classes have decorators

This case is supported by InheritDefinitionFeature, which merges some fields
of the definitions (such as the inputs or queries).

2) only the parent class has a decorator

If the child class is missing a decorator, the compiler effectively behaves
as if the parent class' decorator is applied to the child class as well.
This is the "undecorated child" scenario, and this commit adds a migration
to ngcc to support this pattern in Ivy.

This migration has 2 phases. First, the NgModules of the application are
scanned for classes in 'declarations' which are missing decorators, but
whose base classes do have decorators. These classes are the undecorated
children. This scan is performed recursively, so even if a declared class
has a base class that itself inherits a decorator, this case is handled.

Next, a synthetic decorator (either @Component or @Directive) is created
on the child class. This decorator copies some critical information such
as 'selector' and 'exportAs', as well as supports any decorated fields
(@Input, etc). A flag is passed to the decorator compiler which causes a
special feature `CopyDefinitionFeature` to be included on the compiled
definition. This feature copies at runtime the remaining aspects of the
parent definition which `InheritDefinitionFeature` does not handle,
completing the "full" inheritance of the child class' decorator from its
parent class.

PR Close #33362
2019-10-25 09:16:50 -07:00
..
migration.ts feat(ngcc): add a migration for undecorated child classes (#33362) 2019-10-25 09:16:50 -07:00
missing_injectable_migration.ts feat(ngcc): migrate services that are missing @Injectable() (#33362) 2019-10-25 09:16:49 -07:00
README.md feat(ivy): ngcc - support ngcc "migrations" (#31544) 2019-07-23 21:11:40 -07:00
undecorated_child_migration.ts feat(ngcc): add a migration for undecorated child classes (#33362) 2019-10-25 09:16:50 -07:00
undecorated_parent_migration.ts refactor(ngcc): rework undecorated parent migration (#33362) 2019-10-25 09:16:50 -07:00
utils.ts feat(ngcc): add a migration for undecorated child classes (#33362) 2019-10-25 09:16:50 -07:00

ngcc migrations

There are some cases where source code needs to be migrated before ngtsc can compile it correctly.

For example, there are cases where ngtsc expects directives need to be explicitly attached to classes, whereas previously they were not required.

There are two ways this can happen:

  1. in a project being developed, the code can be migrated via a CLI schematic.
  2. in a package already published to npm, the code can be migrated as part of the ngcc compilation.

To create one of these migrations for ngcc, you should implement the Migration interface and add an instance of the class to the DecorationAnalyzer.migrations collection.

This folder is where we keep the Migration interface and the implemented migrations.

Each migration should have a unit test stored in the ../../test/migrations directory.