refactor(ivy): extract import rewriting into a separate interface (#27998)

Currently the ImportManager class handles various rewriting actions of
imports when compiling @angular/core. This is required as code compiled
within @angular/core cannot import from '@angular/core'. To work around
this, imports are rewritten to get core symbols from a particular file,
r3_symbols.ts.

In this refactoring, this rewriting logic is moved out of the ImportManager
and put behind an interface, ImportRewriter. There are three implementers
of the interface:

* NoopImportRewriter, used for compiling all non-core packages.
* R3SymbolsImportRewriter, used when ngtsc compiles @angular/core.
* NgccFlatImportRewriter, used when ngcc compiles @angular/core (special
  logic is needed because ngcc has to rewrite imports in flat bundles
  differently than in non-flat bundles).

This is a precursor to using this rewriting logic in other contexts besides
the ImportManager.

PR Close #27998
This commit is contained in:
Alex Rickabaugh
2019-01-08 11:49:58 -08:00
committed by Andrew Kushnir
parent 5a0deb8d69
commit 3cf1b62722
15 changed files with 222 additions and 95 deletions

View File

@ -14,8 +14,9 @@
* compiler writes imports to this file.
*
* Only a subset of such imports are supported - core is not allowed to declare components or pipes.
* A check in ngtsc's translator.ts validates this condition. The translator is responsible for
* translating an external name (prefixed with ɵ) to the internal symbol name as exported below.
* A check in ngtsc's `R3SymbolsImportRewriter` validates this condition. The rewriter is only used
* when compiling @angular/core and is responsible for translating an external name (prefixed with
* ɵ) to the internal symbol name as exported below.
*
* The below symbols are used for @Injectable and @NgModule compilation.
*/