Commit Graph

12024 Commits

Author SHA1 Message Date
Matthieu Riegler a7b973eac5 docs(docs-infra): Use shiki for code highlighting (#57059)
PR Close #57059
2024-07-24 10:24:51 -07:00
Andrew Scott 0e439d78c2 Revert "fix(router): Scroller should scroll as soon as change detection completes (#55105)" (#57115)
This reverts commit 66ffeca2de.

It looks like nuxt encountered the same issue with scrolling when
waiting for Vue's `nextTick`, which is a microtask. This would have
similar timing to ZoneJS's rendering in the microtask queue. This
reverts to a `setTimeout` alone, though recreates the problem in #53985.
This was also mentioned in one of the comments in the Nuxt issue and the
solution would be `rAF`.

In order to address #53985, we'd likely want to use the `race(rAF, setTimeout)`
that we use in the zoneless and coalescing schedulers. This would have effectively the same timing as
the `afterNextRender` implementation here with zoneless, but quite
different timing to `afterNextRender` with ZoneJS.

fixes #57109

PR Close #57115
2024-07-24 10:04:38 -07:00
Tom Wilkinson 83117f1a0d refactor(core): Switch to using concat rather than spread operator for events. (#57103)
Internally, the JSCompiler does not dead code eliminate this code when its using spread.

PR Close #57103
2024-07-23 15:54:23 -07:00
Kristiyan Kostadinov bb977e0ba9 refactor(migrations): use common import manager for schematics (#57096)
Updates the schematics to reuse the common `ImportManager`, instead of having to maintain a separate one.

PR Close #57096
2024-07-23 12:17:41 -07:00
Kristiyan Kostadinov b464c3d786 refactor(compiler-cli): import manager not picking up some options (#57096)
Fixes that the `ImportManager` wasn't picking up some of its configuration options.

PR Close #57096
2024-07-23 12:17:41 -07:00
Kristiyan Kostadinov 6cbcef237e refactor(compiler-cli): add alias option to the import manager (#57096)
Updates the import manager to allow for a specific alias to be passed in. This is a prerequisite for switching schematics to the new import manager.

Note that passing in an alias disables identifier conflict resolution in order to avoid rewriting the alias that was passed in explicitly. For now this is fine since we have a very narrow use case for it, but we may want to revisit it in the future.

PR Close #57096
2024-07-23 12:17:41 -07:00
Paul Gschwendtner ad230630d6 test(migrations): adds golden tests for the signal input migration (#57082)
This commit adds golden tests for the signal input migration, along with
a tool to execute and automatically test the migration via the batch
mode, treating a single file as compilation unit.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner e0ff4f5386 refactor(migrations): add batching helper for signal migration (#57082)
This commit adds the batching logic helpers for running the signal
migration as a sharded/parallel action in Google3 and potentially
externally. The helpers are the main entry points for go/tsunami.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner 03b4c3b622 refactor(migrations): add main entry points for signal migration (#57082)
Adds the main entrypoint for the signal migration. These invoke the
individual phases and expose helpers.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner f1ad9f9893 refactor(migrations): add phase for migrating inputs and references (#57082)
Adds the migration phase for migrating inputs and references. Thise
phase may execute as the third step when batching.

The migration is intentionally split into three phases:

1. Extract and analyze
2. Inheritance merge / merge of metadata
3. Migrate

This allows us to batch the migration in Google3, or for large projects,
merge metadata, and then batch-execute migration for computation of
replacements. This is compatible with Google's LSC tsunami tool.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner 4c5081182f refactor(migrations): add advisors for problematic patterns (#57082)
E.g. detects `spyOn(myComp, 'input')`. This is problematic
as `input` no longer provides access to the raw value via property
access, but via a getter. The `spyOn` would be effictively a noop,
causing tests to fail. We skip such inputs for safety right now.

Similarly, we have an advisor for correcting type safety loss
with `.componentInstance` in unit tests. This is a common pattern
but is typed in Angular core as `any`. This breaks resolution of
references and we accidentally miss those. This advisor mitigates that.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner 466b647917 refactor(migrations): check for incompatible input patterns and inheritance (#57082)
Adds logic to the signal input migration for checking incompatible
patterns and inheritance.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner ed4f43cf64 refactor(migrations): logic for detecting and capturing references to inputs (#57082)
This commit adds the logic for detecting and capturing references to
Angular `@Input`s. Those references may be migrated to unwrap signals
as part of the migration; or are refactored into temporary variables.

This commit detects and captures:

- host bindings references
- template references
- TypeScript references

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner 95ef7f4146 refactor(migrations): add AST traversal for detecting references in templates and host bindings (#57082)
This commit adds logic for AST traversing Angular HTML templates and
detecting references to Angular `@Input`s that may be migrated.

In addition, the expression visitor logic is built in a generic way so
that it can also be used for finding references in host binding
expressions— where no type check block information is available.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner 9bda2c3fa3 refactor(migrations): initial logic for converting @Input() to input (#57082)
This commit includes the initial logic for converting `@Input()` to
`input`. The logic is not fully polished in terms of what use-cases
and patterns we want to generate, but it's working pretty stable
with testing in Angular Material and some g3 targets.

We may improve this and e.g. generate the `input()` shorthand in a
couple of cases.

The commit also includes some related helpers/parts that are needed
for the migration phases.

Notably the conversion phase is split up into preparation and migration.
That is necessary because as part of analysing we already try to
prepare to see if it's "possible". This is necessary for the global
metadata analysis, so that we can know that certain references are
incompatible across compilation units (e.g. when running as a batch).

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner b5d610062b refactor(migrations): phase for recognizing inputs in program (#57082)
This introduces the phase for recognizing inputs the migration
target program, extracting input metadata.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner a196c8d8db refactor(migrations): add initial helpers and registry for tracking inputs (#57082)
This commit adds the initial set of helpers and registries for tracking
inputs discovered in the signal input migration.

A few short summary notes:

- Every input has an unique key. This key is used for global analysis
  that may be performed when the migration is executed on a per
  individual unit basis in Google3 via e.g. go/tsunami — The keys allow
  us to build a combined global metadata for e.g. references or figuring
  out which inputs are incompatible or not.

- A known input may be _any_ input in an compilation unit/ the program.
  E.g. even inputs from `d.ts`. We keep track of these inputs so that we
  can later figure out if a reference `ts.Identifier` points to any of
  those. In addition it allows us to attach incompatibility metadata to
  those. I.e. incompatible for migration because "something writes to
  the input".

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner 521a8d287b refactor(migrations): initial flow analysis logic for input migration (#57082)
This commit introduces the initial flow analysis logic for the input
migration. The flow analysis will allow us to determine which references
inside a flow container participate potentially in narrowing.

We can then use this information and the proposed restructred accesses
to refactor the accesses to use temporary variables where needed. E.g.

```
if (this.input) {
  this.input.charAt(0);
}
```

```
const input_1 = this.input();
if (input_1) {
  input_1.charAt(0);
}
```

Notably we could easily, naively figure out similar references in a flow
container and always use temporary variables, but this approach allows
us to minimally introduce such variables and this commonly leaves code
very readable when no narrowing was involved (noticable in g3 tests)

E.g. simple cases like:

```
this.input.bla();
this.input.bla();
```

would otherwise result in refactored expressions, leveraging a temporary
variable.

PR Close #57082
2024-07-23 10:28:11 -07:00
Paul Gschwendtner a22f1428b7 refactor(compiler): support use of poisoned data as private compiler option (#57082)
This allows use of poisoned data for migrations. Right now, migrations
often enable this flag by creating some deeper structures of the
Angular compiler, but with this change it's easier to enable as a
private compiler option.

This is helpful for migrations, specifically the signal input migration
as it allows us to generate as much TCB code as possible, for reference
resolution.

PR Close #57082
2024-07-23 10:28:10 -07:00
Paul Gschwendtner bf853b7c67 refactor(compiler): expose information about inputs from inputs field (#57082)
This commit exposes metadata about inputs that are defined inside
the `inputs` field of `@Directive` or `@Component` class decorators

This is useful and necessary information for migrations, like the
signal inputs migration.

PR Close #57082
2024-07-23 10:28:10 -07:00
Andrew Scott 8718abce90 fix(core): Deprecate ignoreChangesOutsideZone option (#57029)
This option was introduced out of caution as a way for developers to opt out of the new behavior in v18 which schedule change detection for the above events when they occur outside the Zone. After monitoring the results post-release, we have determined that this feature is working as desired and do not believe it should ever be disabled by setting this option to `true`.

PR Close #57029
2024-07-23 10:10:48 -07:00
Kristiyan Kostadinov d4ff6bc0b2 fix(compiler-cli): add warning for unused let declarations (#57033)
Adds a new extended diagnostic that will flag `@let` declarations that aren't used within the template. The diagnostic can be turned off through the `extendedDiagnostics` compiler option.

PR Close #57033
2024-07-23 08:27:17 -07:00
Kristiyan Kostadinov 6c2fbda694 fix(compiler-cli): extended diagnostic visitor not visiting template attributes (#57033)
Fixes that the visitor which is used to implement template diagnostics isn't visiting the template attributes of structural directives.

PR Close #57033
2024-07-23 08:27:17 -07:00
Andrew Scott 4ac39aeea9 Revert "fix(compiler-cli): add warning for unused let declarations (#57033)" (#57088)
This reverts commit c76b440ac0.

PR Close #57088
2024-07-22 15:28:03 -07:00
Kristiyan Kostadinov fab673a1dd feat(core): add ng generate schematic to convert to inject (#57056)
Adds the new `ng generate @angular/core:inject-migration` schematic that will convert existing code from constructor-based injection to injection using the `inject` function. The migration also has a few options that should help reduce compilation errors.

This migration is slightly different than our usual ones in that it may have to update entire class or constructor declarations. We don't go through the `ts.factory.update*` APIs for this, because it can cause the entire declaration to be re-formatted. Instead, this migration tries to insert strings in a way that won't affect the user's formatting.

PR Close #57056
2024-07-22 14:39:45 -07:00
JoostK 08c5977bd5 fix(compiler): limit the number of chained instructions (#57069)
Some Angular template instructions that follow each other may be chained
together in a single expressions statement, containing a deeply nested
AST of call expressions. The number of chained instructions wasn't previously
limited, so this could result in very deep ASTs that cause stack overflow
errors during TypeScript emit.

This commit introduces a limit to the number of chained instructions to
avoid these problems.

Closes #57066

PR Close #57069
2024-07-22 11:50:12 -07:00
Rushikesh Kavar 13bc8d7d81 docs: Update packages/router/src/router.ts (#57053)
Co-authored-by: Andrew Scott <atscott01@gmail.com>
PR Close #57053
2024-07-22 10:52:36 -07:00
Rushikesh Kavar 4bbdab633d docs: Update packages/router/src/router.ts (#57053)
Co-authored-by: Andrew Scott <atscott01@gmail.com>
PR Close #57053
2024-07-22 10:52:36 -07:00
Rushikesh Kavar 65a0a0329a docs: adding reference to RouterModule.forroot method in Router service for better understanding for beginner (#57053)
PR Close #57053
2024-07-22 10:52:36 -07:00
Rushikesh Kavar 30aeb81899 docs: Adding Router service hierarchical injection level (#57053)
PR Close #57053
2024-07-22 10:52:36 -07:00
Kristiyan Kostadinov fe41b11434 fix(core): tree shake dev mode error message (#57035)
Adds an `ngDevMode` check before a runtime error message.

Fixes #57034.

PR Close #57035
2024-07-22 10:49:18 -07:00
Angular Robot 38e4802c7f build: update babel dependencies (#57045)
See associated pull request for more information.

Closes #56996 as a pr takeover

PR Close #57045
2024-07-19 13:46:00 -07:00
Thomas Nguyen 3664cd6cb2 refactor(core): Allow manual renderer listens to contribute to event delegation as well. (#56799)
There are existing usages that inject the renderer to manualy listen (often for event
delegation purposes). These should contribute as well.

PR Close #56799
2024-07-19 13:42:26 -07:00
Ashish Deshpande 4e6a42b215 docs: update broken link to version updates in versionEvent (#56870) (#56870)
PR Close #56870
2024-07-19 13:41:54 -07:00
Matthieu Riegler 7d4b2d2413 fix(core): afterNextRender hooks return that callback value. (#57031)
`afterRender` was working fine but `afterNextRender` wasn't

PR Close #57031
2024-07-19 13:40:59 -07:00
Kristiyan Kostadinov c76b440ac0 fix(compiler-cli): add warning for unused let declarations (#57033)
Adds a new extended diagnostic that will flag `@let` declarations that aren't used within the template. The diagnostic can be turned off through the `extendedDiagnostics` compiler option.

PR Close #57033
2024-07-19 11:50:32 -07:00
Tom Wilkinson 425f44c133 refactor(core): Move logic into early event contract files. (#56994)
Also remove some dead a11y code, now that a11y is in `ActionResolver`.

PR Close #56994
2024-07-18 12:05:17 -07:00
Alan Agius 658c7fe42d docs: fix changelog entry (#57038)
The entry incorrectly included a link.

PR Close #57038
2024-07-18 11:12:29 -07:00
Andrew Scott d97aee6dc2 release: cut the zone.js 0.14.8 release (#57030)
PR Close #57030
2024-07-17 14:03:01 -07:00
Alan Agius 982f1b1251 fix(zone.js): support Timeout.refresh in Node.js (#56852)
The `Timeout` object in Node.js has a `refresh` method, used to restart `setTimeout`/`setInterval` timers. Before this commit, `Timeout.refresh` was not handled, leading to memory leaks when using `fetch` in Node.js. This issue arose because `undici` (the Node.js fetch implementation) uses a refreshed `setTimeout` for cleanup operations.

For reference, see: https://github.com/nodejs/undici/blob/1dff4fd9b1b2cee97c5f8cf44041521a62d3f133/lib/util/timers.js#L45

Fixes: #56586

PR Close #56852
2024-07-16 12:46:51 -07:00
Matthieu Riegler 2c4613a002 fix(common): Don't run preconnect assertion on the server. (#56213)
The `window` global is patched by domino on the server but the value of `window.location.href` isn't a valid base.

Before this change `getUrl()` would throw when running in devmode on the server.

Fixes #56207

PR Close #56213
2024-07-16 09:53:33 -07:00
Matthieu Riegler e5e1f49a22 docs: Expose $localize in the @angular/localize/init entry. (#55345)
fixes #54388

PR Close #55345
2024-07-16 08:43:52 -07:00
Kristiyan Kostadinov e504ad97d4 fix(core): not all callbacks running when registered at the same time (#56981)
Fixes that only the first callback was firing when multiple are registered in the same call to `afterNextRender`, e.g. `afterNextRender({earlyRead: fn, read: fn});`

Fixes #56979.

PR Close #56981
2024-07-16 08:42:26 -07:00
Paul Gschwendtner 7663debce1 perf(language-service): quick exit if no code fixes can exist (#57000)
This is a performance optimization that would exit early when
code actions are requested, but we know Angular cannot provide fixes
based on the error codes.

Previously, we would unnecessarily compute and analyze the application
for semantic diagnostics.

This will be helpful for: https://github.com/angular/vscode-ng-language-service/pull/2050

PR Close #57000
2024-07-16 08:41:03 -07:00
Kristiyan Kostadinov 9167fc815c fix(compiler): JIT mode incorrectly interpreting host directive configuration in partial compilation (#57002)
Fixes that the runtime implementation of `ɵɵngDeclareDirective` was interpreting the `hostDirectives` mapping incorrectly. Instead of treating the inputs/outputs as `['binding', 'alias']` arrays, it was parsing them as `['binding: alias']`. This was leading to runtime errors if a user is consuming a partially-compiled library in JIT mode.

Fixes #54096.

PR Close #57002
2024-07-16 08:37:26 -07:00
Matthieu Riegler e958fa8a3c refactor(compiler): include public constructor paramters to class properties. (#56315)
Public properties declared in the constructor are part of the public API and we should extract them.

Fixes #56310

PR Close #56315
2024-07-15 11:39:21 -07:00
Paul Gschwendtner 4bb558ab0c feat(language-service): support writing code refactorings (#56895)
In addition to quick fixes, this commit adds the ability to write
code refactoring actions that can be applied by users.

For example, we may implement a migration as a code refactoring action.
Notably the quick fix support, existing already, is insufficient as it
only allows for edits to be applied based on diagnostics shwon in e.g.
VSCode.

PR Close #56895
2024-07-15 11:35:40 -07:00
Kristiyan Kostadinov f0d6d0688d fix(compiler-cli): avoid emitting references to typecheck files in TS 5.4 (#56961)
In #56358 we removed most of the places that untag the references to typecheck files, because it was causing the compiler to throw error when it produces diagnostics. This appears to have caused a regression in TS 5.4 which now emits the synthetic references.

These changes add tagging right before the program emits.

Fixes #56945.

PR Close #56961
2024-07-15 11:22:00 -07:00
Jessica Janiuk 0ea6a4a361 fix(migrations): fix common module removal (#56968)
This fixes the case that common module is removed on a second run of the migration. We were not looking at block parameters for common module usage.

PR Close #56968
2024-07-15 11:17:46 -07:00
Matthieu Riegler 38b93201c5 refactor(compiler-cli): Extract call signatures from interfaces. (#56973)
This commit adds support for extracting call signals from interfaces.

fixes #56969

PR Close #56973
2024-07-15 11:07:57 -07:00