angular-docs-cn/packages/compiler-cli/ngcc/test
Alex Rickabaugh 80f4ff3338 fix(compiler-cli): set TS original node on imported namespace identifiers (#40711)
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
2021-02-11 15:58:25 -08:00
..
analysis fix(compiler-cli): remove the concept of an errored trait (#39923) 2020-12-03 13:42:13 -08:00
dependencies test(compiler-cli): move testing utils to separate package (#39594) 2020-11-17 11:59:56 -08:00
entry_point_finder fix(compiler-cli): update type castings for JSON.parse usage (#40710) 2021-02-09 10:48:43 -08:00
execution fix(ngcc): ensure lockfile is removed when analyzeFn fails (#37739) 2020-06-29 10:29:11 -07:00
helpers refactor(compiler-cli): update to use new file-system interfaces (#40281) 2021-01-08 09:34:44 -08:00
host fix(compiler-cli): remove the concept of an errored trait (#39923) 2020-12-03 13:42:13 -08:00
integration fix(compiler-cli): update type castings for JSON.parse usage (#40710) 2021-02-09 10:48:43 -08:00
locking fix(compiler-cli): ngcc - remove outdated link (#40285) 2021-01-06 07:10:39 -08:00
migrations test(compiler-cli): move testing utils to separate package (#39594) 2020-11-17 11:59:56 -08:00
packages fix(compiler-cli): update type castings for JSON.parse usage (#40710) 2021-02-09 10:48:43 -08:00
rendering fix(compiler-cli): set TS original node on imported namespace identifiers (#40711) 2021-02-11 15:58:25 -08:00
writing fix(compiler-cli): update type castings for JSON.parse usage (#40710) 2021-02-09 10:48:43 -08:00
BUILD.bazel fix(compiler-cli): update ngcc integration tests for latest changes in rules_nodejs (#40710) 2021-02-09 10:48:43 -08:00
ngcc_options_spec.ts perf(ngcc): reduce maximum worker count (#38840) 2020-09-15 11:23:09 -07:00
utils_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00