Commit graph

3050 commits

Author SHA1 Message Date
Kristiyan Kostadinov
d36fa111eb fix(core): avoid Closure Compiler error in restoreView (#45445)
Closure Compiler in advanced optimization mode may end up inlining the `ɵɵrestoreView` into the event listener which can lead to a runtime null pointer exception after the changes in #43075.

These changes add an annotation to prevent function inlining of the specific instruction.

PR Close #45445
2022-03-25 17:19:30 -07:00
Tobias Speicher
4ddcf81e61 refactor: replace deprecated String.prototype.substr() (#45397)
.substr() is deprecated so we replace it with functions which work similarily but aren't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>

PR Close #45397
2022-03-24 11:48:09 -07:00
Kristiyan Kostadinov
be161bef79 fix(core): memory leak in event listeners inside embedded views (#43075)
When we have an event listener inside an embedded view, we generate a `restoreView` call which saves the view inside of the LFrame. The problem is that we don't clear it until it gets overwritten which can lead to memory leaks.

These changes rework the generated code in order to generate a `resetView` call which will clear the view from the LFrame.

Fixes #42848.

PR Close #43075
2022-03-24 11:05:24 -07:00
JoostK
71ee417fae refactor(core): remove unused logic from reflection capabilities (#45335)
This commit removes a bunch of methodss from `ReflectionCapabilities` as they
have gone unused. This also removes `Reflector` as it doesn't serve any purpose
and it is not exposed as public API, so can be safely removed.

PR Close #45335
2022-03-24 11:02:39 -07:00
Kristiyan Kostadinov
c9d566ce4b feat(core): drop support for TypeScript 4.4 and 4.5 (#45394)
Drops support for TypeScript older than 4.6 and removes some workarounds in the compiler.

BREAKING CHANGE:
TypeScript versions older than 4.6 are no longer supported.

PR Close #45394
2022-03-24 10:51:47 -07:00
Alex Rickabaugh
27b4af7240 fix(compiler-cli): full side-effectful registration of NgModules with ids (#45024)
Angular contains an NgModule registry, which allows a user to declare
NgModules with string ids and retrieve them via those ids, using the
`getNgModuleById` API.

Previously, we attempted to structure this registration in a clever fashion
to allow for tree-shaking of registered NgModules (that is, those with ids).
This sort of worked due to the accidental alignment of behaviors from the
different tree-shakers involved. However, this trick relies on the
generation of `.ngfactory` files and how they're specifically processed in
various bundling scenarios. We intend to remove `.ngfactory` files, hence
we can no longer rely on them in this way.

The correct solution here is to recognize that `@NgModule({id})` is
inherently declaring a global side-effect, and such classes should not
really be eligible for tree-shaking in the first place. This commit removes
all the old registration machinery, and standardizes on generating a side-
effectful call to `registerNgModuleType` for NgModules that have ids.

There is some risk here that NgModules with unnecessary `id`s may not
tree-shake as a result of this change, whereas they would have in previous
circumstances. The fix here should be to remove the `id` if it's not needed.
Specifying an `id` is a request that the NgModule be retained regardless of
any other references, in case it is later looked up by string id.

PR Close #45024
2022-03-22 11:11:53 -07:00
Dylan Hunn
c26915c8cf refactor(core): Make the typed forms migration apply to all usages of the symbols. (#45311)
Previously, the migration only migrated constructor calls. Now, the migration will rewrite every usage, in all contexts. Both ways are technically correct, but migrating all symbols is likely to produce clearer and more readable results.

PR Close #45311
2022-03-21 14:40:59 -07:00
Kristiyan Kostadinov
2a75754ee8 fix(animations): apply default params when resolved value is null or undefined (#45339)
The animations package supports adding default parameter values to an animation that will be used as a fallback if some parameters aren't defined. The problem is that they're applied using a spread expression which means that any own property of the animation parameters will override the defaults, even if it resolves to null or undefined. This can lead to obscure errors like "Cannot read property toString of undefined" for an animation that looks like `{params: {foo: undefined}}` with defaults `{foo: 123}`.

I ran into this issue while debugging some test failures on Material.

These changes address the issue by:
1. Applying the defaults if the resolved value is null or undefined.
2. Updating the validation function to use a null check instead of `hasOwnProperty`.

PR Close #45339
2022-03-17 14:02:37 -07:00
Jessica Janiuk
5f7c4f67d0 refactor(core): Switch over to new closure LOCALE vs getLocale() (#45302)
This is a change requested via an LSC due to a deprecation.

PR Close #45302
2022-03-10 12:48:29 -08:00
JiaLiPassion
225e4f2dbe feat(core): triggerEventHandler accept optional eventObj (#45279)
Close #44724

`DebugNode.triggerEventHandler()` should accept the `eventObj` as an
optional parameter. So the user don't have to write code like

```
elem.triggerEventHandler('click', null);
```

PR Close #45279
2022-03-09 13:51:54 -08:00
Andrew Scott
e78a928d6b refactor(migrations): update isReferenceToImport to not use valueDeclaration (#45292)
valueDeclaration is only set when the Symbol type is a `Value`:

* [setValueDeclaration](https://sourcegraph.com/github.com/microsoft/TypeScript@d8b21a8d6cef772fea5cf2a507b651c5d38194bd/-/blob/src/compiler/binder.ts?L321-322)
* [Value union](https://sourcegraph.com/github.com/microsoft/TypeScript@d8b21a8d6cef772fea5cf2a507b651c5d38194bd/-/blob/src/compiler/types.ts?L4849:9#tab=references)

This won't be the case if the symbol is an interface (notice that `Interface` is not in the union for `Value` above).

For this reason, we can't rely on the `valueDeclaration` property of the symbol.
Instead, it's more reliable to just compare the first items in the `declarations` list.

PR Close #45292
2022-03-08 13:13:24 -08:00
Dylan Hunn
6cec8aa728 refactor(core): Improve the efficiency of the Typed Forms migration. (#45288)
Consider a file that imports `FormControl` and then never uses it. In that case, we don't need to add the import for `UntypedFormControl`.

By examining constructor calls *first*, we can identify these cases and skip over them.

This will reduce the memory footprint of the migration when run in tsunami, hopefully making OOM errors less likely.

PR Close #45288
2022-03-08 12:06:16 -08:00
Alan Agius
6eaaefd22e feat(core): drop support for Node.js 12 (#45286)
Node.js v12 will become EOL on 2022-04-30. As a result, Angular CLI v14 will no longer support Node.js v12.

BREAKING CHANGE:

Support for Node.js v12 has been removed as it will become EOL on 2022-04-30. Please use Node.js v14.15 or later.

PR Close #45286
2022-03-08 12:05:03 -08:00
Kristiyan Kostadinov
9fa6f5a552 fix(core): incorrectly inserting elements inside <template> element (#43429)
Currently whenever we insert element we do it directly on the node using `appendChild` or `insertBefore`, however this doesn't work with `<template>` elements where the `template.content` has to be used.

These changes add a few checks to call `appendChild` and `insertBefore` on the `content` of the template.

Fixes #15557.

PR Close #43429
2022-03-08 10:22:18 -08:00
nanda18
0b31c8e2da docs: update flush description to include microtasks (#45237)
PR Close #45237
2022-03-07 15:41:07 -08:00
Dylan Hunn
d336ba96d9 fix(forms): Update the typed forms migration. (#45281)
The typed forms migration was previously designed to add `<any>` type parameters to existing forms classes. However, due to some design changes, the new opt-out strategy requires untyped versions of the classes, as introduced in #45205 and #45268.

This PR updates the migration to import these new classes (in an idempotent manner), and replace constructor calls with the new classes. It respects qualified imports as well. Finally, the code has been refactored to move as much common code as possible into `util.ts`.

PR Close #45281
2022-03-07 12:24:59 -08:00
Kristiyan Kostadinov
69018c9f42 feat(core): allow for injector to be specified when creating an embedded view (#45156)
Adds support for passing in an optional injector when creating an embedded view through `ViewContainerRef.createEmbeddedView` and `TemplateRef.createEmbeddedView`. The injector allows for the DI behavior to be customized within the specific template.

This is a second stab at the changes in #44666. The difference this time is that the new injector acts as a node injector, rather than a module injector.

Fixes #14935.

PR Close #45156
2022-03-02 16:38:00 +00:00
Andrew Kushnir
05d50b849b perf(common): make NgLocalization token tree-shakable (#45118)
This commit updates the `NgLocalization` token to become tree-shakable (vs using a direct reference to that token in the `providers` section of the `CommonModule`). The `NgLocalization` token is used for apps that use i18n and for other apps it would be excluded from the bundle.

PR Close #45118
2022-03-01 20:42:39 +00:00
Dylan Hunn
c8e4d62882 refactor(forms): Split up model.ts. (#45217)
model.ts is currently extremely large. This is the first step in an attempt to refactor it to be more easily navigable and reviewable. This commit breaks up `model.ts` into the following new files:

* `model/abstract_model.ts`: The remainder of the model, including the `AbstractControl` base class and helper functions which are used throughout.
* `model/form_control.ts`: `FormControl`, `FormControlOptions`, and helpers, plus the constructor and untyped friends.
* `model/form_array.ts`: `FormArray` and untyped friends.
* `model/form_group.ts`: `FormGroup` and untyped friends.

This first phase is a purely mechanical code move. There is no new code at all, and no interfaces have been separated.

PR Close #45217
2022-03-01 19:49:31 +00:00
Theodore Brown
c5df474c7c fix(core): remove individual commands for updating gold files (#45198)
The documented command for updating the forms gold files was outdated
and didn't work. Since this command list can easily become outdated,
remove the individual commands in favor of the simpler global scripts.

PR Close #45198
2022-03-01 19:16:53 +00:00
Dylan Hunn
bd12f9eda4 refactor(forms): Move getRawValue into the AbstractControl hierarchy. (#45200)
Currently, there is a freestanding `getRawValue` function which examines the type of the control. This is an issue for refactoring `model.ts` because it creates unnecessary dependencies between the `AbstractControl` classes. It is cleaner to simply add this method to the model hierarchy and call it directly, and will ease upcoming refactoring.

PR Close #45200
2022-03-01 01:07:12 +00:00
Dylan Hunn
4b936a1014 Revert "feat(core): allow for injector to be specified when creating an embedded view (#45156)" (#45220)
This reverts commit 94c949a60a.

PR Close #45220
2022-03-01 01:04:57 +00:00
Dylan Hunn
b817f3cbf5 Revert "refactor(forms): Move getRawValue into the AbstractControl hierarchy. (#45200)" (#45219)
This reverts commit dfc4301b33.

PR Close #45219
2022-03-01 00:07:39 +00:00
Dylan Hunn
dfc4301b33 refactor(forms): Move getRawValue into the AbstractControl hierarchy. (#45200)
Currently, there is a freestanding `getRawValue` function which examines the type of the control. This is an issue for refactoring `model.ts` because it creates unnecessary dependencies between the `AbstractControl` classes. It is cleaner to simply add this method to the model hierarchy and call it directly, and will ease upcoming refactoring.

PR Close #45200
2022-02-28 19:44:07 +00:00
Kristiyan Kostadinov
94c949a60a feat(core): allow for injector to be specified when creating an embedded view (#45156)
Adds support for passing in an optional injector when creating an embedded view through `ViewContainerRef.createEmbeddedView` and `TemplateRef.createEmbeddedView`. The injector allows for the DI behavior to be customized within the specific template.

This is a second stab at the changes in #44666. The difference this time is that the new injector acts as a node injector, rather than a module injector.

Fixes #14935.

PR Close #45156
2022-02-28 19:42:26 +00:00
Dylan Hunn
4c80ca3700 refactor(forms): Clean up the find function. (#45199)
Move `find` into the `AbstractControl` hierarchy, and clean up a longstanding implementation todo.

PR Close #45199
2022-02-28 17:26:31 +00:00
Kristiyan Kostadinov
88f1168506 perf(core): only track LViews that are referenced in __ngContext__ (#45172)
Follow-up to #45051 where every `LView` that was being created was tracked in the `TRACKED_LVIEWS` map. This isn't necessary, because we only need to track the view that have been referenced by an `__ngContext__`.

PR Close #45172
2022-02-24 23:51:38 +00:00
Andrew Scott
0920104372 refactor(router): Refactor errors in applyRedirects to use common throwError function (#45170)
The implementation of `throwError` in `rxjs` is identical to what is
done manually in the Router code.

PR Close #45170
2022-02-24 23:50:00 +00:00
Kristiyan Kostadinov
ff6be32c1a refactor(compiler): remove usages of deprecated AST creation functions (#45134)
Proactively replaces our usages of the deprecated `ts.create*` methods in favor of using `ts.factory.create*` so that we're not surprised when the TS removes them in the future. Also accounts for some cases where the signature had changed.

PR Close #45134
2022-02-22 10:22:47 -08:00
Andrew Kushnir
1e60fe0a3e perf(core): make LOCALE_ID and other tokens from ApplicationModule tree-shakable (#45102)
The `ApplicationModule` module has a number of tokens declared as non-tree-shakable providers. This commit updates them to make tree-shakable.

PR Close #45102
2022-02-18 13:40:02 -08:00
Andrew Kushnir
a96c4827c4 perf(core): make Compiler, ApplicationRef and ApplicationInitStatus tree-shakable (#45102)
The `Compiler`, `ApplicationRef` and `ApplicationInitStatus` classes are registered as non-tree-shakable providers in the `ApplicationModule`. This commit converts them to the tree-shakable providers instead.

PR Close #45102
2022-02-18 13:40:02 -08:00
Andrew Kushnir
fcd047335d refactor(core): drop unused SCHEDULER provider (#45102)
The `SCHEDULER` provider was used previously when both ViewEngine and Ivy code was present. After some prior refactoring, all references to the `SCHEDULER` token were removed, but the token itself remains present in the `ApplicationModule`, which makes it non-tree-shakable.

This commit removes the `SCHEDULER` token as unused.

PR Close #45102
2022-02-18 13:40:02 -08:00
Kristiyan Kostadinov
071c8af8ba perf(core): avoid storing LView in __ngContext__ (#45051)
These changes combine #41358 and #41894.

Currently we save a reference to an `LView` on most DOM nodes created by Angular either by saving the `LView` directly in the `__ngContext__` or by saving the `LContext` which has a reference to the `LView`. This can be a problem if the DOM node is retained in memory, because the `LView` has references to all of the child nodes of the view, as well as other internal data structures.

Previously we tried to resolve the issue by clearing the `__ngContext__` when a node is removed (see https://github.com/angular/angular/pull/36011), but we decided not to proceeed, because it can slow down destruction due to a megamorphic write.

These changes aim to address the issue while reducing the performance impact by assigning a unique ID when an `LView` is created and adding it to `__ngContext__`. All active views are tracked in a map where their unique ID is used as the key. We don't need to worry about leaks within that map,  because `LView`s are an internal data structure and we have complete control over when they are  created and destroyed.

Fixes #41047.

PR Close #45051
2022-02-18 13:32:11 -08:00
JoostK
5c7c56bc85 perf(animations): improve algorithm to balance animation namespaces (#45057)
The prior approach would consider all existing namespaces from back to front
to find the one that's the closest ancestor for a given host element. An
expensive `contains` operation was used which needed to traverse all the
way up the document root _for each existing namespace_. This commit implements
an optimization where the closest namespace is found by traversing up from
the host element, avoiding repeated DOM traversal.

Closes #45055

PR Close #45057
2022-02-16 13:48:51 -08:00
Andrew Kushnir
45d98e7ca5 perf(core): make IterableDiffers and KeyValueDiffers tree-shakable (#45094)
This commit removed references to the `IterableDiffers` and `KeyValueDiffers` classes from the `ApplicationModule`, which effectively make them tree-shakable. Both classes have `prov` static field with the right setup, so they'll be properly initialized when referenced.

PR Close #45094
2022-02-16 13:35:18 -08:00
Kristiyan Kostadinov
e461f716d4 feat(core): move ANIMATION_MODULE_TYPE injection token into core (#44970)
Moves the `ANIMATION_MODULE_TYPE` DI token into core so that libraries like Material don't have to introduce a dependency to animations only to figure out whether animations are disabled.

PR Close #44970
2022-02-14 14:03:07 -08:00
Jessica Janiuk
4c778cdb28 perf(animations): made errors in the animations package tree shakeable (#45004)
This moves all the error strings into exported functions that can be tree shaken away.

PR Close #45004
2022-02-09 11:43:42 -08:00
Andrew Kushnir
822439fddd fix(core): ViewContainerRef.createComponent should consult module injector when custom one is provided (#44966)
Before Ivy, it was only possible to call the `ViewContainerRef.createComponent` function with the ComponentFactory as the first argument. An instance of a `ComponentFactory` resolved via `ComponentFactoryResolver` contained a reference to an `NgModule` where the component is declared. As a result, the component maintained a DI connection with the module injector tree (by retrieving an instance of `NgModuleRef` internally), even when the custom injector was provided (we try to find a token in a custom injector first and consult module injector after that).

With Ivy, we expanded the `ViewContainerRef.createComponent` function API to support direct references to the Component classes without going through the factory resolution step. As a result, there was no connection to the NgModule that declares the component. Thus, if you provide a custom injector, this is the only injector that is taken into account.

This commit updates the logic for the factory-less case to try retrieving an instance of an `NgModuleRef` using the DI tree which `ViewContainerRef` belongs to. The `NgModuleRef` instance is then used to get a hold of a module injector tree. This brings the factory-less and factory-based logic to more consistent state.

Closes #44897.

PR Close #44966
2022-02-08 09:57:20 -08:00
Kristiyan Kostadinov
1b91e1049e perf(compiler): chain element start/end instructions (#44994)
In templates with several levels of nested nodes, it's common for several `elementStart`/`elementEnd` instructions to show up in a row which can be optimized away.

These changes add chaining support for `elementStart`, `elementEnd`, `elementContainerStart` and `elementContainerEnd` to shave off some bytes when possible.

PR Close #44994
2022-02-08 09:56:50 -08:00
Andrew Kushnir
64acbc4242 refactor(core): drop all .ngfactory and .ngsummary imports (#44957)
This commit updates various places in the repo (mostly tests/examples) to drop all `.ngfactory` and `.ngsummary` imports as they are no longer needed in Ivy.

PR Close #44957
2022-02-07 15:31:49 -08:00
Ruslan Lekhman
d5719c2e0f fix(core): input coercion (#42803)
BREAKING CHANGE: Forms [email] input coercion

Forms [email] input value will be considered as true if it is defined with any value rather
than false and 'false'.

PR Close #42803
2022-02-07 10:52:59 -08:00
Andrew Kushnir
99171522cb refactor(core): cleanup DebugNode and DebugElement implementations (#44270)
This commit updates `DebugNode` and `DebugElement` implementaitons to cleanup ViewEngine removal artifacts. There is no need for a separate interface and implementation class, so we can combine them now. This comment also gets rid of `R3` suffixes (denoting Ivy) in helper methods.

PR Close #44270
2022-02-04 10:43:42 -08:00
dario-piotrowicz
e46b379204 fix(animations): implement missing transition delay (#44799)
fix the transition function accepting a delay in its AnimationOptions
input but not acting on it by adding such delay to all the transition's
timelines

(note: adding the delay to all the transition's timelines is the only
way to accomplish this since transitions have their own logic and do not
have their own timelines like other animation functions have)

resolves #29762

PR Close #44799
2022-02-03 23:54:16 +00:00
Alex Rickabaugh
0072eb48ba feat(compiler-cli): initial implementation of standalone components (#44812)
This commit implements the first phase of standalone components in the Angular
compiler. This mainly includes the scoping rules for standalone components
(`@Component({imports})`).

Significant functionality from the design is _not_ implemented by this PR,
including:

* imports of standalone components into NgModules.
* the provider aspect of standalone components

Future commits will address these issues, as we proceed with the design of
this feature.

PR Close #44812
2022-02-03 08:55:25 -08:00
Dylan Hunn
cae1e44608 fix(forms): Update the typed forms migration to use FormArray<T> instead of FormArray<T[]>. (#44933)
Previously, `FormArray` accepted an array generic. Now it accepts the element type, so the migration must be update accordingly.

PR Close #44933
2022-02-02 01:58:18 +00:00
Andrew Scott
fdfcef5a0a build: enable useUnknownInCatchVariables (#44679)
This unblocks the internal migration to turn the option on in g3.

PR Close #44679
2022-02-01 18:17:29 +00:00
Alan Agius
bc61cc2449 refactor(migrations): remove old migrations (#44857)
When using `ng update` users cannot update multiple major versions at the same time. Therefore migrations that are not targeting version 14 cannot be run and therefore we are removing them.

PR Close #44857
2022-02-01 03:52:26 +00:00
Andrew Kushnir
ed1732c268 refactor(core): the RuntimeError class should support more compact syntax (#44783)
This commit refactors the `RuntimeError` class to support a short version of providing error messages:
```
throw new RuntimeError(
  RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
  ngDevMode && 'Injector has already been destroyed.');
```
In prod mode, the second argument becomes `false` andn this commit extends the typings to support that.

This commit also contains a couple places were the `RuntimeError` class is used to demostrate the compact form.

PR Close #44783
2022-02-01 00:15:56 +00:00
arturovt
889de8276d fix(forms): ensure OnPush ancestors are marked dirty when the promise resolves (#44886)
Currently, `ngModel` calls` setValue` after the `resolvedPromise` is resolved.
The promise is resolved _after_ the child template executes. The change detection
is run but `OnPush` views are not updated because they are not marked as dirty.

PR Close #44886
2022-01-31 21:38:39 +00:00
Andrew Kushnir
39c614c438 fix(core): flush delayed scoping queue while setting up TestBed (#44814)
Previously, some NgModules that were added to the delayed scoping queue, never got removed from the queue before unit test execution. That resulted in some components (declared in those NgModules) missing their scope (which components/directives/pipes were matched).

This commit adds the logic to invoke delayed scoping queue flushing before starting a test to avoid missing/incomplete scopes for Components used in a test.

PR Close #44814
2022-01-31 21:37:53 +00:00