Commit graph

12272 commits

Author SHA1 Message Date
Pawel Kozlowski
a7eff3ffaa feat(core): mark signal-based query APIs as stable (#57921)
This commit marks the contentChild, contentChildren, viewChild
and viewChildren APIs (along with any associated APIs) as stable
and thus exits the dev preview
phase for those APIs.

PR Close #57921
2024-09-24 12:34:37 +02:00
Andrew Scott
48216a28e8 refactor(router): Move view transitions to developer preview (#55600)
Nothing of concern arose during the time this feature was in the
experimental phase. There are no plans to change the shape of the API.

This change also updates the route animations documentation to use the
view transitions feature instead of the old and difficult to follow
guide that used the animations package. The content was taken from the
blog post: https://blog.angular.io/check-out-angulars-support-for-the-view-transitions-api-3937376cfc19

PR Close #55600
2024-09-24 12:07:02 +02:00
Matthieu Riegler
5a04837c54 refactor(core): replace non output EventEmitter with Subject. (#54666)
Semantcly we're shifting away from using `EventEmitter` on non-outputs.

PR Close #54666
2024-09-24 11:58:24 +02:00
Matthieu Riegler
b23113dc96 refactor(common): replace non output EventEmitter with Subject. (#54666)
Semantcly we're shifting away from using `EventEmitter` on non-outputs.

PR Close #54666
2024-09-24 11:58:24 +02:00
Angular Robot
9f5798e511 build: update dependency @rollup/plugin-commonjs to v28 (#57929)
See associated pull request for more information.

PR Close #57929
2024-09-24 11:48:50 +02:00
Matthieu Riegler
6c9abd38fb refactor(forms): lift circular deps (#55881)
`import type` to the rescue.

PR Close #55881
2024-09-23 16:24:05 +02:00
Charles Lyding
7b2fda16b1 refactor(platform-browser): reduce runtime code size of shared style host (#57834)
The `SharedStylesHost` class has been refactored to both reduce the runtime
code size and also modernize some of the code structures. The class is also
adjusted to better support reuse via subclassing or other reuses in the future.
Additional comments have been added to improve readability as well.
The code reduction in a prerelease newly generated Angular CLI application
for production is ~410 bytes.

Before:
```
Initial chunk files   | Names         |  Raw size | Estimated transfer size
main-GOQKBZBZ.js      | main          | 208.67 kB |                56.41 kB
polyfills-FFHMD2TL.js | polyfills     |  34.52 kB |                11.28 kB
styles-5INURTSO.css   | styles        |   0 bytes |                 0 bytes

                      | Initial total | 243.19 kB |                67.69 kB
```

After:
```
Initial chunk files   | Names         |  Raw size | Estimated transfer size
main-CRTDDKPH.js      | main          | 208.26 kB |                56.32 kB
polyfills-FFHMD2TL.js | polyfills     |  34.52 kB |                11.28 kB
styles-5INURTSO.css   | styles        |   0 bytes |                 0 bytes

                      | Initial total | 242.78 kB |                67.61 kB
```

PR Close #57834
2024-09-23 14:22:58 +02:00
Paul Gschwendtner
04a48736b1 refactor(migrations): add TODO for special output of signal input migration (#57918)
Sometimes we may insert `undefined!` or `any`. We should add a TODO in
those cases.

PR Close #57918
2024-09-23 13:41:48 +02:00
Paul Gschwendtner
7d74ab8ba3 refactor(migrations): improve logging of signal input migration (#57918)
The program preparation may take longer than the short analysis, given
potential larger projects. We should print this.

PR Close #57918
2024-09-23 13:41:48 +02:00
Paul Gschwendtner
d1391ceaad refactor(migrations): fix peformance.now() not available in input schematic (#57913)
In schematics, `performance.now()` is not available. This breaks
execution.

PR Close #57913
2024-09-23 12:43:53 +02:00
Paul Gschwendtner
304bb3b274 refactor(migrations): remove imports to QueryList in signal queries migration (#57919)
With this commit, we remove imports to `QueryList` whenever possible.

PR Close #57919
2024-09-23 12:43:17 +02:00
Paul Gschwendtner
505c0f788e refactor(migrations): add better explanation on what color diff represents in testing (#57919)
This clarifies what colors mean in the Tsurge text diff Jasmine matcher.

PR Close #57919
2024-09-23 12:43:17 +02:00
cexbrayat
eb77b533b8 refactor(migrations): avoid TS error 18003 when no files found (#57899)
When running a migration, tsurge creates a TS program from the tsconfig files found.
This can result in a 18003 error when no files are found (based on the includes/files of the config).

For example, the signal input migration throws in a CLI project that has no spec files:

```
ng g @angular/core:signal-inputs --defaults
Tsconfig could not be parsed or is invalid:

No inputs were found in config file '/tsconfig.spec.json'. Specified 'include' paths were '["src/**/*.spec.ts","src/**/*.d.ts"]' and 'exclude' paths were '["/out-tsc/spec"]'.
```

A similar issue has already been raised in the CDK migration (see https://github.com/angular/components/issues/27055).

This was solved in the CDK (credits to @crisbeto) by ignoring the 18003 error (see 9c1112d408361a47c98dfd470b8e990cbd1753db).

This PR does the same in tsurge.

PR Close #57899
2024-09-23 12:42:33 +02:00
Paul Gschwendtner
101d162d6d refactor(migrations): support inserting TODOs for skipped input fields (#57898)
This is a helpful option to retrieve some insights on why certain inputs
were not migrated.

PR Close #57898
2024-09-23 12:41:34 +02:00
Paul Gschwendtner
5bb7050c59 refactor(migrations): add common helpers for inserting TODOs (#57898)
Adds a common helper for inserting TODOs to Tsurge.

PR Close #57898
2024-09-23 12:41:34 +02:00
Dylan Hunn
7ecfd89592 fix(language-service): The suppress diagnostics option should work for external templates (#57873)
Previously, due to a bug, this option only worked for inline templates.

PR Close #57873
2024-09-23 12:03:30 +02:00
ChinoUkaegbu
d30cef290d docs(core): update wording in ComponentDecorator (#57878)
PR Close #57878
2024-09-23 11:59:08 +02:00
Andrew Kushnir
6b239535e8 docs: declare Event Replay feature as stable (#57895)
This commit drops the `@developerPreview` annotation from the `withEventReplay()` function, which effectively makes the Event Replay feature stable.

PR Close #57895
2024-09-23 11:41:52 +02:00
Andrew Scott
950a5540f1 fix(core): Ensure the ViewContext is retained after closure minification (#57903)
In order to survive closure minification correctly, static properties need to
be annotated with `@nocollapse`.

For more history, see https://github.com/angular/angular/pull/28050

PR Close #57903
2024-09-20 14:01:26 -07:00
Andrew Scott
a1f229850a feat(core): migrate ExperimentalPendingTasks to PendingTasks (#57533)
This commit promotes the `ExperimentalPendingTasks` service from
experimental to developer preview and includes a migration schematic for
the rename.

BREAKING CHANGE: `ExperimentalPendingTasks` has been renamed to
`PendingTasks`.

PR Close #57533
2024-09-20 18:26:48 +02:00
Paul Gschwendtner
ef5412c9bc refactor(migrations): fix virtual devkit file system not detecting directories (#57897)
The compiler and its file system implementation expects `fs.exists` to
return `true` even for directories. This caused issues with the TSConfig
resolution as `/` was looked up.

We fix this by making use of `stat` which is equally expensive to
`tree.exists`. The devkit tree's don't expose directory existance checks
out of the box.

Fixes #57887.

PR Close #57897
2024-09-20 15:06:33 +02:00
Paul Gschwendtner
88f2fe4387 test(migrations): fix batch test for signal input migration (#57883)
The batch test (not running on CI due to memory/resource constraints) currently fails
after refactorings we did recently. This commit fixes that there were
two different instances of `sourceFiles string[]`.

PR Close #57883
2024-09-20 12:19:11 +02:00
Paul Gschwendtner
8b632dbdb6 refactor(migrations): simplify and improve inheritance checking in input migration (#57883)
Instead of running inheritance checking for analyze and migration phases
(in batch mode), we can run once and create a mini-graph in the
compilation unit data. This can then improve lookups and propagation of
incompatibilities.

This commit fixes an issue where a class is chained between three
isolated units and members are overriden. Currently this pattern would
not be checked properly and e.g. an incompatibility of the superclass
would not propagate to derived class, or deeper.

PR Close #57883
2024-09-20 12:19:11 +02:00
Paul Gschwendtner
4ea8ad6f55 refactor(migrations): reduce bytes of merged compilation unit in input migration (#57883)
This reduces the bytes of the merged compilation unit data, so that we
don't have to transer gigabytes of data to every batch worker. This
reduces quota and helps with reliablity of the migration in 1P.

The references metadata was never needed across units, but an initial
idea to e.g. allow for issuing of CLs based on a graph that we build
after changes computation

PR Close #57883
2024-09-20 12:19:11 +02:00
Paul Gschwendtner
4993dd51e6 refactor(migrations): improve ergonomics of performance improvement for reference lookup (#57883)
This would allow us to have better control over reference lookups
without needing a whole new set of `KnownFields` or `KnownInputs`.

PR Close #57883
2024-09-20 12:19:11 +02:00
Paul Gschwendtner
d8aba1d901 refactor(migrations): automatically skip inputs outside of project (#57883)
Currently we support filtering files outside of the project, or source
files via `shouldMigrateInput` option. This works well, but we can
smartly skip inputs in batch migrations if we never saw a source
declaration.

This is an improvement in G3 where we cannot simply limit the migration
to a given directory, because we may include build targets from various
places. E.g. via reverse dependency tracking— so this fixes the issue
naturally.

Notably, an explicit filter would improve reference lookups because we
wouldn't consider the input when determining potential references. That
is because we would know beforehand that those inputs in the `.d.ts`
cannot be migrated inputs— and therefore references with names of the
input would never be verified via expensive type checking.

This is fine for G3 though, and there is no way around this. This is a
slow performance overhead; mostly releveant for VSCode integration.

PR Close #57883
2024-09-20 12:19:11 +02:00
Alex Rickabaugh
fc59e2a7b7 feat(core): change effect() execution timing & no-op allowSignalWrites (#57874)
This commit flips the flag that was added in 4e890cc, putting the new effect
timing into... effect :)

BREAKING CHANGE:

Generally this PR has two implications:

* effects which are triggered outside of change detection run as part of
  the change detection process instead of as a microtask. Depending on the
  specifics of application/test setup, this can result in them executing
  earlier or later (or requiring additional test steps to trigger; see below
  examples).

* effects which are triggered during change detection (e.g. by input
  signals) run _earlier_, before the component's template.

We've seen a few common failure cases:

* Tests which used to rely on the `Promise` timing of effects now need to
  `await whenStable()` or call `.detectChanges()` in order for effects to
  run.

* Tests which use faked clocks may need to fast-forward/flush the clock to
  cause effects to run.

* `effect()`s triggered during CD could rely on the application being fully
  rendered (for example, they could easily read computed styles, etc). With
  the change, they run before the component's updates and can get incorrect
  answers. The recent `afterRenderEffect()` API is a natural replacement for
  this style of effect.

* `effect()`s which synchronize with the forms system are particularly
  timing-sensitive and might need to adjust their initialization timing.

Fixes #55311
Fixes #55808
Fixes #55644
Fixes #56863

PR Close #57874
2024-09-19 14:17:56 -07:00
Alex Rickabaugh
4e890cc5ac refactor(core): add support for new effect scheduling. (#56501)
The original effect design for Angular had one "bucket" of effects, which
are scheduled on the microtask queue. This approach got us pretty far, but
as developers have built more complex reactive systems, we've hit the
limitations of this design.

This commit changes the nature of effects significantly. In particular,
effects created in components have a completely new scheduling system, which
executes them as a part of the change detection cycle. This results in
behavior similar to that of nested effects in other reactive frameworks. The
scheduling behavior here uses the "mark for traversal" flag
(`HasChildViewsToRefresh`). This has really nice behavior:

 * if the component is dirty already, effects run following preorder hooks
   (ngOnInit, etc).
 * if the component isn't dirty, it doesn't get change detected only because
   of the dirty effect.

This is not a breaking change, since `effect()` is in developer preview (and
it remains so).

As a part of this redesigned `effect()` behavior, the `allowSignalWrites`
flag was removed. Effects no longer prohibit writing to signals at all. This
decision was taken in response to feedback / observations of usage patterns,
which showed the benefit of the restriction did not justify the DX cost.

The new effect timing is not yet enabled - a future PR will flip the flag.

PR Close #56501
2024-09-18 14:52:25 -07:00
Kristiyan Kostadinov
f611faadfe fix(compiler-cli): extended diagnostics not validating ICUs (#57845)
The visitor that all extended diagnostics are based on hadn't implemented the `visitIcu` method which meant that it wasn't detecting any code inside of them.

Fixes #57838.

PR Close #57845
2024-09-18 09:48:20 +02:00
Paul Gschwendtner
d0a71a33b1 refactor(migrations): check inheritance in signal queries migration (#57854)
Notably the inheritance checking is less complete as the one in the
input migration. That is because we can't efficiently determine query
fields in the analyze phase of compilation units. Unless we aggresively
consider every field of decorated classes as queries and complexify
the merged metadata significantly, we can't reliably check for cases
where a class is incompatible for migration because it overrides a
member from a class that is in a different compilation unit.

This is an acceptable limitation though (maybe for now), as worst case,
we would migrate the class and the other compilation unit would simply
break. Not ideal, but migrations are impossible to be 100% correct in
general— so not a surprise.

In the future, we may find ways to identify queries more reliably in
analyze phase already. e.g. if the compiler were to include this
metadata in the `.d.ts`, or if we decide to simply add this to the
metadata, accepting potential significant HDD increase.

PR Close #57854
2024-09-18 09:45:20 +02:00
Matthieu Riegler
4231e8f28f fix(core): Handle @let declaration with array when preparingForHydration (#57816)
Before this commit, `@let` decleration with an array where  mistaken for a component in the lView and throwing an unexpected error.

This commit fixes this.

PR Close #57816
2024-09-17 16:29:39 +02:00
Paul Gschwendtner
8ecafce2d9 refactor(migrations): do not run optional TCB operations in input migration (#57835)
Optional operations that don't run in the actual application compilation
would then cause fatal diagnostic errors breaking the compiler
initialization at runtime.

We should try to keep the migration as close as possible to the
application build.

PR Close #57835
2024-09-17 11:08:37 +02:00
Paul Gschwendtner
4e05a6f299 refactor(migrations): share problematic pattern detection code (#57835)
This allows us to use the inheritance checks we built for the signal
input migration, inside the queries migration.

PR Close #57835
2024-09-17 11:08:37 +02:00
Paul Gschwendtner
64c76b79db refactor(migrations): prepare for sharing problematic pattern recognition (#57835)
This commit prepares us for sharing the problematic pattern detection,
or inheritance checking. E.g. if a class is manually instantiated, using
certain APIs may not be considered safe. This logic will be shared in
the following commit.

PR Close #57835
2024-09-17 11:08:37 +02:00
Kristiyan Kostadinov
39098f3a9b refactor(compiler): finalize hydrate syntax (#57831)
Finalizes compiler implementation of the new `hydrate` triggers by:
* Reworking the logic that was depending on the `hydrateSpan` to distinguish hydrate triggers from non-hydrate triggers.
* Fixing that the `hydrate when` trigger didn't have a `hydrateSpan`.
* Adding an error if a parameter is passed into a `hydrate` trigger.
* Add an error if other `hydrate` triggers are used with `hydrate never`.
* Replacing the `prefetch` and `hydrate` flags in the template pipeline with a `modifiers` field.
* Fixing an error that was being thrown when reifying `hydrate` triggers in the pipeline.
* Adding quick info support for the `hydrate` keyword in the language service.
* Adding some tests for the new logic.

PR Close #57831
2024-09-17 11:05:17 +02:00
Jessica Janiuk
79b54bba9c refactor(compiler): initial integration of hydrate triggers into the compiler (#57831)
Sets up the AST for hydrate triggers.

PR Close #57831
2024-09-17 11:05:17 +02:00
Paul Gschwendtner
59fe9bc772 feat(migrations): introduce signal input migration as ng generate schematic (#57805)
Introduces a new `ng generate` schematic for migration `@Input()`
declarations to signal inputs.

This migration is the same that is also integrated into the
VSCode extension.

Note: In a follow-up the documentation for this will be improved, and a
flag to report reasons on why certain inputs weren't migrated, is added.

PR Close #57805
2024-09-16 18:06:49 +02:00
Paul Gschwendtner
6cdcf5d6ca refactor(compiler-cli): respect configured file system when parsing tsconfig (#57805)
Whenever the `ngc` binary is used directly to parse configurations, we
should try to respect the configured file system like we do in all other
places. Right now one spot where we escape the FS is for reading
directories to e.g. support tsconfig#includes.

This commit fixes this, implementing TypeScript's read directory method
leveraging the configured FS. The approach taken here was used for a
couple of months/years for Angular Material migrations and no issues
were found.

PR Close #57805
2024-09-16 18:06:49 +02:00
Charles Lyding
149d69e47c refactor(compiler): allow internal style encapsulation helper to directly encapsulate for a component (#57809)
For component stylesheet hot module replacement scenarios, it will be necessarily to directly
encapsulate a component's stylesheet in a single operation. This currently requires the
consumer of the `encapsulateStyle` helper to use the internal Angular attribute values combined
with a find/replace over the entire stylesheet. To avoid both of these, the helper function now
has an optional second parameter which allows direct and full encapsulation of a style for a given
component when the component identifier is known.

PR Close #57809
2024-09-16 12:14:57 +02:00
Pawel Kozlowski
1b1519224d feat(core): mark input, output and model APIs as stable (#57804)
This commit marks the input, output and model APIs as stable
(along with the associated APIs) and thus exits the dev preview
phase for those APIs.

PR Close #57804
2024-09-16 12:13:47 +02:00
Matthieu Riegler
41c212d604 refactor(migrations): Keep standalone:true (#57717)
This commit also adds the support of handling standalone proparties assigned by variables (or via shorthand assignments).

PR Close #57717
2024-09-16 12:12:33 +02:00
Paul Gschwendtner
fd081e8ee4 refactor(migrations): add compiler filesystem for devkit virtual tree (#57794)
The file system will be used for dev-kit wiring up of Tsurge migrations
in e.g. `ng generate` and `ng update`

PR Close #57794
2024-09-13 14:13:58 +02:00
Andrew Scott
3ebe6b4ad4 feat(core): Add async run method on ExperimentalPendingTasks (#56546)
This helper method is simply a convenience function that reduces some
boilerplate with manually adding and removing a task around some
asynchronous function.

PR Close #56546
2024-09-13 11:10:08 +02:00
Kristiyan Kostadinov
6144612940 fix(migrations): account for explicit standalone: false in migration (#57803)
Fixes that the standalone migration was duplicating the `standalone` flag if the declaration was `standalone: false`.

PR Close #57803
2024-09-13 10:48:42 +02:00
Paul Gschwendtner
73feb0e7bc refactor(migrations): support reference migration in query migration (#57777)
The query migration will now fully re-use the reference resolution and
migration logic from the input migration to reliably migrate references
to the new signal properties, supporing control flow outsourcing etc.

PR Close #57777
2024-09-11 17:48:29 +00:00
Paul Gschwendtner
cf306d7ad7 refactor(migrations): follow-up improvements to shared reference resolution (#57777)
Moves leftover files that are related to resolution into the resolution
logic directory.

PR Close #57777
2024-09-11 17:48:29 +00:00
Paul Gschwendtner
2591b988ce refactor(migrations): add jasmine diff matcher to tsurge testing utilities (#57777)
Commonly when testing Tsurge migrations, we need to diff text content of
files. This commit adds a colored diff helper that makes writing tests
much easier.

PR Close #57777
2024-09-11 17:48:29 +00:00
Paul Gschwendtner
1c663ca820 refactor(migrations): add helper for dedenting to tsurge (#57777)
Dedenting the smallest leading whitespace is useful for conveniently
testing the output of a migration. This commit includes the helper in
Tsurge.

PR Close #57777
2024-09-11 17:48:29 +00:00
JoostK
c93b510f9b feat(core): allow passing undefined without needing to include it in the type argument of input (#57621)
This commit introduces an overload for `input` to accept `undefined` as initial value if only
options are needed to be provided, inferring an input of type `T|undefined`. Prior to this change,
the type argument as specified needed to include `|undefined` explicitly even though that isn't
necessary when passing options isn't needed.

Relates to #53909

PR Close #57621
2024-09-11 14:28:19 +00:00
Matthieu Riegler
c15e72a0eb refactor(core): extract assertNotDestroyed as function. (#57692)
This will allow the mangling of the method name

PR Close #57692
2024-09-11 14:27:35 +00:00