Skip to content
Snippets Groups Projects
This project is mirrored from https://github.com/angular/angular.git. Pull mirroring updated .
  1. May 08, 2020
    • Alex Rickabaugh's avatar
    • Alex Rickabaugh's avatar
      77d8afb7
    • Alex Rickabaugh's avatar
      fix(compiler-cli): don't try to tag non-ts files as shims (#36987) · 42d1091d
      Alex Rickabaugh authored
      Some projects include .js source files (via the TypeScript allowJs option).
      Previously, the compiler would attempt to tag these files for shims, which
      caused errors as the regex used to create shim filenames assumes a .ts file.
      This commit fixes the bug by filtering out non-ts files during tagging.
      
      PR Close #36987
      42d1091d
    • Paul Gschwendtner's avatar
      fix(compiler): remove outdated and invalid warning for unresolved DI parameters (#36985) · d0280a03
      Paul Gschwendtner authored
      In past versions of the View Engine compiler, we added a warning that is
      printed whenever the compiler comes across an Angular declaration with a
      constructor that does not match suitable DI tokens. The warning mentioned
      that in `v6.x` it will turn into an actual error.
      
      This actually happened as expected for most cases. e.g. the constructor
      of `@NgModule`, `@Component`'s, `@Pipe`'s etc will be checked and an error
      will be reported if constructor is not DI compatible.
      
      The warning has never been removed though as it was still relevant for
      unprovided injectables, or injectables serialized into summaries of the
      Angular compiler.
      
      As of version 10, classes that use Angular features need an Angular decorator.
      This includes base classes of services that use the lifecycles Angular feature.
      Due to this being a common pattern now, we can remove the warning in
      View Engine. The warning is not correct, and also quite confusing as it
      mentions the planned removal in `v6.x`.
      
      Resolves FW-2147.
      
      PR Close #36985
      d0280a03
    • Tidi's avatar
      fix(forms): number input fires valueChanges twice. (#36087) · 97d6d909
      Tidi authored
      Prior to this commit, number input fields would to fire valueChanges twice: once for `input` events when typing and second for the `change` event when the field lost focus (both events happen at once when using the increment and decrement buttons on the number field).
      
      Fixes #12540
      
      BREAKING CHANGE: Number inputs no longer listen to the `change` event.
      * Tests which trigger `change` events need to be updated to trigger `input` events instead.
      * The `change` event was in place to support IE9, as we found that `input` events were not fired with backspace or cut actions. If you need to maintain IE9 support, you will need to add a change event listener to number inputs and call the `onChange` method of `NumberValueAccessor` manually.
      * Lastly, old versions of WebDriver would synthetically trigger the `change` event on `WebElement.clear` and `WebElement.sendKeys`. If you are using an old version of WebDriver, you may need to update tests to ensure `input` events are triggered. For example, you could use `element.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE);` in place of `element.clear()`.
      
      PR Close #12540
      
      PR Close #36087
      97d6d909
  2. May 07, 2020
    • Pete Bacon Darwin's avatar
      test(compiler-cli): ensure reflection tests are not brittle to case-sensitivity (#36859) · f7815cf9
      Pete Bacon Darwin authored
      These tests were matching file-paths against what is retrieved from the
      TS compiler. But the TS compiler paths have been canonicalised, so the
      tests were brittle on case-insensitive file-systems.
      
      PR Close #36859
      f7815cf9
    • Pete Bacon Darwin's avatar
      test(compiler-cli): ensure partial-evaluator tests are not brittle to case-sensitivity (#36859) · 9e43e490
      Pete Bacon Darwin authored
      These tests were matching file-paths against what is retrieved from the
      TS compiler. But the TS compiler paths have been canonicalised, so the
      tests were brittle on case-insensitive file-systems.
      
      PR Close #36859
      9e43e490
    • Pete Bacon Darwin's avatar
      test(compiler-cli): ensure indexer tests are not brittle to case-sensitivity (#36859) · 8ce38cac
      Pete Bacon Darwin authored
      These tests were matching file-paths against what is retrieved from the
      TS compiler. But the TS compiler paths have been canonicalised, so the
      tests were brittle on case-insensitive file-systems.
      
      PR Close #36859
      8ce38cac
    • Pete Bacon Darwin's avatar
      fix(compiler-cli): use CompilerHost to ensure canonical file paths (#36859) · a10c1266
      Pete Bacon Darwin authored
      The type checking infrastrure uses file-paths that may come from the
      TS compiler. Such paths will have been canonicalized, and so the type
      checking classes must also canonicalize paths when matching.
      
      PR Close #36859
      a10c1266
    • Pete Bacon Darwin's avatar
      fix(compiler-cli): normalize mock Windows file paths correctly (#36859) · b682bd19
      Pete Bacon Darwin authored
      Since the `MockFileSystemWindows` is case-insensitive, any
      drive path that must be added to a normalized path should be lower
      case to make the path canonical.
      
      PR Close #36859
      b682bd19
    • Pete Bacon Darwin's avatar
      fix(compiler-cli): ensure `MockFileSystem` handles case-sensitivity (#36859) · 26eacd4f
      Pete Bacon Darwin authored
      Previously this class used the file passed in directly to look up files in the
      in-memory mock file-system. But this doesn't match the behaviour of
      case-insensitive file-systems. Now the look up is done on the canonical
      file paths.
      
      PR Close #36859
      26eacd4f
    • Pete Bacon Darwin's avatar
      fix(compiler-cli): `isCaseSensitive()` returns correct value (#36859) · fc4741f6
      Pete Bacon Darwin authored
      Previously this method was returning the exact opposite value
      than the correct one.
      Also, calling `this.exists()` causes an infinite recursions,
      so the actual file-system `fs.existsSync()` method is used
      to ascertain the case-sensitivity of the file-system.
      
      PR Close #36859
      fc4741f6
    • Pete Bacon Darwin's avatar
      fix(compiler-cli): ensure `getRootDirs()` handles case-sensitivity (#36859) · 3f3e9b75
      Pete Bacon Darwin authored
      Previously the `getRootDirs()` function was not converting
      the root directory paths to their canonical form, which can
      cause problems on case-insensitive file-systems.
      
      PR Close #36859
      3f3e9b75
    • Pete Bacon Darwin's avatar
      fix(compiler-cli): ensure LogicalFileSystem handles case-sensitivity (#36859) · 53a8459d
      Pete Bacon Darwin authored
      The `LogicalFileSystem` was not taking into account the
      case-sensitivity of the file-system when caching logical
      file paths.
      
      PR Close #36859
      53a8459d
    • Pete Bacon Darwin's avatar
      fix(compiler-cli): fix case-sensitivity issues in NgtscCompilerHost (#36859) · 0ec0ff3b
      Pete Bacon Darwin authored
      The `getCanonicalFileName()` method was not actually
      calling the  `useCaseSensitiveFileNames()` method. So
      it always returned a case-sensitive canonical filename.
      
      PR Close #36859
      0ec0ff3b
    • Paul Gschwendtner's avatar
      ci: update components-repo-unit-tests job commit (#36921) · f930e75a
      Paul Gschwendtner authored
      Updates the `components-repo-unit-tests` job to
      https://github.com/angular/components/commit/d3a9ac67d2ef89ca9570c73af41111c796c135ca.
      
      We need to update since we added a new diagnostic in ngtsc, and
      the given commit in the components repo fixes failures caused by
      the new diagnostic.
      
      Note: This commit currently points to a PR as it's unlikely that
      this fix lands soon, but we want to move forward. There is no
      downside to doing that as the PR is based on top of the latest
      components repo `master`.
      
      PR Close #36921
      f930e75a
    • Paul Gschwendtner's avatar
      build(docs-infra): do not require abstract directives to declare a @ngModule (#36921) · 854bd7d0
      Paul Gschwendtner authored
      Abstract directives cannot be part of a `@NgModule`, but the AIO dgeni
      setup currently enforces this. This commit updates the logic so that
      abstract directives are skipped.
      
      PR Close #36921
      854bd7d0
    • Paul Gschwendtner's avatar
      refactor: fix undecorated classes with angular features in repo (#36921) · e17fe90a
      Paul Gschwendtner authored
      A few instances of undecorated classes with Angular features
      have been discovered in the framework repo. This commit fixes
      those.
      
      PR Close #36921
      e17fe90a
    • Paul Gschwendtner's avatar
      refactor: enable ng update migrations for v10 (#36921) · 0577bf0e
      Paul Gschwendtner authored
      Enables the `ng update` migrations for v10. Status for individual
      migrations:
      
      **undecorated-classes-with-di**.
      
      This migration dealt exlusively with inherited constructors and
      cases where a derived component was undecorated. In those cases,
      the migration added `@Directive()` or copied the inherited decorator
      to the derived class.
      
      We don't need to run this migration again because ngtsc throws if
      constructor is inherited from an undecorated class. Also ngtsc will
      throw if a NgModule references an undecorated class in the declarations.
      
      ***undecorated-classes-with-decorated-fields***
      
      This migration exclusively deals with undecorated classes that use
      Angular features but are not decorated. Angular features include
      the use of lifecycle hooks or class fields with Angular decorators,
      such as `@Input()`.
      
      We want to re-run this migration in v10 as we will disable the
      compatibility code in ngtsc that detects such undecorated classes
      as `@Directive`.
      
      **module-with-providers**:
      
      This migration adds an explicit generic type to `ModuleWithProviders`.
      As of v10, the generic type is required, so we need to re-run the
      migration again.
      
      **renderer-to-renderer2**:
      
      We don't need to re-run that migration again as the
      renderer has been already removed in v9.
      
      **missing-injectable**:
      
      This migration is exclusively concerned with undecorated
      providers referenced in an `NgModule`. We should re-run
      that migration again as we don't have proper backsliding
      prevention for this yet. We can consider adding an error
      in ngtsc for v10, or v11. In either way, we should re-run
      the migration.
      
      **dynamic-queries**:
      
      We ran this one in v9 to reduce code complexity in projects. Instead
      of explicitly passing `static: false`, not passing any object literal
      has the same semantics. We don't need to re-run the migration again
      since there is no good way to prevent backsliding and we cannot always
      run this migration for future versions (as some apps might actually
      intentionally use the explicit `static: false` option).
      
      PR Close #36921
      0577bf0e
    • Paul Gschwendtner's avatar
      feat(compiler-cli): report error if undecorated class with Angular features is discovered (#36921) · 4c92cf43
      Paul Gschwendtner authored
      Previously in v9, we deprecated the pattern of undecorated base classes
      that rely on Angular features. We ran a migration for this in version 9
      and will run the same on in version 10 again.
      
      To ensure that projects do not regress and start using the unsupported
      pattern again, we report an error in ngtsc if such undecorated classes
      are discovered.
      
      We keep the compatibility code enabled in ngcc so that libraries
      can be still be consumed, even if they have not been migrated yet.
      
      Resolves FW-2130.
      
      PR Close #36921
      4c92cf43
    • Paul Gschwendtner's avatar
      feat(core): undecorated-classes-with-decorated-fields migration should handle... · c6ecdc9a
      Paul Gschwendtner authored
      feat(core): undecorated-classes-with-decorated-fields migration should handle classes with lifecycle hooks (#36921)
      
      As of v10, undecorated classes using Angular features are no longer
      supported. In v10, we plan on removing the undecorated classes
      compatibility code in ngtsc. This means that old patterns for
      undecorated classes will result in compilation errors.
      
      We had a migration for this in v9 already, but it looks like
      the migration does not handle cases where classes uses lifecycle
      hooks. This is handled in the ngtsc compatibility code, and we
      should handle it similarly in migrations too.
      
      This has not been outlined in the migration plan initially,
      but an appendix has been added for v10 to the plan document.
      
      https://hackmd.io/vuQfavzfRG6KUCtU7oK_EA?both.
      
      Note: The migration is unable to determine whether a given undecorated
      class that only defines `ngOnDestroy` is a directive or an actual
      service. This means that in some cases the migration cannot do
      more than adding a TODO and printing an failure.
      
      Certainly there are more ways to determine the type of such classes,
      but it would involve metadata and NgModule analysis. This is out of
      scope for this migration.
      
      PR Close #36921
      c6ecdc9a
    • Kara Erickson's avatar
      refactor(core): make generic mandatory for ModuleWithProviders (#36892) · 20cc3ab3
      Kara Erickson authored
      In v9, we deprecated the use of ModuleWithProviders
      without a generic. In v10, we will be requiring the
      generic when using ModuleWithProviders. You can read
      more about the reasoning behind this change in the
      migration guide:
      http://v9.angular.io/guide/migration-module-with-providers
      
      PR Close #36892
      20cc3ab3
    • Matias Niemelä's avatar
      refactor: disable sanitization for [style] and [style.prop] bindings (#35621) · 420b9be1
      Matias Niemelä authored
      This patch is the first of many commits to disable sanitization for
      [stlye.prop] and [style] bindings in Angular.
      
      Historically, style-based sanitization has only been required for old
      IE browsers (IE6 and IE7). Since Angular does not support these old
      browsers at all, there is no reason for the framework to support
      style-based sanitization.
      
      PR Close #35621
      420b9be1
    • Igor Minar's avatar
      docs: remove the note about @angular/http from the deprecations guide (#36944) · 3c6c00d1
      Igor Minar authored
      We stopped publishing @angular/http to npm a while back (v7?), so from the perspective of our
      customer @angular/http has been removed a long time ago and mentioninig it now that we actually
      removed the code from our repo is just confusing.
      
      PR Close #36944
      3c6c00d1
    • Igor Minar's avatar
      test(docs-infra): temporarily disable the 'upgrade-phonecat-2-hybrid' docs example test (#36944) · 6fa36e38
      Igor Minar authored
      This is due to issue described in: https://github.com/angular/angular/issues/36957
      
      This commit works around the problem rather than trying to solve it in order to unblock the big APF v10 change.
      
      PR Close #36944
      6fa36e38
    • Paul Gschwendtner's avatar
      test: disable ng_package tests in ivy test jobs (#36944) · 9bde1be5
      Paul Gschwendtner authored
      Since we no longer hardcode the `package.json` for
      entry-points, a bug has appeared for `ng_package` in Ivy.
      
      The `package.json` files are populated incorrectly with Ivy
      as the flat module bundle name is not propagated from `ng_module`
      to the `ng_package` rule. The rule then guesses the index file
      to `index.js` and does not respect the flat module bundle shim.
      
      PR Close #36944
      9bde1be5
    • Paul Gschwendtner's avatar
      build: update side-effects integration test to not expect esm5 output (#36944) · 040253c4
      Paul Gschwendtner authored
      As mentioned in previous commits, as of v10 the release output
      does no longer contain ESM5 output due to an update to the APF.
      
      This means that the side-effect integration test needs to be
      updated as it currently expects/tests esm5 output.
      
      PR Close #36944
      040253c4
    • Paul Gschwendtner's avatar
      feat(ngcc): support for new APF where `module` points to esm2015 output (#36944) · c98a4d6d
      Paul Gschwendtner authored
      As of version 10, libraries following the APF will no longer contain
      ESM5 output. Hence, tests in ngcc need to be updated as they currently
      rely on the release output of `@angular/core`.
      
      Additionally, we'd need to support in ngcc that the `module`
      property of entry-points no longer necessarily refers to
      `esm5` output, but instead can also target `esm2015`.
      
      We currently achieve this by checking the path the `module`
      property points to. We can do this because as per APF, the
      folder name is known for the esm2015 output. Long-term for
      more coverage, we want to sniff the format by looking for
      known ES2015 constructs in the file `module` refers to.
      
      PR Close #36944
      c98a4d6d
    • Paul Gschwendtner's avatar
      fix(bazel): ng_package rule should update "package.json" of ts_library targets (#36944) · d5293d2a
      Paul Gschwendtner authored
      In the past we added support for `ts_library` to `ng_package`. For those
      targets we never can determine the "index" file. Unlike `ng_module`,
      there is no provider data for flat module bundles, so the `ng_package`
      rule assumes that the index file is simply called `index`.
      
      This works as expected, but we also added logic in the past that doesn't
      allow `ng_package` to add format properties (e.g. `main`, `module`) to a
      `package.json` if a package json is handwritten for such a `ts_library` target.
      
      This has been done that way because we assumed that such `package.json` files
      might want to set format properties explicitly to different paths due to a
      faulty "index" guess.
      
      We want to change this behavior as most of the time a `package.json`
      file already exists with just the module name. In those cases, the
      packager should still set the format properties. We should only warn
      and skip automatic insertion of the format properties if such a
      `package.json` explicitly sets format properties.
      
      PR Close #36944
      d5293d2a
    • Igor Minar's avatar
      build: simplify package.jsons for all of our packages (#36944) · d578ab8f
      Igor Minar authored
      We can remove all of the entry point resolution configuration from the package.json
      in our source code as ng_package rule adds the properties automatically and correctly
      configures them.
      
      This change simplifies our code base but doesn't have any impact on the package.json
      in the distributed npm_packages.
      
      PR Close #36944
      d578ab8f
    • Igor Minar's avatar
      feat(bazel): simplify ng_package by dropping esm5 and fesm5 (#36944) · 9dbb30f8
      Igor Minar authored
      esm5 and fesm5 are no longer needed and have been deprecated in the past.
      
      https://v9.angular.io/guide/deprecations#esm5-and-fesm5-code-formats-in-angular-npm-packages
      
      This commit modifies ng_package to no longer distribute these two formats in npm packages
      built by ng_package (e.g. @angular/core).
      
      This commit intentionally doesn't fully clean up the ng_package rule to remove all traces of esm5 and fems5
      build artifacts as that is a bigger cleanup and currently we are narrowing down the scope of this change
      to the MVP needed for v10, which in this case is 'do not put esm5 and fesm5' into the npm packages.
      
      More cleanup to follow: https://angular-team.atlassian.net/browse/FW-2143
      
      BREAKING CHANGE: esm5 and fesm5 format is no longer distributed in
      Angular's npm packages e.g. @angular/core
      
      If you are not using Angular CLI to build your application or library,
      and you need to be able to build es5 artifacts, then you will need to
      downlevel the distributed Angular code to es5 on your own.
      
      Angular CLI will automatically downlevel the code to es5 if differential
      loading is enabled in the Angular project, so no action is required from
      Angular CLI users.
      
      PR Close #36944
      9dbb30f8
    • Pete Bacon Darwin's avatar
      fix(ngcc): support ModuleWithProviders functions that delegate (#36948) · fafa50d9
      Pete Bacon Darwin authored
      In #36892 the `ModuleWithProviders` type parameter becomes required.
      This exposes a bug in ngcc, where it can only handle functions that have a
      specific form:
      
      ```
      function forRoot() {
        return { ... };
      }
      ```
      
      In other words, it only accepts functions that return an object literal.
      
      In some libraries, the function instead returns a call to another function.
      For example in `angular-in-memory-web-api`:
      
      ```
      InMemoryWebApiModule.forFeature = function (dbCreator, options) {
        return InMemoryWebApiModule_1.forRoot(dbCreator, options);
      };
      ```
      
      This commit changes the parsing of such functions to use the
      `PartialEvaluator`, which can evaluate these more complex function
      bodies.
      
      PR Close #36948
      fafa50d9
    • Pete Bacon Darwin's avatar
      refactor(ngcc): move `getModuleWithProvidersFunctions()` into the analyzer (#36948) · e010f2ca
      Pete Bacon Darwin authored
      Previously this method was implemented on the `NgccReflectionHost`,
      but really it is asking too much of the host, since it actually needs to do
      some static evaluation of the code to be able to support a wider range
      of function shapes. Also there was only one implementation of the method
      in the `Esm2015ReflectionHost` since it has no format specific code in
      in.
      
      This commit moves the whole function (and supporting helpers) into the
      `ModuleWithProvidersAnalyzer`, which is the only place it was being used.
      This class will be able to do further static evaluation of the function bodies
      in order to support more function shapes than the host can do on its own.
      
      The commit removes a whole set of reflection host tests but these are
      already covered by the tests of the analyzer.
      
      PR Close #36948
      e010f2ca
    • Misko Hevery's avatar
      refactor(core): deprecate `WrappedValue` (#36819) · c9e0db55
      Misko Hevery authored
      The purpose of the `WrappedValue` is to allow same object instance to be treated as different for the purposes of change detection. It is currently used with `async` pipe and only with `Observables`. The use case which it covers is if the `Observable` produces the same instance of the value but it is desirable to still try to mark it as changed for the purposes of change detection.
      
      We believe tha the above use case is too rare to warrant special handling in the framework. (Having special handling causes application slowdown for the users and mental load for the developers.) No replacement is planned for this deprecation.
      
      PR Close #36819
      c9e0db55
  3. May 06, 2020
    • Alex Rickabaugh's avatar
      perf(compiler-cli): perform template type-checking incrementally (#36211) · ecffc355
      Alex Rickabaugh authored
      This optimization builds on a lot of prior work to finally make type-
      checking of templates incremental.
      
      Incrementality requires two main components:
      - the ability to reuse work from a prior compilation.
      - the ability to know when changes in the current program invalidate that
        prior work.
      
      Prior to this commit, on every type-checking pass the compiler would
      generate new .ngtypecheck files for each original input file in the program.
      
      1. (Build #1 main program): empty .ngtypecheck files generated for each
         original input file.
      
      2. (Build #1 type-check program): .ngtypecheck contents overridden for those
         which have corresponding components that need type-checked.
      
      3. (Build #2 main program): throw away old .ngtypecheck files and generate
         new empty ones.
      
      4. (Build #2 type-check program): same as step 2.
      
      With this commit, the `IncrementalDriver` now tracks template type-checking
      _metadata_ for each input file. The metadata contains information about
      source mappings for generated type-checking code, as well as some
      diagnostics which were discovered at type-check analysis time. The actual
      type-checking code is stored in the TypeScript AST for type-checking files,
      which is now re-used between programs as follows:
      
      1. (Build #1 main program): empty .ngtypecheck files generated for each
         original input file.
      
      2. (Build #1 type-check program): .ngtypecheck contents overridden for those
         which have corresponding components that need type-checked, and the
         metadata registered in the `IncrementalDriver`.
      
      3. (Build #2 main program): The `TypeCheckShimGenerator` now reuses _all_
         .ngtypecheck `ts.SourceFile` shims from build #1's type-check program in
         the construction of build #2's main program. Some of the contents of
         these files might be stale (if a component's template changed, for
         example), but wholesale reuse here prevents unnecessary changes in the
         contents of the program at this point and makes TypeScript's job a lot
         easier.
      
      4. (Build #2 type-check program): For those input files which have not
         "logically changed" (meaning components within are semantically the same
         as they were before), the compiler will re-use the type-check file
         metadata from build #1, and _not_ generate a new .ngtypecheck shim.
         For components which have logically changed or where the previous
         .ngtypecheck contents cannot otherwise be reused, code generation happens
         as before.
      
      PR Close #36211
      ecffc355
    • Alex Rickabaugh's avatar
      perf(compiler-cli): split Ivy template type-checking into multiple files (#36211) · b861e9c0
      Alex Rickabaugh authored
      As a performance optimization, this commit splits the single
      __ngtypecheck__.ts file which was previously added to the user's program as
      a container for all template type-checking code into multiple .ngtypecheck
      shim files, one for each original file in the user's program.
      
      In larger applications, the generation, parsing, and checking of this single
      type-checking file was a huge performance bottleneck, with the file often
      exceeding 1 MB in text content. Particularly in incremental builds,
      regenerating this single file for the entire application proved especially
      expensive.
      
      This commit introduces a new strategy for template type-checking code which
      makes use of a new interface, the `TypeCheckingProgramStrategy`. This
      interface abstracts the process of creating a new `ts.Program` to type-check
      a particular compilation, and allows the mechanism there to be kept separate
      from the more complex logic around dealing with multiple .ngtypecheck files.
      
      A new `TemplateTypeChecker` hosts that logic and interacts with the
      `TypeCheckingProgramStrategy` to actually generate and return diagnostics.
      The `TypeCheckContext` class, previously the workhorse of template type-
      checking, is now solely focused on collecting and generating type-checking
      file contents.
      
      A side effect of implementing the new `TypeCheckingProgramStrategy` in this
      way is that the API is designed to be suitable for use by the Angular
      Language Service as well. The LS also needs to type-check components, but
      has its own method for constructing a `ts.Program` with type-checking code.
      
      Note that this commit does not make the actual checking of templates at all
      _incremental_ just yet. That will happen in a future commit.
      
      PR Close #36211
      b861e9c0
    • Alex Rickabaugh's avatar
      fix(compiler): switch to 'referencedFiles' for shim generation (#36211) · 4213e8d5
      Alex Rickabaugh authored
      Shim generation was built on a lie.
      
      Shims are files added to the program which aren't original files authored by
      the user, but files authored effectively by the compiler. These fall into
      two categories: files which will be generated (like the .ngfactory shims we
      generate for View Engine compatibility) as well as files used internally in
      compilation (like the __ng_typecheck__.ts file).
      
      Previously, shim generation was driven by the `rootFiles` passed to the
      compiler as input. These are effectively the `files` listed in the
      `tsconfig.json`. Each shim generator (e.g. the `FactoryGenerator`) would
      examine the `rootFiles` and produce a list of shim file names which it would
      be responsible for generating. These names would then be added to the
      `rootFiles` when the program was created.
      
      The fatal flaw here is that `rootFiles` does not always account for all of
      the files in the program. In fact, it's quite rare that it does. Users don't
      typically specify every file directly in `files`. Instead, they rely on
      TypeScript, during program creation, starting with a few root files and
      transitively discovering all of the files in the program.
      
      This happens, however, during `ts.createProgram`, which is too late to add
      new files to the `rootFiles` list.
      
      As a result, shim generation was only including shims for files actually
      listed in the `tsconfig.json` file, and not for the transitive set of files
      in the user's program as it should.
      
      This commit completely rewrites shim generation to use a different technique
      for adding files to the program, inspired by View Engine's shim generator.
      In this new technique, as the program is being created and `ts.SourceFile`s
      are being requested from the `NgCompilerHost`, shims for those files are
      generated and a reference to them is patched onto the original file's
      `ts.SourceFile.referencedFiles`. This causes TS to think that the original
      file references the shim, and causes the shim to be included in the program.
      The original `referencedFiles` array is saved and restored after program
      creation, hiding this little hack from the rest of the system.
      
      The new shim generation engine differentiates between two kinds of shims:
      top-level shims (such as the flat module entrypoint file and
      __ng_typecheck__.ts) and per-file shims such as ngfactory or ngsummary
      files. The former are included via `rootFiles` as before, the latter are
      included via the `referencedFiles` of their corresponding original files.
      
      As a result of this change, shims are now correctly generated for all files
      in the program, not just the ones named in `tsconfig.json`.
      
      A few mitigating factors prevented this bug from being realized until now:
      
      * in g3, `files` does include the transitive closure of files in the program
      * in CLI apps, shims are not really used
      
      This change also makes use of a novel technique for associating information
      with source files: the use of an `NgExtension` `Symbol` to patch the
      information directly onto the AST object. This is used in several
      circumstances:
      
      * For shims, metadata about a `ts.SourceFile`'s status as a shim and its
        origins are held in the extension data.
      * For original files, the original `referencedFiles` are stashed in the
        extension data for later restoration.
      
      The main benefit of this technique is a lot less bookkeeping around `Map`s
      of `ts.SourceFile`s to various kinds of data, which need to be tracked/
      invalidated as part of incremental builds.
      
      This technique is based on designs used internally in the TypeScript
      compiler and is serving as a prototype of this design in ngtsc. If it works
      well, it could have benefits across the rest of the compiler.
      
      PR Close #36211
      4213e8d5
    • Alex Rickabaugh's avatar
      fix(compiler-cli): fix bug tracking indirect NgModule dependencies (#36211) · bab90a77
      Alex Rickabaugh authored
      The compiler needs to track the dependencies of a component, including any
      NgModules which happen to be present in a component's scope. If an upstream
      NgModule changes, any downstream components need to have their templates
      re-compiled and re-typechecked.
      
      Previously, the compiler handled this well for the A -> B -> C case where
      module A imports module B which re-exports module C. However, it fell apart
      in the A -> B -> C -> D case, because previously tracking focused on changes
      to components/directives in the scope, and not NgModules specifically.
      
      This commit introduces logic to track which NgModules contributed to a given
      scope, and treat them as dependencies of any components within.
      
      This logic also contains a bug, which is intentional for now. It
      purposefully does not track transitive dependencies of the NgModules which
      contribute to a scope. If it did, using the current dependency system, this
      would treat all components and directives (even those not exported into the
      scope) as dependencies, causing a major performance bottleneck. Only those
      dependencies which contributed to the module's export scope should be
      considered, but the current system is incapable of making this distinction.
      This will be fixed at a later date.
      
      PR Close #36211
      bab90a77
    • Keen Yee Liau's avatar
      test(language-service): [ivy] Add mock service to overwrite files (#36923) · da79e043
      Keen Yee Liau authored
      Add a mechanism to replace file contents for a specific file. This
      allows us to write custom test scenarios in code without modifying the
      test project.
      
      Since we are no longer mocking the language service host, the file
      overwrite needs to happen via the project service.
      Project service manages a set of script infos, and overwriting the files
      is a matter of updating the relevant script infos.
      
      Note that the actual project service is wrapped inside a Mock Service.
      Tests should not have direct access to the project service. All
      manipulations should take place via the Mock Service.
      
      The MockService provides a `reset()` method to undo temporary overwrites
      after each test.
      
      PR Close #36923
      da79e043
    • George Kalpakas's avatar
      refactor(docs-infra): take advantage of latest Jasmine features in preview server tests (#36837) · 1b8752e5
      George Kalpakas authored
      This commit updates the preview server tests to take advantage of
      features supported in the latest version of Jasmine that were not
      supported when the rests were first written.
      
      Changes include:
      
      - Use [async/await] in tests.
      - Use the new [toBeInstanceOf()] and [toHaveBeenCalledBefore()] matchers.
      - Use the new [toBeResolved()] and [toBeRejected()] async matchers (and
        their variants).
      - Use the new [withArgs()] method of `Spy` to simplify "trained"
        responses.
      - Use the new [resolveTo()]/[rejectWith()] methods of `SpyStrategy` (and
        their variants) to simplify promise-based spies.
      - Implement custom async matchers (via [addAsyncMatchers()]) to simplify
        certain tests.
      
      [addAsyncMatchers()]: https://jasmine.github.io/api/3.5/jasmine.html#.addAsyncMatchers
      [async/await]: https://jasmine.github.io/tutorials/async
      [rejectWith()]: https://jasmine.github.io/api/3.5/SpyStrategy.html#rejectWith
      [resolveTo()]: https://jasmine.github.io/api/3.5/SpyStrategy.html#resolveTo
      [toBeInstanceOf()]: https://jasmine.github.io/api/3.5/matchers.html#toBeInstanceOf
      [toBeRejected()]: https://jasmine.github.io/api/3.5/async-matchers.html#toBeRejected
      [toBeResolved()]: https://jasmine.github.io/api/3.5/async-matchers.html#toBeResolved
      [toHaveBeenCalledBefore()]: https://jasmine.github.io/api/3.5/matchers.html#toHaveBeenCalledBefore
      [withArgs()]: https://jasmine.github.io/api/3.5/Spy.html#withArgs
      
      PR Close #36837
      1b8752e5