angular/packages/compiler-cli/src/ngtsc/annotations
Kristiyan Kostadinov bb863ee0db refactor(compiler): consolidate combined recursive visitors (#61158)
We have several cases where we need a visitor that traverses both the template and expression ASTs fully. Currently we're re-implementing the visitor each time which means that we need to update multiple visitors every time something changes.

These changes add a single base class that we can reuse to simplify such cases in the future.

PR Close #61158
2025-05-08 07:11:36 +02:00
..
common fix(compiler-cli): Produce fatal diagnostic on duplicate decorated properties (#60376) 2025-03-27 20:26:42 +00:00
component refactor(compiler): consolidate combined recursive visitors (#61158) 2025-05-08 07:11:36 +02:00
directive refactor(compiler-cli): add selectorless-related analysis to components (#61100) 2025-05-05 14:38:12 -07:00
ng_module build: properly compile tests in core with Angular compiler (#60268) 2025-03-07 11:00:47 -08:00
src docs(docs-infra): Improve doc support for pipes. (#60926) 2025-04-23 08:46:11 +02:00
test refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
BUILD.bazel refactor(compiler-cli): split the 'annotations' package into sub-packages (#44812) 2022-02-03 08:55:25 -08:00
index.ts build: properly compile tests in core with Angular compiler (#60268) 2025-03-07 11:00:47 -08:00
README.md refactor(compiler-cli): split the 'annotations' package into sub-packages (#44812) 2022-02-03 08:55:25 -08:00

What is the 'annotations' package?

This package implements compilation of Angular-annotated classes - those with @Component, @NgModule, etc. decorators. (Note that the compiler uses 'decorator' and 'annotation' interchangeably, despite them having slightly different semantics).

The 'transform' package of the compiler provides an abstraction for a DecoratorHandler, which defines how to compile a class decorated with a particular Angular decorator. This package implements a DecoratorHandler for each Angular type. The methods of these DecoratorHandlers then allow the rest of the compiler to process each decorated class through the phases of compilation.

Anatomy of DecoratorHandlers

Each handler implemented here performs some similar operations:

  • It uses the PartialEvaluator to resolve expressions within the decorator metadata or other decorated fields that need to be understood statically.
  • It extracts information from constructors of decorated classes which is required to generate dependency injection instructions.
  • It reports errors when developers have misused or misconfigured the decorators.
  • It populates registries that describe decorated classes to the rest of the compiler.
  • It uses those same registries to understand decorated classes within the context of the compilation (for example, to understand which dependencies are used in a given template).
  • It creates SemanticSymbols which allow for accurate incremental compilation when reacting to input changes.
  • It builds metadata objects for @angular/compiler which describe the decorated classes, which can then perform the actual code generation.

Since there is significant overlap between DecoratorHandler implementations, much of this functionality is implemented in a shared 'common' sub-package.