Commit graph

12057 commits

Author SHA1 Message Date
Paul Gschwendtner
e2259c7b09 fix(compiler-cli): support JIT transforms before other transforms modifying classes (#57262)
Similar to a previous fix that intended to make the JIT transforms
compatible with pre-transforms like e.g. Tsickle, we need to solve
an additional issue where the class properties are synthetic and result
in an `getSourceFile() => undefined` invocation that breaks the import
insertion, causing errors like:

```
TypeError: Cannot read properties of undefined (reading 'fileName')
```

PR Close #57262
2024-08-05 14:45:19 +00:00
Angular Robot
dbca467a35 build: lock file maintenance (#57256)
See associated pull request for more information.

PR Close #57256
2024-08-05 14:42:24 +00:00
Andrew Scott
99d679d606 feat(zone.js): Add 'flush' parameter option to fakeAsync to flush after the test (#57137)
From the internal issue on the matter:

> When using the standard Jasmine version of it promises returned by the body function are automatically awaited. The Catalyst version of it is fake-async, so awaiting the promise does not make sense; however it would be nice if Catalyst automatically flushed the promise to replicate the experience of using standard it. This would allow users to do the following:

```
it('should fail later', async () => {
  await new Promise(r => setTimeout(r));
  fail('failure');
});
```
> In Catalyst today the above test will pass. If this proposal to automatically flush the resulting promise were implemented it would fail.

Flushing after the tests complete has been the default behavior inside
Google since 2020. Very few tests remain that use the old behavior of
only flushing microtasks. The example above would actually fail with
`fakeAsync` due to the pending timer, but the argument still remains the
same. We might as well just flush if we're going to fail the test
anyways by throwing if there's no flush at the end.

PR Close #57137
2024-08-02 16:52:07 +00:00
Andrew Scott
827070e331 fix(core): Do not run image performance warning checks on server (#57234)
These checks require document so they should not be run on the server.

PR Close #57234
2024-08-02 15:53:29 +00:00
Charles Lyding
4bb9d0f923 fix(language-service): avoid generating TS suggestion diagnostics for templates (#56241)
Angular's template files are not valid TypeScript. Attempting to get suggestion
diagnostics from the underlying TypeScript language service will result in
a large amount of false positives. Only actual TypeScript files should
be analyzed by the underlying TypeScript language service for suggestions.

PR Close #56241
2024-08-02 15:51:35 +00:00
Andrew Scott
6c76c91e15 feat(router): Add defaultQueryParamsHandling to router configuration (#57198)
This commit adds an option to specify the default value for
`queryParamsHandling` in `Router.createUrlTree` when another option is
not specified (or is `null|undefined`).

resolves #12664

PR Close #57198
2024-08-02 15:11:38 +00:00
Thomas Nguyen
2a915d1912 refactor(core): Remove clickmod support from Angular. (#57201)
This was an old feature that mapped shift + click (et al) to "clickmod". This doesn't really make sense to add to Angular, so let's remove it.

PR Close #57201
2024-08-02 14:20:53 +00:00
Jessica Janiuk
d73a3741a2 Revert "fix(compiler): reduce chance of conflicts between generated factory and local variables (#57181)" (#57230)
This reverts commit 67e09404db.

PR Close #57230
2024-08-01 19:33:04 +00:00
Paul Gschwendtner
187666480f test: update symbol golden after lock file maintenance (#57205)
Lock file maintenance updated Terser, which impacts the bundle
optimizations being tested via the symbol golden tests.

There was a small noticable change in the symbol golden where
`withDomHydration` is now preserved, and the underlying function
that was previously detected is gone. Seemingly Terser now inlines
this function and had to preserve `withDomHydration` as the entry point.

PR Close #57205
2024-07-31 16:02:11 +00:00
Paul Gschwendtner
2d314865c8 build: lock file maintenance (#57205)
See associated pull request for more information.

PR Close #57205
2024-07-31 16:02:11 +00:00
Paul Gschwendtner
e11c0c42d2 fix(compiler-cli): run JIT transforms on @NgModule classes with jit: true (#57212)
This commit is similar to 98ed5b609e, and
makes use of the preparation work implemented there.

Similar to directives and components marked via `jit: true`, we also
need to do the same for JIT marked `@NgModule` classes. This is mostly
important for downleveling of decorators to support dependency injection
of such classes.

Inside Google3, migrating from `ts_library` to `ng_module` turns of
decorator downleveling, so the `jit: true` for NgModule's is implicitly
requesting/reliant on this transform— as expected.

PR Close #57212
2024-07-31 14:14:14 +00:00
Enea Jahollari
147eee4253 feat(migrations): add migration to convert standalone component routes to be lazy loaded (#56428)
This schematic helps developers to convert eagerly loaded component routes to lazy loaded routes

PR Close #56428
2024-07-30 20:00:37 +00:00
Andrew Scott
b558f99150 refactor(core): Update callback schedulers to cancel pending timers (#57186)
Rather than leaving the timers around as no-ops, this commit updates the
logic to also attempt to clear or cancel the timers. This is helpful for
the eventual goal of running the scheduler in the `fakeAsync` zone (if
the test is running in `fakeAsync`) rather than scheduling in the root
zone and making it impossible to flush.

PR Close #57186
2024-07-30 18:05:09 +00:00
Andrew Scott
b3836c2f1c refactor(core): Private option to rethrow ApplicationRef.tick errors in tests (#57153)
This creates a private option that can be used internally while we
migrate this to the default and only behavior. ~200 tests in TGP have errors
that are being swallowed (console.log) and not causing the test to fail.
We can first explicitly opt those out, flip the default internally, then
"fix" them by adding expect...toThrow.

PR Close #57153
2024-07-30 18:04:27 +00:00
Andrew Scott
2a4f488a6c fix(core): warnings for oversized images and lazy-lcp present with bootstrapModule (#57060)
This commit adds the `ImagePerformanceWarning` to the common bootstrap
code rather than only starting it when using `bootstrapApplication`.

PR Close #57060
2024-07-30 18:03:35 +00:00
Andrew Scott
3da0254478 refactor(core): de-duplicate bootstrap code between bootstrapApplication and bootstrapModule (#57060)
This commit de-duplicates the code for bootstrapping between
`bootstrapApplication` and `bootstrapModule`. A majority of the
bootstrap code was identical between the two, with some minor
differences that can be handled with a function overload.

PR Close #57060
2024-07-30 18:03:35 +00:00
Andrew Scott
3459289ef0 feat(core): bootstrapModule can configure NgZone in providers (#57060)
This commit allows configuring `NgZone` through the providers for
`bootstrapModule`. Prior to this change, developers had to configure
`NgZone` in the `BootstrapOptions`.

PR Close #57060
2024-07-30 18:03:35 +00:00
Bouguima, Walid
03553c485d docs: broken HammerLoader reference fix (#55836)
*Fixing broken documentation reference to HammerLoader in HammerLoaderInjectionToken page

PR Close #55836
2024-07-30 16:56:33 +00:00
Kristiyan Kostadinov
a752178f28 fix(core): hydration error in some let declaration setups (#57173)
Fixes that we were throwing an assertion error during hydration if a `@let` declaration is used before and immediately inside of a container.

Fixes #57160.

PR Close #57173
2024-07-30 16:43:46 +00:00
Joey Perrott
2d8635d29d refactor(docs-infra): migrate @angular/docs from dev-infra into adev directory (#57132)
To increase the ease of development we are moving @angular/docs into the adev directory within this repo. While
we are doing this to improve our development experience in the short term, efforts are also in place
to maintain a division between this @angular/docs (shared) code and adev itself, so that it can be extracted
back out in the future when components is ready to leverage it as well.

PR Close #57132
2024-07-30 15:51:26 +00:00
Andrew Scott
3a63c9ebbe fix(core): errors during ApplicationRef.tick should be rethrown for zoneless tests (#56993)
The behavior of `ComponentFixture` for zoneless tests was decided somewhat through guesswork, trial, and error. In addition, working on the zoneless fixture revealed oddities in the behavior of the zone-based fixture, or behaviors that we felt were counterintuitive. The most consequential difference is how change detection works: `detectChanges` goes through ApplicationRef.tick in zoneless while it is `changeDetectorRef.detectChanges` in the zone fixture.

We felt that running change detection through `ApplicationRef.tick` was important for several reasons:
* Aligning application behavior more closely with the test behavior (almost all views are attached to application ref in reality)
* Ensuring that afterRender* hooks are executed when calling `fixture.detectChanges`
* Ensuring that the change detection runs again if render hooks update state

This change, however, has some noticeable consequences that will break some tests, mostly around how errors are handled. `ApplicationRef.tick` catches errors that happen during change detection and reports them to the ErrorHandler from DI. The default error handler only logs the error to the console. This will break tests which have `expect(() => fixture.detectChanges()).toThrow()`. In addition, it allows tests to pass when there are real errors encountered during change detection.

This change ensures that errors from `ApplicationRef.tick` are rethrown
and will fail the test. We should also do a follow-up investigation to
determine whether we can/should also do this for the zone-based
`ComponentFixture`.

fixes #56977

PR Close #56993
2024-07-29 13:49:00 -07:00
Kristiyan Kostadinov
ba0df30ef6 fix(migrations): remove unused imports in inject migration (#57179)
The `inject` migration can leave some unused imports behind when it removes decorators like `@Inject`. These changes add some logic to remove them.

PR Close #57179
2024-07-29 13:47:14 -07:00
Kristiyan Kostadinov
7a40234fb7 refactor(migrations): optimize some of the import utilities (#57179)
Makes a few optimizations in the utilities we use for dealing with imports in migrations. I didn't end up using these in the inject migration, but they should still come in handy. Includes:
1. Exiting `isReferenceToImport` early when the node being checked is an identifier and it doesn't match the identifier of the import. This saves us some type checker calls.
2. Adds the ability to pass a single string to `getImportSpecifiers`. This saves us unnecessary arrays and for loops.

PR Close #57179
2024-07-29 13:47:14 -07:00
Kristiyan Kostadinov
2ffa417665 refactor(migrations): add the ability to remove imports in the change tracker (#57179)
Updates the `ChangeTracker` to integrate the changes from #57110.

PR Close #57179
2024-07-29 13:47:14 -07:00
Kristiyan Kostadinov
67e09404db fix(compiler): reduce chance of conflicts between generated factory and local variables (#57181)
Currently we use some short variable names like `t` and `r` in the generated factory functions. They can conflict with local symbols with the same names, if they're used for DI.

These changes add a `ɵ` to the generated variables to reduce the chance of conflicts.

Fixes #57168.

PR Close #57181
2024-07-29 13:46:48 -07:00
cexbrayat
56816bbdb2 refactor(compiler-cli): typo in compilePoisonedComponents option name (#57126)
The recently introduced option (in a22f1428) has a typo in its name

PR Close #57126
2024-07-26 10:02:34 -07:00
Kristiyan Kostadinov
2158b8dafb refactor(compiler-cli): add the ability to remove imports from the import manager (#57110)
Extends the `ImportManager` to allow for imports to be removed. This will be useful in automated migrations.

PR Close #57110
2024-07-26 10:01:18 -07:00
Kristiyan Kostadinov
aae9646a1b fix(migrations): unwrap injected forwardRef (#57127)
Updates the inject migration to unwrap the `forwardRef` call in cases like `constructor(@Inject(forwardRef(() => Foo)) foo: Foo);`, because the `forwardRef` will type the initializer to `any` and it shouldn't be necessary.

PR Close #57127
2024-07-26 10:00:32 -07:00
Kristiyan Kostadinov
cb442a0ce7 fix(migrations): account for parameters with union types (#57127)
This can up in Material where we had a `constructor(@Optiona() foo: Foo | null)` which ended up producing incorrect code, because the union type was preserved.

These changes resolve the issue by picking out the first non-literal type from the union for the `inject` call.

PR Close #57127
2024-07-26 10:00:32 -07:00
Kristiyan Kostadinov
1cf616f671 fix(migrations): remove generic arguments from the injected type reference (#57127)
Currently if an injected type has type arguments, we copy it over together with the type arguments to inject, because `inject()` isn't able to infer the generic properly otherwise. E.g. if there's `constructor(el: ElementRef<HTMLElement>)` we produce `inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);`.

These changes drop the generics from the `inject()` parameter since we're overwriting the type anyway. The example from above would become `inject<ElementRef<HTMLElement>>(ElementRef);`.

PR Close #57127
2024-07-26 10:00:32 -07:00
Kristiyan Kostadinov
166166d79e fix(migrations): add alias to inject migration (#57127)
Adds a shorter alias to the inject migration.

PR Close #57127
2024-07-26 10:00:32 -07:00
Kristiyan Kostadinov
0f0a1f2836 fix(compiler-cli): emitting references to ngtypecheck files (#57138)
Follow-up to #56961 which doesn't appear to have caught all the cases. This change moves the pre-emit untagging to `NgCompiler.prepareEmit` which seems to cover a bit more comared to `NgtscProgram.emit`.

Fixes #57135.

PR Close #57138
2024-07-26 10:00:05 -07:00
cexbrayat
ca89ef9141 fix(core): handle shorthand assignment in the inject migration (#57134)
Currently the migration updates:

```ts
constructor(@Inject(LOCALE_ID) locale: string) {
  console.log({ locale });
}
```

to:

```ts
constructor() {
  console.log({ locale });
}
```

This fixes the migration, and results in:

```
constructor() {
  const locale = inject(LOCALE_ID);
  console.log({ locale });
}
```

PR Close #57134
2024-07-25 18:43:45 -07:00
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