angular-docs-cn/packages/compiler-cli/test/ngtsc
Alex Rickabaugh 99d8582882 feat(ivy): support @Injectable on already decorated classes (#28523)
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
2019-02-13 19:13:10 -08:00
..
fake_core fix(ivy): proper resolution of Enums in Component decorator (#27971) 2019-01-10 10:49:03 -08:00
BUILD.bazel feat(ivy): add source mappings to compiled Angular templates (#28055) 2019-02-12 20:58:28 -08:00
env.ts build: support running ngtsc tests on windows (#28352) 2019-02-05 14:31:10 -05:00
ngtsc_spec.ts feat(ivy): support @Injectable on already decorated classes (#28523) 2019-02-13 19:13:10 -08:00
sourcemap_utils.ts feat(ivy): add source mappings to compiled Angular templates (#28055) 2019-02-12 20:58:28 -08:00
template_mapping_spec.ts test(ivy): add template source mapping tests (#28055) 2019-02-12 20:58:28 -08:00
template_typecheck_spec.ts build: remove unused "test.sh" leftover code in compiler-cli (#28352) 2019-02-05 14:31:10 -05:00