Commit Graph

7550 Commits

Author SHA1 Message Date
Ahmed Ayed efb440eb2f refactor(router): compute correct history restoration when navigation is cancelled (#38884)
We can’t determine whether the user actually meant the `back` or
the `forward` using the popstate event (triggered by a browser
back/forward)
so we instead need to store information on the state and compute the
distance the user is traveling withing the browser history.
So by using the `History#go` method,
we can bring the user back to the page where he is supposed to be after
performing the action.

implementation for #13586

PR Close #38884
2021-06-10 14:09:21 -07:00
JiaLiPassion 299f92c3b6 fix(zone.js): only one listener should also re-throw an error correctly (#41868)
Close #41867

In the previous commit https://github.com/angular/angular/pull/41562#issuecomment-822696973,
the error thrown in the event listener will be caught and re-thrown, but there is a bug
in the commit, if there is only one listener for the specified event name, the error
will not be re-thrown, so this commit fixes the issue and make sure the error is re-thrown.

PR Close #41868
2021-06-10 09:24:03 -07:00
JoostK 22bda2226b fix(compiler-cli): prevent prior compilations from being retained in watch builds (#42537)
In watch builds, the compiler attempts to reuse as much information from
a prior compilation as possible. To accomplish this, it keeps a
reference to the most recently succeeded `TraitCompiler`, which contains
all analysis data for the program. However, `TraitCompiler` has an
internal reference to an `IncrementalBuild`, which is itself built on
top of its prior state. Consequently, all prior compilations continued
to be referenced, preventing garbage collection from cleaning up these
instances.

This commit changes the `AnalyzedIncrementalState` to no longer retain
a `TraitCompiler` instance, but only the analysis data it contains. This
breaks the retainer path to the prior incremental state, allowing it to
be garbage collected.

PR Close #42537
2021-06-09 16:10:04 -07:00
Igor Minar 3961b3c360 fix(core): ensure that autoRegisterModuleById registration in ɵɵdefineNgModule is not DCE-ed by closure (#42529)
Previously the autoRegisterModuleById registration was marked with noSideEffects wrapper to ensure that we don't end up retaining all NgModules.

However the return value was not referenced by anything, so closure compiler removed it because it determined that this code has no side effects and is not referenced by anyone.

This issue affects apps that use Closure Compiler and also rely on https://angular.io/api/core/getModuleFactory to retrieve factories by ID. This combination is used heavily in google3, especially in Pantheon.

Fixes b/188453434

PR Close #42529
2021-06-09 12:13:23 -07:00
Andrew Scott 536c3738ba docs: clarify onSameUrlNavigation behavior (#42275)
`onSameUrlNavigation` only affects whether the Angular Router
processes the URL and runs it through the navigation pipeline,
retriggering redirects, guards, and resolvers. The name `reload` is a
little confusing because it does _not_ reload the component. Developers
_also_ need to implement a custom `RouteReuseStrategy` to trigger a
component reload on same URL navigation.

Fixes #21115

PR Close #42275
2021-06-09 09:45:25 -07:00
Renovate Bot e1a80d4b24 build: update dependency mocha to v9 (#42514)
PR Close #42514
2021-06-08 15:26:44 -07:00
Renovate Bot 230f0c41b7 build: lock file maintenance (#42499)
PR Close #42499
2021-06-08 15:25:59 -07:00
Dylan Hunn 34ce635e3a feat(forms): undo revert and add ng-submitted class to forms that have been submitted. (#42132) (#42132)
As previously discussed in pull/31070 and issues/30486, this would be useful because it is often desirable to apply styles to fields that are both `ng-invalid` and `ng-pristine` after the first attempt at form submission, but Angular does not provide any simple way to do this (although evidently Angularjs did). This will now be possible with a descendant selector such as `.ng-submitted .ng-invalid`.

In this implementation, the directive that sets control status classes on forms and formGroups has its set of statuses widened to include `ng-submitted`. Then, in the event that `is('submitted')` is invoked, the `submitted` property of the control container is returned iff it exists. This is preferred over checking whether the container is a `Form` or `FormGroup` directly to avoid reflecting on those classes.

Closes #30486.

PR Close #42132.

This reverts commit 00b1444d12, undoing the rollback of this change.

PR Close #42132
2021-06-08 14:02:29 -07:00
anups1 5c0541f351 docs: fix issue 24571 in ngOnChanges (#42517)
fix issue #24571 in ngOnChanges doc

PR Close #42517
2021-06-08 12:44:30 -07:00
Sam Severance c44ab4f6da fix(router): fix `serializeQueryParams` logic (#42481)
corrects a bug that resulted in query params such as
`[queryParams]={a: 1, b:[]}` being serialized as 'a=1&'
instead of 'a=1'

resolves #42445

PR Close #42481
2021-06-08 10:43:00 -07:00
Andrew Scott 171428ec98 docs: add selector documentation for `ViewChildren`, `ContentChildren`, and `ContentChild` (#42366)
These notes are copied from `ViewChild`. In addition, `ContentChildren` and `ViewChildren`
can specify multiple string selectors by separating each selector by a
comma.

fixes #21734

PR Close #42366
2021-06-08 10:42:21 -07:00
MrJithil 4cf442c879 docs: add links to examples for ComponentFactoryResolver (#42496)
Fixes #21705

PR Close #42496
2021-06-08 10:41:33 -07:00
Jessica Janiuk 66f49c2497 Revert "refactor: remove checked-in locale files" (#42521)
This reverts commit 3a83ec8020f96c293fdc316854e199281d329111.

PR Close #42521
2021-06-08 10:06:24 -07:00
Jessica Janiuk e3b709314f Revert "build: convert CLDR locale extraction from Gulp to Bazel tool" (#42521)
This reverts commit b9759522260cd57392e44fe63c5b17a9f102c101.

PR Close #42521
2021-06-08 10:06:24 -07:00
Jessica Janiuk cb59bdfebd Revert "build: wire up new CLDR generation tool within Bazel" (#42521)
This reverts commit 40bf84c89decea1de08e43936c9886a391b02173.

PR Close #42521
2021-06-08 10:06:24 -07:00
Jessica Janiuk cc55fd6e11 Revert "build: add documentation for `generate-locales-tool`" (#42521)
This reverts commit 12d84d041a2b27bec77f18d7e433b01f105ac784.

PR Close #42521
2021-06-08 10:06:24 -07:00
Jessica Janiuk fa4b0b31c0 Revert "build: simplify generation of closure locale file" (#42521)
This reverts commit 5fca35de0de8da24b8a046616404e74ecb4547b4.

PR Close #42521
2021-06-08 10:06:24 -07:00
Paul Gschwendtner b762820485 build: simplify generation of closure locale file (#42230)
In the past, the closure file has been generated so that all individual
locale files were imported individually. This resulted in a huge
slow-down in g3 due to the large amount of imports.

With 90bd984ff7 this changed so that we
inline the locale data for the g3 closure locale file. Also the file
only contained data for locales being supported by Closure. For this a
list of locales has been extracted from Closure Compiler, as well as a
list of locale aliases.

This logic is prone to CLDR version updates, and also broke as part of
the Gulp -> Bazel migration where this logic has been slightly modified
but caused issues in G3. e.g. a locale `zh-Hant` was requested in g3,
but the locale data had the name of the alias locale that provided the
data at index zero (which represents the locale name). Note that the
locale names at index zero always could differentiate from the requested
`goog.LOCALE` due to the aliasing logic. This just didn't come up before.

We simplify this logic by generating a `goog.LOCALE` case for all
locales CLDR provides data for. We don't need to bother about aliasing
because with the refactorings to the CLDR generation tool, all locales
are built (which also captures the aliases), and we can generate the locale
file on the fly (which has not been done before).

PR Close #42230
2021-06-07 15:34:39 -07:00
Paul Gschwendtner 7b288471bf build: add documentation for `generate-locales-tool` (#42230)
The CLDR extraction tool has been reworked to run as part of Bazel.
This adds a initial readme explaining what the tool generates. It's
far from a detailed description but it can serve as foundation for more
detailed explanations.

PR Close #42230
2021-06-07 15:34:39 -07:00
Paul Gschwendtner 4641fc71a2 build: wire up new CLDR generation tool within Bazel (#42230)
Introduces a few Starlark macros for running the new Bazel
CLDR generation tool. Wires up the new tool so that locales
are generated properly. Also updates the existing
`closure-locale` file to match the new output generated by the Bazel tool.

This commit also re-adds a few locale files that aren't
generated by CLDR 37, but have been accidentally left in
the repository as the Gulp script never removed old locales
from previous CLDR versions. This problem is solved with the
Bazel generation of locale files, but for now we re-add these
old CLDR 33 locale files to not break developers relying on these
(even though the locale data indicies are incorrect; but there might
be users accessing the data directly)

PR Close #42230
2021-06-07 15:34:38 -07:00
Paul Gschwendtner 1f75a657a8 build: convert CLDR locale extraction from Gulp to Bazel tool (#42230)
Converts the CLDR locale extraction script to a Bazel tool.
This allows us to generate locale files within Bazel, so that
locales don't need to live as sources within the repo. Also
it allows us to get rid of the legacy Gulp tooling.

The migration of the Gulp script to a Bazel tool involved the
following things:

  1. Basic conversion of the `extract.js` script to TypeScript.
     This mostly was about adding explicit types. e.g. adding `locale:
     string` or `localeData: CldrStatic`.

  2. Split-up into separate files. Instead of keeping the large
     `extract.js` file, the tool has been split into separate files.
     The logic remains the same, just that code is more readable and
     maintainable.

  3. Introduction of a new `index.ts` file that is the entry-point
     for the Bazel tool. Previously the Gulp tool just generated
     all locale files, the default locale and base currency files
     at once. The new entry-point accepts a mode to be passed as
     first process argument. based on that argument, either locales
     are generated into a specified directory, or the default locale,
     base currencies or closure file is generated.

     This allows us to generate files with a Bazel genrule where
     we simply run the tool and specify the outputs. Note: It's
     necessary to have multiple modes because files live in separate
     locations. e.g. the default locale in `@angular/core`, but the
     rest in `@angular/common`.

  4. Removal of the `cldr-data-downloader` and custom CLDR resolution
     logic. Within Bazel we cannot run a downloader using network.

     We switch this to something more Bazel idiomatic with better
     caching. For this a new repository rule is introduced that
     downloads the CLDR JSON repository and extracts it. Within
     that rule we determine the supported locales so that they
     can be used to pre-declare outputs (for the locales) within
     Bazel analysis phase. This allows us to add the generated locale
     files to a `ts_library` (which we want to have for better testing,
     and consistent JS transpilation).

     Note that the removal of `cldr-data-downloader` also requires us to
     add logic for detecting locales without data. The CLDR data
     downloader overwrote the `availableLocales.json` file with a file
     that only lists locales that CLDR provides data for. We use the
     official `availableLocales` file CLDR provides, but filter out
     locales for which no data is available. This is needed until we
     update to CLDR 39 where data is available for all such locales
     listed in `availableLocales.json`.

PR Close #42230
2021-06-07 15:34:38 -07:00
Paul Gschwendtner 9421bcd978 refactor: remove checked-in locale files (#42230)
This is a pre-refactor commit allowing us to move
the CLDR locale generation to Bazel where files would
no longer be checked-in, except for the `closure-locale`
file that is synced into Google3.

PR Close #42230
2021-06-07 15:34:38 -07:00
Andrew Scott a493ea9bcb fix(language-service): fix autocomplete info display for some cases (#42472)
Before this commit, attribute completion display parts were retrieved
but not assigned. In addition, the switch case was non-exhaustive
because it did not include `StructuralDirectiveAttribute`.

PR Close #42472
2021-06-07 12:25:53 -07:00
Paul Gschwendtner 38c592ea0a build: remove unused no-strict tsconfig file (#42506)
In the past, when we enabled `--strict` in the repository, we added
another tsconfig for code not being migrated to be `--strict`
compatible. This was done for the deprecated http and webworker
packages. Since these are now removed, we can rmeove the logic.

PR Close #42506
2021-06-07 10:47:47 -07:00
Andrew Kushnir f4c55e464a docs: provide more info on the `NO_ERRORS_SCHEMA` schema (#42327)
The `NO_ERRORS_SCHEMA` schema can be used to ignore errors related to unknown elements or properties, but since it suppresses these errors it may also hide real problems in a template. This commit updates the `NO_ERRORS_SCHEMA` docs to mention that.

Closes #39454.

PR Close #42327
2021-06-07 10:46:34 -07:00
Kristiyan Kostadinov afd68e5674 feat(compiler): emit diagnostic for shadow dom components with an invalid selector (#42245)
This is based on a discussion we had a few weeks ago. Currently if a component uses `ViewEncapsulation.ShadowDom` and its selector doesn't meet the requirements for a custom element tag name, a vague error will be thrown at runtime saying something like "Element does not support attachShadowRoot".

These changes add a new diagnostic to the compiler that validates the component selector and gives a better error message during compilation.

PR Close #42245
2021-06-07 10:44:57 -07:00
Pete Bacon Darwin cc904b5226 docs(core): clarify deprecation of `entryComponents` (#42248)
These may still be needed in View Engine libraries.

Closes #39958

PR Close #42248
2021-06-07 10:02:01 -07:00
Paul Gschwendtner 2d0ff0a5d3 ci: add lint error for files with missing trailing new-line (#42478)
For quite a while it is an unspoken convention to add a trailing
new-line files within the Angular repository. This was never enforced
automatically, but has been frequently raised in pull requests through
manual review. This commit sets up a lint rule so that this is
"officially" enforced and doesn't require manual review.

PR Close #42478
2021-06-04 13:31:03 -07:00
Paul Gschwendtner 71e14a71f5 test: update compiler-cli compliance goldens due to TS 4.3 emit format regression (#42022)
Updates the compiler-cli compliance goldens. The golden updates are
required due to a regression in TypeScript 4.3 that causes the emitter
to not incorrectly preserve lines when emitting a node list.

This can be reverted once https://github.com/microsoft/TypeScript/pull/44070
is available.

PR Close #42022
2021-06-04 11:17:09 -07:00
Paul Gschwendtner 25f763cff8 feat(core): support TypeScript 4.3 (#42022)
Switches the repository to TypeScript 4.3 and the latest
version of tslib. This involves updating the peer dependency
ranges on `typescript` for the compiler CLI and for the Bazel
package. Tests for new TypeScript features have been added to
ensure compatibility with Angular's ngtsc compiler.

PR Close #42022
2021-06-04 11:17:09 -07:00
Renovate Bot 69296254da build: update dependency google-closure-compiler to v20210601 (#42475)
PR Close #42475
2021-06-04 10:34:58 -07:00
Jessica Janiuk 00b1444d12 Revert "feat(forms): add `ng-submitted` class to forms that have been submitted." (#42474)
This reverts commit f024d7556081f8913f21761bb8e6aab8d08be110.

PR Close #42474
2021-06-03 17:42:02 -07:00
Kristiyan Kostadinov ba084857ea feat(compiler): support safe keyed read expressions (#41911)
Currently we support safe property (`a?.b`) and method (`a?.b()`) accesses, but we don't handle safe keyed reads (`a?.[0]`) which is inconsistent. These changes expand the compiler in order to support safe key read expressions as well.

PR Close #41911
2021-06-03 13:22:41 -07:00
Dylan Hunn 47270d9e63 feat(forms): add `ng-submitted` class to forms that have been submitted. (#42132)
As previously discussed in pull/31070 and issues/30486, this would be useful because it is often desirable to apply styles to fields that are both `ng-invalid` and `ng-pristine` after the first attempt at form submission, but Angular does not provide any simple way to do this (although evidently Angularjs did). This will now be possible with a descendant selector such as `.ng-submitted .ng-invalid`.

In this implementation, the directive that sets control status classes on forms and formGroups has its set of statuses widened to include `ng-submitted`. Then, in the event that `is('submitted')` is invoked, the `submitted` property of the control container is returned iff it exists. This is preferred over checking whether the container is a `Form` or `FormGroup` directly to avoid reflecting on those classes.

Closes #30486.

PR Close #42132
2021-06-03 13:21:29 -07:00
JoostK 69e57827e2 refactor(compiler-cli): remove unused return type transform (#41996)
With the removal of the `ModuleWithProviders` transform in the parent commit,
the underlying dts transform can also be removed as it is not used elsewhere.

PR Close #41996
2021-06-03 11:38:58 -07:00
JoostK ce8720910d refactor(compiler-cli): remove `ModuleWithProviders` generic type transform (#41996)
The `ModuleWithProviders` type has required a generic type since Angular 10,
so it is no longer necessary for the compiler to transform usages of the
`ModuleWithProviders` type without the generic type, as that should have
been reported as a compile error. This commit removes the detection logic
from ngtsc.

PR Close #41996
2021-06-03 11:38:58 -07:00
iRealNirmal 751cd83ae3 fix(forms): the `min` and `max` validators should work correctly with `0` as a value (#42412)
Prior to this change the `min` and `max` validator directives would not
set the `min` and `max` attributes on the host element. The problem was
caused by the truthy check in host binding expression that was
calculated as `false` when `0` is used as a value. This commit updates
the logic to leverage nullish coalescing operator in these host binding
expressions, so `0` is treated as a valid value, thus the `min` and
`max` attributes are set correctly.

Partially closes #42267

PR Close #42412
2021-06-03 11:34:46 -07:00
JoostK 85c7f7691e fix(common): infer correct type when `trackBy` is used in `ngFor` (#41995)
When a `trackBy` function is used that accepts a supertype of the iterated
array's type, the loop variable would undesirably be inferred as the supertype
instead of the array's item type. This commit adds an inferred type parameter
to `TrackByFunction` to allow an extra degree of freedom, enabling the
loop value to be inferred as the most narrow type.

Fixes #40125

PR Close #41995
2021-06-03 11:33:26 -07:00
JoostK 9d290b4fef test(compiler-cli): move `TrackByFunction` from `fake_common` to `fake_core` (#41995)
The `TrackByFunction` is declared in `@angular/core` so it should also be
included in `fake_core` instead of `fake_common`.

PR Close #41995
2021-06-03 11:33:26 -07:00
JoostK 481540dd4e test(compiler-cli): load type declarations from fake_common (#41995)
The ngtsc test targets have fake declarations files for `@angular/core`
and `@angular/common` and the template type checking tests can leverage
the fake common declarations instead of declaring its own types.

PR Close #41995
2021-06-03 11:33:26 -07:00
JoostK bd1836b999 fix(compiler-cli): exclude type-only imports from cycle analysis (#42453)
Type-only imports are known to be elided by TypeScript, so the compiler
can be certain that such imports do not contribute to potential import
cycles. As such, type-only imports are no longer considered during cycle
analysis.

Regular import statements that would eventually be fully elided by
TypeScript during emit if none of the imported symbols are used in a
value position continue to be included in the cycle analysis, as the
cycle analyzer is unaware of these elision opportunities. Only explicit
`import type` statements are excluded.

PR Close #42453
2021-06-03 11:31:59 -07:00
Vahid Mohammadi 374fa2c26f fix(common): initialize currencyCode in currencyPipe (#40505)
currencyCode should be initialized with the injected default currency code

PR Close #40505
2021-06-03 10:52:28 -07:00
Paul Gschwendtner a16f82b851 refactor(dev-infra): move shared browser bazel setup into dedicated bazel folder (#42268)
This change moves the `dev-infra/browsers` folder into `dev-infra/bazel`.
The browser folder is providing custom configuration for Bazel, so it
should live within the `bazel` folder for a more well-structured
`dev-infra` folder.

PR Close #42268
2021-06-03 10:37:41 -07:00
Renovate Bot f3f10140b5 build: lock file maintenance (#42264)
PR Close #42264
2021-06-02 13:16:58 -07:00
Andrew Scott fe22c2b0b6 fix(language-service): Correct rename info for pipe name expressions (#41974)
Prior to this PR, attempting to get rename info for pipe name expressions would defer to the
typescript language service, which would return no rename info. This was not caught because
the test was written incorrectly.

This PR corrects the test behavior and adjusts the logic in getting rename info to account
for indirect renames (like pipe names).

PR Close #41974
2021-06-02 13:15:48 -07:00
Andrew Scott 6a2e3e2b2c docs: change Navigation from type to interface (#42281)
Navigation type should be interface so it can be documented on aio site.

fixes #37384

PR Close #42281
2021-06-01 14:13:20 -07:00
Alex Rickabaugh e039075a28 fix(compiler-cli): better detect classes that are indirectly exported (#42207)
The compiler flag `compileNonExportedClasses` allows the Angular compiler to
process classes which are not exported at the top level of a source file.
This is often used to allow for AOT compilation of test classes inside
`it()` test blocks, for example.

Previously, the compiler would identify exported classes by looking for an
`export` modifier on the class declaration itself. This works for the
trivial case, but fails for indirectly exported classes:

```typescript
// Component is declared unexported.
@Component({...})
class FooCmp {...}

// Indirect export of FooCmp
export {FooCmp};
```

This is not an immediate problem for most application builds, since the
default value for `compileNonExportedClasses` is `true` and therefore such
classes get compiled regardless.

However, in the Angular Language Service now, `compileNonExportedClasses` is
forcibly overridden to `false`. That's because the tsconfig used by the IDE
and Language Service is often far broader than the application build's
configuration, and pulls in test files that can contain unexported classes
not designed with AOT compilation in mind.

Therefore, the Language Service has trouble working with such structures.

In this commit, the `ReflectionHost` gains a new API for detecting whether a
class is exported. The implementation of this method now not only considers
the `export` modifier, but also scans the `ts.SourceFile` for indirect
exports like the example above. This ensures the above case will be
processed directly in the Language Service.

This new operation is cached using an expando symbol on the `ts.SourceFile`,
ensuring good performance even when scanning large source files with lots of
exports (e.g. a FESM file under `ngcc`).

Fixes #42184.

PR Close #42207
2021-06-01 12:16:46 -07:00
Kristiyan Kostadinov 3e192bfa4d build: fix linting against jasmine focus functions (#42415)
We were linting against usages of `fdescribe` and `fit` by referencing the `no-jasmine-focus` rule which isn't installed, causing tslint to log the following:

```
Could not find implementations for the following rules specified in the configuration:
    no-jasmine-focus
Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.
If TSLint was recently upgraded, you may have old rules configured which need to be cleaned
```

These changes switch to using the built-in `ban` rule.

PR Close #42415
2021-06-01 10:16:55 -07:00
Andrew Scott 1b8bbddff5 docs: list supported values for `read` in decorator metadata (#42370)
fixes #20927

PR Close #42370
2021-06-01 10:12:23 -07:00
Andrew Scott 62b5a6cb07 docs: add docs for DebugElement (#42352)
fixes #36048

PR Close #42352
2021-05-27 17:02:24 -07:00