Commit graph

28152 commits

Author SHA1 Message Date
mgechev
4dffbeff35 docs: remove the developer survey 2023 banner (#52116)
PR Close #52116
2023-10-10 11:23:44 -07:00
Thabo
add0bd364c docs: correct wording for Directive's decorator host property key description (#51977)
PR Close #51977
2023-10-10 11:22:18 -07:00
Kristiyan Kostadinov
7dbd47fb30 fix(compiler): allow newlines in track and let expressions (#52137)
Fixes that the template parser didn't allow for newlines in the `track` and `let` expressions of `@for` blocks.

Fixes #52132.

PR Close #52137
2023-10-10 11:19:41 -07:00
Phalgun Vaddepalli
644f3f2241 docs(core): add an example of configuring APP_INITIALIZER token in context of standalone components (#52084)
docs(core): fix formatting

PR Close #52084
2023-10-10 11:18:37 -07:00
Alex Rickabaugh
5411864c2e fix(core): adjust toSignal types to handle more common cases (#51991)
This commit cleans up the signatures of `toSignal` to better handle the
types of situations that it might be used in, and produce better type
inference results.

Fixes #50687
Fixes #50591

Co-authored-by: Andrew Scott <atscott@google.com>

PR Close #51991
2023-10-10 11:17:30 -07:00
Andrew Scott
1da28f4825 feat(router): Add callback to execute when a view transition is created (#52002)
This commit adds the ability to provide a function that will get called
immediately after the view transition is created. This will allow
developers to do things like add/remove classes from the DOM when the
transition animation is finished, skip the transition based on
application conditions, etc. Having access to the transition unlocks
just about every example outlined in https://developer.chrome.com/docs/web-platform/view-transitions.

Note that the timing of the `updateCallback` execution is in the spec as
being called asyncronously (https://drafts.csswg.org/css-view-transitions-1/#callbackdef-updatecallback).
This means the `onViewTransitionCreated` callback is guaranteed to
execute before the update callback which in turn means it is guaranteed
to execute before the view transition `ready`/animation. As a result, it
is safe/effictive to add classes to the document in the
`onViewTransitionCreated` function in order to control animations of
that transition and then remove those classes in the transition's `finished`
`Promise`. The animation also doesn't start until the `Promise` returned
by `updateCallback` resolves, so this would also guarantee that the
animation starts asynchronously.

resolves #51827

PR Close #52002
2023-10-10 11:16:22 -07:00
Angular Robot
5a4ccdfa7b build: update cross-repo angular dependencies (#52133)
See associated pull request for more information.

PR Close #52133
2023-10-10 10:58:45 -07:00
Jessica Janiuk
d487014785 fix(core): Remove no longer needed build rule related to removed migration (#52143)
This removes the esbuild rule for the migration that was removed.

PR Close #52143
2023-10-10 10:40:39 -07:00
Dylan Hunn
7c052bb6ef feat(language-service): Support autocompletion for blocks (#52121)
This commit introduces basic autocompletion support for the new block keywords. After typing `@`, the language service suggests the various block names.

PR Close #52121
2023-10-10 10:29:23 -07:00
Alex Rickabaugh
4da08dc2ef fix(core): remove unnecessary migration (#52141)
PR #49672 added a g3-flavored migration for compiler option removal, but g3
doesn't use those options at all. So this migration is unnecessary and we
can remove it.

PR Close #52141
2023-10-10 10:07:53 -07:00
Kristiyan Kostadinov
d5dad3eb4c fix(core): viewport trigger deregistering callbacks multiple times (#52115)
Adds a check to the viewport cleanup function to prevent it from re-processing elements that have been fully cleaned up, because it can lead to the `IntersectionObserver` being destroyed even though there are still pending triggers. This can happen, because we have cleanup callbacks both for the block is loaded, but also when the placeholder view is destroyed.

Fixes #52113.

PR Close #52115
2023-10-10 09:51:20 -07:00
Kristiyan Kostadinov
861ce3a7c5 fix(compiler): pipes using DI not working in blocks (#52112)
Fixes that the new block syntax was generating instructions in the wrong order which meant that pipes were being declared too early. This meant that if the block is first in the template, any pipes used in it won't be able to inject things like `ChangeDetectorRef`.

These changes update the compiler and add a bunch of tests to ensure that pipes work as expected.

Fixes #52102.

PR Close #52112
2023-10-10 09:48:37 -07:00
Kristiyan Kostadinov
ac0d5dcfd6 fix(compiler): narrow the type of expressions in event listeners inside switch blocks (#52069)
Since expressions in event listener are added inside of a callback, type narrowing won't apply to them anymore. These changes add the logic to create a guard expression that will re-narrow the expression in the callback.

Fixes #52052.

PR Close #52069
2023-10-10 09:47:47 -07:00
Kristiyan Kostadinov
16ff08ec70 fix(compiler): narrow the type of expressions in event listeners inside if blocks (#52069)
Since expressions in event listener are added inside of a callback, type narrowing won't apply to them anymore. These changes add the logic to create a guard expression that will re-narrow the expression in the callback.

Fixes #52052.

PR Close #52069
2023-10-10 09:47:47 -07:00
Kristiyan Kostadinov
503e67dca2 refactor(compiler): clean up compatibility code for old TS versions (#52099)
Cleans up some code that was left in place to support old versions of TypeScript.

PR Close #52099
2023-10-10 09:37:38 -07:00
Andrew Scott
37df395be0 fix(router): children of routes with loadComponent should not inherit parent data by default (#52114)
When a route has loadComponent, its children should not inherit params and
data unless paramsInheritanceStrategy is 'always'.

fixes #52106

BREAKING CHANGE: Routes with `loadComponent` would incorrectly cause
child routes to inherit their data by default. The default
`paramsInheritanceStrategy` is `emptyOnly`. If parent data should be
inherited in child routes, this should be manually set to `always`.

PR Close #52114
2023-10-10 09:36:37 -07:00
Matthieu Riegler
f0da7c2e44 feat(migrations): schematic to remove deprecated CompilerOptions properties (#49672)
`useJit` and `missingTranslation` have been deprecated since v13 and  are unused in Ivy. They can be safely removed.

PR Close #49672
2023-10-10 09:35:55 -07:00
Matthieu Riegler
40113f653c feat(core): Remove deprecated CompilerOptions.useJit andCompilerOptions.missingTranslation. (#49672)
Both properties have been deprecated in v13 and are unused in v16.

PR Close #49672
2023-10-10 09:35:55 -07:00
Kristiyan Kostadinov
229331e11b build: fix broken symbols test
Fixes a symbol test that broke on the main branch.
2023-10-10 09:12:28 +02:00
Angular Robot
b9a4941a32 build: update babel dependencies (#51898)
See associated pull request for more information.

PR Close #51898
2023-10-09 17:01:20 -07:00
Matthieu Riegler
c2f270cf14 refactor(compiler): Delete the @angular/compiler/testing module. (#49872)
The package was removed in components, it can now be deleted here also.

PR Close #49872
2023-10-09 15:58:25 -07:00
Andrew Kushnir
2eebd47733 refactor(core): make timer-related @defer logic tree-shakable (#52042)
This commit updates `@defer` logic related to handling `after` and `minimum` parameters tree-shakable.

If `after` or `minimum` was used on a `@loading` or `@placeholder` blocks, compiler generates an extra argument for the `ɵɵdefer` instruction. This extra argument is a reference to a function that brings timer-related code.

PR Close #52042
2023-10-09 15:57:59 -07:00
Payam Valadkhan
68ba798ae3 feat(core): revamp the runtime error message for orphan components to include full component info (#51919)
The error message now contains the code location of the component. It now looks like: "Error: NG01001: Orphan component found! Trying to render the component Main (at $PROJECT_ROOT/src/main.ts:8) without first loading the NgModule ..."

PR Close #51919
2023-10-09 15:57:03 -07:00
Payam Valadkhan
f12e1ef479 refactor(core): add a new stringifier for runtime errors which includes debug info such as the file path and line number (#51919)
The current error stringifier only includes the class name. In this change a new stringifier is added which returns a more helpful string which includes the file path and line number. Note that this is only the case with components, and for other class types (directive, pipes) it will fallback to the current stringifier. Subsequent changes can cover the case of directive and pipes as well.

PR Close #51919
2023-10-09 15:57:03 -07:00
Payam Valadkhan
9e7d243455 refactor(core): implement the runtime ɵsetClassDebugInfo for components (#51919)
A new field `debugInfo` is added to the component definition. Now the runtime  ɵsetClassDebugInfo stores the debug info for components in this new field.

PR Close #51919
2023-10-09 15:57:03 -07:00
Payam Valadkhan
7f9b32caee refactor(core): add an empty implementation for the runtime ɵsetClassDebugInfo (#51919)
This runtime will set the runtime debug info for the given angular class

PR Close #51919
2023-10-09 15:57:03 -07:00
Payam Valadkhan
acd468f804 refactor(compiler-cli): add debug info to components (#51919)
A new statement will be generated for components which will attach some useful debug info to them to be used in runtime error handling. Currently this only happens in full and local compilation modes.

PR Close #51919
2023-10-09 15:57:03 -07:00
Payam Valadkhan
421d790a1c refactor(compiler): compile debug info for angular classes (#51919)
A new utility function `compileClassDebugInfo` is introduced which creates compile result necessary to generate statement for attaching some useful debug info into angular classes. An example of teh new statement would be:

```
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(Main, { className: "Main", filePath: "$PROJECT_ROOT/src/main.ts", lineNumber: 8 }); })();
```

Currently, the debug info contains:
 - the class name
 - the file path in which it is defined
 - the line number in which it is defined

 The debug info will be used in runtime to generate more helpful error messages.

PR Close #51919
2023-10-09 15:57:03 -07:00
Andrew Scott
0ec66b85e6 refactor(core): Use flag instead of counter for dirty child transplanted views (#51515)
This commit updates the tracking of dirty child views to be a flag
rather than a counter. This is a much more simple method and less likely
to get into the same 'always-wrong' situation that could happen with the
counter (if it is off by 1 once, it's off by 1 forever and you either
get infinite change detection or your view is never refreshed).

PR Close #51515
2023-10-09 14:44:01 -07:00
Payam Valadkhan
11bb19cafc fix(compiler-cli): handle nested qualified names in ctor injection in local compilation mode (#51947)
The current implementation assumes a qualified name consists of just two identifier, e.g., Foo.Bar. However it can be more nested, like Foo.Bar.Baz.XX.YY. While such nested patterns are quite uncommon and devs mostly just use two identifier here, the TS compiler seems to throw error if we make such assumption and it broke quite a lot of targets in g3 when compiled in local mode. So here we handle this nested property of qualified names.

PR Close #51947
2023-10-09 14:34:55 -07:00
Kristiyan Kostadinov
29b876b16f refactor(compiler): clean up block syntax switch (#52091)
Now that the block syntax is fully rolled out, we don't need the switch constants anymore.

PR Close #52091
2023-10-09 13:41:02 -07:00
Andrew Kushnir
dbc14eb41d refactor(platform-browser): remove withNoDomReuse function (#52057)
This commit removes the `withNoDomReuse` function to minimize public API. The `withNoDomReuse` function used to disable DOM reuse, which is the main feature of the `provideClientHydration()`.

The `withNoDomReuse()` function was in the "developer preview" mode, so the removal happens without prior deprecation.

BREAKING CHANGE:

The `withNoDomReuse()` function was removed from the public API. If you need to disable hydration, you can exclude the `provideClientHydration()` call from provider list in your application (which would disable hydration features for the entire application) or use `ngSkipHydration` attribute to disable hydration for particular components. See this guide for additional information: https://angular.io/guide/hydration#how-to-skip-hydration-for-particular-components.

PR Close #52057
2023-10-09 13:36:16 -07:00
Angular Robot
4beeaf5724 build: update io_bazel_rules_sass digest to 6725d86 (#51844)
See associated pull request for more information.

PR Close #51844
2023-10-09 13:26:41 -07:00
Kristiyan Kostadinov
7368b8aaeb fix(core): host directive validation not picking up duplicate directives on component node (#52073)
Fixes that, depending on the matching and import order, in some cases we weren't throwing the error saying that a directive matched multiple times on the same element.

Fixes #52072.

PR Close #52073
2023-10-09 12:39:19 -07:00
Miles Malerba
acac9ea070 refactor(compiler): Separate param map serialization into a helper class (#51988)
Cleans up the i18n placeholder resolution phase by extracting the
details of how the map is serialized into its own class, instead of
mixing it with the phase's traversal logic.

PR Close #51988
2023-10-09 12:35:15 -07:00
Miles Malerba
ed2a20f490 refactor(compiler): Fix subTemplateIndex on template tags (#51988)
Template instructions exist in the parent view, but for the purposes of
the i18n placeholders, they should use the subTemplateIndex of the i18n
op wrapping their view.

PR Close #51988
2023-10-09 12:35:15 -07:00
Miles Malerba
371cd58eec refactor(compiler): Fix advance instructions for i18n expressions (#51988)
The custom logic in the generate advance phase for i18n expressions did
not work in all cases. Instead we add a new phase to update the
expression's target op, and then allow the standard advance generation
code to determine the number of advance instructions needed.

Co-authored-by: Dylan Hunn <dylhunn@users.noreply.github.com>

PR Close #51988
2023-10-09 12:35:15 -07:00
Miles Malerba
24b88b6f43 refactor(compiler): Add values for sub-template placeholders (#51988)
Fills in values for sub-template placeholders in i18n messages. This
includes both the tag placeholders for ng-template tags, as well as
merging in any placeholders from the child i18n block.

PR Close #51988
2023-10-09 12:35:15 -07:00
Miles Malerba
c3a83a8cec refactor(compiler): Add sub-template index to child i18n instructions (#51988)
Adds an additional sub-template index parameter to child i18n blocks
that are propagated from the root block. This additional paramete
indicates the index of the template in the i18n message.

Co-authored-by: Dylan Hunn <dylhunn@users.noreply.github.com>

PR Close #51988
2023-10-09 12:35:15 -07:00
Miles Malerba
d8bc6aa129 refactor(compiler): Propagate i18n blocks through child templates (#51988)
Adds a phase to the template pipeline to recursively create child i18n
blocks for ng-template views existing inside an i18n block.

PR Close #51988
2023-10-09 12:35:15 -07:00
Jeremy Elbourn
7bfe20707f feat(compiler): extract api for fn overloads and abtract classes (#52040)
This commit adds support for extracting function overloads. Interestingly, this worked in an earlier version when the code was extracting all statements in every source file, but the existing compiler API for extracting all exported declarations from an entry-point only returns the first function declaration in cases when there are overloads.

This also marks abstract classes as abstract, required inputs as required, and filters out Angular-private APIs.

PR Close #52040
2023-10-09 12:03:20 -07:00
Angular Robot
4a75c44b88 build: update all non-major dependencies (#52023)
See associated pull request for more information.

PR Close #52023
2023-10-09 12:01:32 -07:00
Andrew Kushnir
422e8582c4 refactor(core): support OnPush components in @defer blocks (#52095)
This commit adds the code to mark newly created embedded views (that represent `@defer` block states) as dirty to indicate that the view sgould be checked during the next change detection cycle.

Resolves #52094.

PR Close #52095
2023-10-09 10:55:38 -07:00
Kristiyan Kostadinov
386e1e9500 fix(compiler): work around TypeScript bug when narrowing switch statements (#52110)
We type check `@switch` blocks by generating identical TS `switch` statements in the TCB, however TS currently has a bug where parenthesized `switch` block expressions don't narrow their types. Since we use parenthesized expressions to wrap AST nodes for diagnostics, this will bug will affect all Angular-generated `switch` statements.

These changes work around the issue by generating `if`/`else if`/`else` statements that represent the `switch`.

Some alternatives that were considered:
1. Moving the `switch` expression to a constant - this is fairly simple to implement, but it won't fully resolve the narrowing issue since the same constant will have to be used in expressions inside the different cases.
2. Removing the outer-most parenthesis from the switch expression - this works and allows us to continue using switch statements, but because we use parenthesized expressions to map diagnostics to their template locations, I wasn't sure if it won't lead to worse template dignostics.

Fixes #52077.

PR Close #52110
2023-10-09 10:54:28 -07:00
Andrew Scott
023a181ba5 feat(language-service): Implement outlining spans for control flow blocks (#52062)
This commit implements the getOutlingSpans to retrieve Angular-specific
outlining spans. At the moment, these spans are limited to control-flow
blocks in templates.

This is required for folding ranges (https://github.com/angular/vscode-ng-language-service/issues/1930)

PR Close #52062
2023-10-09 10:20:26 -07:00
Pawel Kozlowski
28a5925f53 fix(common): use === operator to match NgSwitch cases (#51504)
This change adjust the equality comparator used by NgSwitch - now it
defaults to === from previously used ==. This change is based on the
following reasoning:
- align behaviour with the built-in switch block);
- improve performance (avoid type coercion);
- enable better type-checking.

BREAKING CHANGE:

the NgSwitch directive now defaults to the === equality operator,
migrating from the previously used ==. NgSwitch expressions and / or
individual condition values need adjusting to this stricter equality
check. The added warning message should help pinpointing NgSwitch
usages where adjustements are needed.

Fixes #33873

PR Close #51504
2023-10-09 10:10:21 -07:00
Nicolas Frizzarin
e25006b341 refactor(router): refactor documentation withHashLocation return type (#52016)
This improve the documentation of withHashLocation function by returning the correct type.

PR Close #52016
2023-10-09 08:54:44 -07:00
Kristiyan Kostadinov
753eb2459e build: fix broken symbols test (#52092)
Fixes a test that is broken on the main branch.

PR Close #52092
2023-10-09 08:06:11 -07:00
Pawel Kozlowski
00128e3853 fix(core): drop mutate function from the signals public API (#51821) (#51986)
This change removes the `mutate` method from the `WritableSignal` interface and
completely drops it from the public API surface.

The initial API proposal for Angular signals included the mutate method, allowing
in-place modification of JS objects, without changing their references (identity).
This was based on the reasoning that identity change on modification is not necessary
as we can send the “modified” notification through the signals graph.
Unfortunately the signal-specific change notification is lost as soon as we read
signal value outside of a reactive context (outside of a reactive graph).
In other words - any code outside of the Angular signals library can’t know
that an object is modified.

Secondly, to make the mutate method work, we’ve defaulted the signal value equality function
to the one that considers non-primitive values as always different.
This is unfortunate for people working with immutable data structures
(this is notably the case for the popular state management libraries)
as the default equality function de-optimizes memoization in computed,
making the application less performant.

Given the above reasons we prefer to remove the mutate method in the signals library -
at least for now. There are just too many sharp edges and tradeoffs that we don’t fully
understand yet.

BREAKING CHANGE:

The  `mutate` method was removed from the `WritableSignal` interface and completely
dropped from the public API surface. As an alternative please use the update method and
make immutable changes to the object.

Example before:

```typescript
items.mutate(itemsArray => itemsArray.push(newItem));
```

Example after:

```typescript
items.update(itemsArray => [itemsArray, …newItem]);
```

PR Close #51986
2023-10-06 15:12:00 -07:00
Alex Rickabaugh
8914eaf86d refactor(core): add consumerOnSignalRead hook to ReactiveNode (#51986)
This hook allows a consumer to create `ReactiveNode`s with custom behavior
when signals are read.

PR Close #51986
2023-10-06 15:12:00 -07:00