80f4ff3338
This commit causes imports added by ngtsc's `ImportManager` to have their TypeScript "original node" set to the generated `ts.ImportDeclaration` statement. In g3, the tsickle transformer runs after the Angular transformer and post- processes Angular's compilation output. One of its post-processing tasks is to transform generated imports and references to imported symbols from the commonjs module system to the g3 module system. Part of this transformation involves recognizing modules with specific metadata and altering references to symbols from those modules accordingly. Normally, tsickle can rely on TypeScript's binding for an imported symbol to find its origin module and thus the correct metadata for the symbol. However the Angular transform generates new synthetic imports which don't have such binding information. Angular's imports are always namespace imports of the form: ``` import * as qualifier 'module/specifier'; ``` References to such an import are then of the form `qualifier.SymbolName`. To process such imports properly, tsickle needs to be able to associate the reference to `qualifier` in the expression `qualifer.SymbolName` with the `ts.ImportDeclaration` statement that defines it. It expects to do this by looking at the `ts.getOriginalNode()` for the `qualifier` reference, which should be the `ts.ImportDeclaration`. This commit changes ngtsc's import generation mechanism to set the original node on `qualifier` identifiers according to this expectation. This commit is not tested in the direct compiler tests, since: 1) there is no observable behavior externally from setting the original node 2) we don't have tests that intercept transformer operations (which could be used to directly assert against the AST nodes) 3) tsickle's published version does not (yet) contain the g3-specific transformations which rely on the original node and would thus allow the behavior to be observed. Instead, we rely on the g3 testing suite to validate the correctness of this fix. Breaking this functionality would cause g3 compilation errors for targets, since tsickle would be unable to transform imports correctly. PR Close #40711 |
||
---|---|---|
.. | ||
src | ||
test | ||
BUILD.bazel | ||
README.md | ||
index.ts | ||
main-ivy-ngcc.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/ngcc
Unit Testing
The unit tests are built and run using Bazel:
yarn bazel test //packages/compiler-cli/ngcc/test
Integration Testing
There are tests that check the behavior of the overall executable:
yarn bazel test //packages/compiler-cli/ngcc/test:integration