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

All ngcc migrations #33362

Closed
wants to merge 7 commits into from
Closed

All ngcc migrations #33362

wants to merge 7 commits into from

Commits on Oct 24, 2019

  1. fix(ngcc): prevent reflected decorators from being clobbered

    ngcc has an internal cache of computed decorator information for
    reflected classes, which could previously be mutated by consumers of the
    reflection host. With the ability to inject synthesized decorators, such
    decorators would inadvertently be added into the array of decorators
    that was owned by the internal cache of the reflection host, incorrectly
    resulting in synthesized decorators to be considered real decorators on
    a class. This commit fixes the issue by cloning the cached array before
    returning it.
    JoostK authored and alxhub committed Oct 24, 2019
    Copy the full SHA
    5c427c5 View commit details
    Browse the repository at this point in the history
  2. feat(ngcc): migrate services that are missing @Injectable()

    A class that is provided as Angular service is required to have an
    `@Injectable()` decorator so that the compiler generates its injectable
    definition for the runtime. Applications are automatically migrated
    using the "missing-injectable" schematic, however libraries built for
    older version of Angular may not yet satisfy this requirement.
    
    This commit ports the "missing-injectable" schematic to a migration that
    is ran when ngcc is processing a library. This ensures that any service
    that is provided from an NgModule or Directive/Component will have an
    `@Injectable()` decorator.
    JoostK authored and alxhub committed Oct 24, 2019
    Copy the full SHA
    7720088 View commit details
    Browse the repository at this point in the history

Commits on Oct 25, 2019

  1. refactor(ivy): mark synthetic decorators explicitly

    In ngcc's migration system, synthetic decorators can be injected into a
    compilation to ensure that certain classes are compiled with Angular
    logic, where the original library code did not include the necessary
    decorators. Prior to this change, synthesized decorators would have a
    fake AST structure as associated node and a made-up identifier. In
    theory, this may introduce issues downstream:
    
    1) a decorator's node is used for diagnostics, so it must have position
    information. Having fake AST nodes without a position is therefore a
    problem. Note that this is currently not a problem in practice, as
    injected synthesized decorators would not produce any diagnostics.
    
    2) the decorator's identifier should refer to an imported symbol.
    Therefore, it is required that the symbol is actually imported.
    Moreover, bundle formats such as UMD and CommonJS use namespaces for
    imports, so a bare `ts.Identifier` would not be suitable to use as
    identifier. This was also not a problem in practice, as the identifier
    is only used in the `setClassMetadata` generated code, which is omitted
    for synthetically injected decorators.
    
    To remedy these potential issues, this commit makes a decorator's
    identifier optional and switches its node over from a fake AST structure
    to the class' name.
    JoostK authored and alxhub committed Oct 25, 2019
    Copy the full SHA
    c8cfa3e View commit details
    Browse the repository at this point in the history
  2. refactor(ngcc): rework undecorated parent migration

    Previously, the (currently disabled) undecorated parent migration in
    ngcc would produce errors when a base class could not be determined
    statically or when a class extends from a class in another package. This
    is not ideal, as it would cause the library to fail compilation without
    a workaround, whereas those problems are not guaranteed to cause issues.
    
    Additionally, inheritance chains were not handled. This commit reworks
    the migration to address these limitations.
    JoostK authored and alxhub committed Oct 25, 2019
    Copy the full SHA
    e28043d View commit details
    Browse the repository at this point in the history
  3. feat(ngcc): enable migrations to apply schematics to libraries

    When upgrading an Angular application to a new version using the Angular
    CLI, built-in schematics are being run to update user code from
    deprecated patterns to the new way of working. For libraries that have
    been built for older versions of Angular however, such schematics have
    not been executed which means that deprecated code patterns may still be
    present, potentially resulting in incorrect behavior.
    
    Some of the logic of schematics has been ported over to ngcc migrations,
    which are automatically run on libraries. These migrations achieve the
    same goal of the regular schematics, but operating on published library
    sources instead of used code.
    JoostK authored and alxhub committed Oct 25, 2019
    Copy the full SHA
    1af6a29 View commit details
    Browse the repository at this point in the history
  4. feat(ivy): add a runtime feature to copy cmp/dir definitions

    This commit adds CopyDefinitionFeature, which supports the case where an
    entire decorator (@component or @directive) is inherited from parent to
    child.
    
    The existing inheritance feature, InheritDefinitionFeature, supports merging
    of parent and child definitions when both were originally present. This
    merges things like inputs, outputs, host bindings, etc.
    
    CopyDefinitionFeature, on the other hand, compensates for a definition that
    was missing entirely on the child class, by copying fields that aren't
    ordinarily inherited (like the template function itself).
    
    This feature is intended to only be used as part of ngcc code generation.
    alxhub committed Oct 25, 2019
    Copy the full SHA
    cc29841 View commit details
    Browse the repository at this point in the history
  5. feat(ngcc): add a migration for undecorated child classes

    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.
    alxhub committed Oct 25, 2019
    Copy the full SHA
    f1b6302 View commit details
    Browse the repository at this point in the history