mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
When `@angular/compiler` processes metadata and compiles a definition field, it might also choose to return statements that are associated with that definition, and should be included after the type being compiled. Currently, the linker ignores these statements, as there are none generated that are relevant in the linking operation. A challenge to supporting such associated statements is that the linker operates on "declare" expressions, and replaces those expressions with other expressions. It does not have the capability to append statements after the whole type. The linker actually faces this challenge with statements from the `ConstantPool` as well, and solves this problem by generating an IIFE expression that executes the statements and then returns the definition expression. Previously, an `EmitScope` processed the definition and converted it to an expression, as well as collected constant statements from a `ConstantPool`. A special `IifeEmitScope` implementation was used when emitting into a context where top-level constant statements couldn't be added at all, and uses the IIFE strategy in this case. This commit adds blanket support for associated statements to the linker using this IIFE strategy. The main `EmitScope` now uses the IIFE strategy to emit associated statements, and `IifeEmitScope` has been renamed to `LocalEmitScope`. Now, the `LocalEmitScope` represents constant statements as associated statements to the main `EmitScope` implementation, so they get included in the IIFE as well. Tests are adjusted/added to cover this new behavior. This is a refactoring commit because no live generated code is affected - there are no cases where associated statements are present in linked definitions today. PR Close #45024 |
||
|---|---|---|
| .. | ||
| ast | ||
| file_linker | ||
| BUILD.bazel | ||
| fatal_linker_error_spec.ts | ||
| linker_import_generator_spec.ts | ||