angular-cn/packages/compiler-cli/test
JoostK fed6a7ce7d perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.

Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:

1. The file dependency graph is used to determine whether it is safe to
   reuse the analysis data of an Angular decorated class. This analysis
   data is invariant to unrelated changes to the NgModule scope, but
   because the single dependency graph also tracked the implicit
   NgModule dependencies the compiler had to consider analysis data as
   stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
   public API—its selector, inputs, outputs, or exportAs clause—in which
   case there is no need to re-emit all declarations in scope, as their
   compilation output wouldn't have changed.

This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.

Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.

These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.

This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.

Fixes #34867
Fixes #40635
Closes #40728

PR Close #40947
2021-03-08 08:41:19 -08:00
..
compliance refactor(compiler): retrieve variables from context inside nested template listener (#40833) 2021-02-17 11:45:46 -08:00
compliance_old refactor(compiler): retrieve variables from context inside nested template listener (#40833) 2021-02-17 11:45:46 -08:00
diagnostics feat(compiler-cli): add support for TypeScript 4.0 (#38076) 2020-08-24 13:06:59 -07:00
metadata build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ngtsc perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947) 2021-03-08 08:41:19 -08:00
transformers fix(compiler-cli): update type castings for JSON.parse usage (#40710) 2021-02-09 10:48:43 -08:00
BUILD.bazel fix(compiler-cli): `readConfiguration` existing options should override options in tsconfig (#40694) 2021-02-11 13:29:51 -08:00
extract_i18n_spec.ts refactor(compiler): `element.sourceSpan` should span the `outerHTML` (#38581) 2020-09-02 14:47:31 -07:00
mocks.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ngc_spec.ts build: support building with TypeScript 4.1 (#39571) 2020-11-25 11:10:01 -08:00
perform_compile_spec.ts fix(compiler-cli): extend `angularCompilerOptions` in tsconfig from node (#40694) 2021-02-11 13:29:51 -08:00
perform_watch_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
test_support.ts test(compiler-cli): move testing utils to separate package (#39594) 2020-11-17 11:59:56 -08:00
typescript_support_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00