99d8582882
Previously, ngtsc would throw an error if two decorators were matched on the same class simultaneously. However, @Injectable is a special case, and it appears frequently on component, directive, and pipe classes. For pipes in particular, it's a common pattern to treat the pipe class also as an injectable service. ngtsc actually lacked the capability to compile multiple matching decorators on a class, so this commit adds support for that. Decorator handlers (and thus the decorators they match) are classified into three categories: PRIMARY, SHARED, and WEAK. PRIMARY handlers compile decorators that cannot coexist with other primary decorators. The handlers for Component, Directive, Pipe, and NgModule are marked as PRIMARY. A class may only have one decorator from this group. SHARED handlers compile decorators that can coexist with others. Injectable is the only decorator in this category, meaning it's valid to put an @Injectable decorator on a previously decorated class. WEAK handlers behave like SHARED, but are dropped if any non-WEAK handler matches a class. The handler which compiles ngBaseDef is WEAK, since ngBaseDef is only needed if a class doesn't otherwise have a decorator. Tests are added to validate that @Injectable can coexist with the other decorators and that an error is generated when mixing the primaries. PR Close #28523 |
||
---|---|---|
.. | ||
src | ||
test | ||
BUILD.bazel | ||
README.md | ||
index.ts | ||
main-ngcc.ts |
README.md
Angular Compatibility Compiler (ngcc)
This compiler will convert node_modules
compiled with ngc
, into node_modules
which
appear to have been compiled with ngtsc
.
This conversion will allow such "legacy" packages to be used by the Ivy rendering engine.
Building
The project is built using Bazel:
yarn bazel build //packages/compiler-cli/src/ngcc
Unit Testing
The unit tests are built and run using Bazel:
yarn bazel test //packages/compiler-cli/src/ngcc/test
Integration Testing
There are tests that check the behavior of the overall executable:
yarn bazel test //packages/compiler-cli/test/ngcc