Commit graph

632 commits

Author SHA1 Message Date
Kristiyan Kostadinov
35165d152d fix(migrations): inject migration dropping code if everything except super is removed (#58959)
Fixes that in some cases the internal version of the migration was dropping code when all the statements after the `super` call are deleted.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
7191aa6e09 fix(migrations): don't migrate classes with parameters that can't be injected (#58959)
Updates the inject migrations to skip over classes that have uninjectable class parameters.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
68e5ba7a3a fix(migrations): preserve type literals and tuples in inject migrations (#58959)
Updates the inject migration to preserve type literals and tuple types, based on some internal feedback.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
a4924af6d5 fix(migrations): inject migration aggressively removing imports (#58959)
Fixes that the inject migration would remove imports even if they're still used by classes that aren't being migrated.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
508d3a1b3b fix(migrations): correctly strip away parameters surrounded by comments in inject migration (#58959)
Fixes that the inject migration was sometimes producing invalid code if there are comments around the parameters.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
e31e52e177 fix(migrations): class content being deleted in some edge cases (#58959)
Fixes that the inject migration was deleting the class' content if a property exists after the constructor that is being rewritten.

PR Close #58959
2024-12-02 08:56:20 +01:00
Kristiyan Kostadinov
bd1f1294ae feat(core): support TypeScript 5.7 (#58609)
Updates the repo to allow for TypeScript 5.7 to be used.

PR Close #58609
2024-11-25 17:12:10 +00:00
Kristiyan Kostadinov
4f1f4a1728 refactor(migrations): skip TS version check in tsurge (#58866)
Skips the TS version check in tsurge since it's blocking some internal changes and generally isn't necessary since the app will be checked when it's built anyways.

PR Close #58866
2024-11-25 15:26:18 +00:00
Younes Jaaidi
1fe001e18b fix(migrations): fix provide-initializer migration when using useFactory (#58518)
Priori to this commit, initializer functions with dependencies were not migrated correctly.
With this commit, the function is executed in a injection context to allow the usage of `inject`.

PR Close #58518
2024-11-21 20:59:35 +00:00
Ryan Russell
3fc14ecc81 fix(migrations): Mark hoisted properties as removed in inject migration (#58804)
Before, in a situation like shown in the test, all of the initializers
would be dropped, as the code would try to insert it at the hoisted
property which is going to be deleted.

PR Close #58804
2024-11-21 20:58:26 +00:00
JoostK
21f757c1c4 fix(core): correctly perform lazy routes migration for components with additional decorators (#58796)
This fixes an issue where the lazy-routes migration would crash for component classes a
decorator without arguments in front of the `@Component` decorator (in particular, it needed
to be the first decorator).

Fixes #58793

PR Close #58796
2024-11-21 16:43:30 +00:00
Kristiyan Kostadinov
18991d3210 fix(migrations): handle parameters with initializers in inject migration (#58769)
Adds some logic to the `inject()` migration that allows is to handle parameter declarations with initializers. This was omitted initially, because we don't officially support such cases, but it came up internally.

PR Close #58769
2024-11-20 08:07:39 -08:00
cexbrayat
2eb4afe2b3 fix(migrations): do not migrate next calls in template if not an EventEmitter (#58631)
Fixes #58630

```html
<button (click)="someSubject.next()">Click</button>
```

was migrated to an `.emit` call, even if `someSubject` was not an `EventEmitter`.

The issue was the same in host listeners.

PR Close #58631
2024-11-15 14:13:52 +01:00
cexbrayat
ecd107b2e3 refactor(migrations): typos in signal migration incompatibility reasons (#58636)
A dot was appearing in the middle of the comment for `DerivedIsIncompatible`.
While at it, a dot was missing in `ClassManuallyInstantiated`.

PR Close #58636
2024-11-14 14:55:04 +00:00
Kristiyan Kostadinov
89256e6868 fix(migrations): replace removed NgModules in tests with their exports (#58627)
In #57684 the standalone migration was changed so that it replaces any leftover modules with their `exports`, in an attempt to preserve more working code. These changes expand that logic to also cover tests since it's somewhat common internally to only import a component's module without having any references to the component.

Note that tests are a bit of a special case, because we don't have access to the template type checker, so instead we copy over all of the `exports` of that module.

PR Close #58627
2024-11-13 18:04:31 +00:00
cexbrayat
579f613a58 fix(migrations): include the output migration in the defaults of the signal migration (#58635)
Running `ng g @angular/core:signals` prompts for the question on which migration to run and offers 3 options (inputs, outputs, queries).
Running with `--defaults` skips the prompts, but only runs 2 of them.
This fixes it by including the `outputs` migration in the default ones.

PR Close #58635
2024-11-13 18:03:58 +00:00
Kristiyan Kostadinov
7e5f705213 refactor(migrations): handle fake async catalyst (#58608)
Fixes that the standalone migration wasn't handling the `fake_async` path for Catalyst.

PR Close #58608
2024-11-12 14:45:40 +00:00
Paul Gschwendtner
5ac0538870 refactor(migrations): improve temporary variable generation in signal migrations (#58581)
This commit improves the temporary variable generation in signal
migrations, whenever references are "shared" inside property
declarations.

PR Close #58581
2024-11-11 15:29:20 +00:00
Paul Gschwendtner
4fe080f04d refactor(migrations): improve control flow analysis for loops in signal migration (#58581)
Currently whenever we would come across a code snippet like this, where
`maxCellsPerRow` is an input, the control flow analysis would fall apart
because the first occurence of the node points to a control flow node
that is offset-wise "after" the first occurence. This commit makes the
logic more robust.

PR Close #58581
2024-11-11 15:29:20 +00:00
Paul Gschwendtner
55fde8dbac refactor(migrations): support running existing migrations with plain TS programs (#58541)
Previously we always ran Tsurge migrations with an Angular program, even
if it's a plain `ts_library` target. This has changed now, so we also
need to properly handle the case where a `ts_library` is analyzed, but
no Angular program is available.

PR Close #58541
2024-11-08 17:22:06 +00:00
Paul Gschwendtner
1a0cee543e refactor(migrations): conditionally create plain TS programs for Tsurge analyzers (#58541)
Tsurge can run against the full Google3 depot, and will often also deal
with plain `ts_library` targets. Those shouldn't be constructed with the
Angular compiler as this could cause out of memory breakages etc. The
targets are simply not "proven" to be compatible with the Angular
compiler; so we shouldn't use them when not necessary.

PR Close #58541
2024-11-08 17:22:06 +00:00
Paul Gschwendtner
8919c80dae refactor(migrations): speed up code refactoring action for queries (#58525)
We were not properly passing around the TCB full program optimization,
so TCB generation was done per individual file. This significantly
slowed down reference resolution.

PR Close #58525
2024-11-06 16:30:18 +01:00
Paul Gschwendtner
121b340916 refactor(migrations): enable debug printing of compiler diagnostics (#58515)
This is useful for some migrations and eases debugging, so we are
building an environment-guarded debug print.

PR Close #58515
2024-11-06 13:04:22 +01:00
Paul Gschwendtner
8d5d5f80b3 fix(migrations): properly bundle shared compiler code into migrations (#58515)
The use of relative imports vs. module imports and the existing mismatch
can cause symbols to be duplicated in migrations. This is problematic as
it breaks migration logic or compiler logic in the worst case.

Long-term we will solve this by having a better Bazel toolchain where
both relative and module imports can point to the same files; but in
practice this is not the case right now.

This commit fixes the fallback template logic in the signal
input/queries migration; in case no type check block information is
available.

PR Close #58515
2024-11-06 13:04:22 +01:00
cexbrayat
01f86287db refactor(migrations): use import manager in provide-initializer (#58456)
The manual replacement logic had a flaw and was inserting the imports several times.

For example:

```ts
import { APP_INITIALIZER, ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { InitService } from './init.service';

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }),
    {
      provide: APP_INITIALIZER,
      useFactory: (initService: InitService) => initService.init(),
      deps: [InitService],
      multi: true
    },
    {
      provide: APP_INITIALIZER,
      useFactory: (initService: InitService) => initService.init(),
      deps: [InitService],
      multi: true
    }
  ]
};
```

produced:

```ts
import { ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer }{ ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer } from '@angular/core';
import { InitService } from './init.service';

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }),
    provideAppInitializer(() => { return ((initService: InitService) => initService.init())(inject(InitService)); }),
    provideAppInitializer(() => { return ((initService: InitService) => initService.init())(inject(InitService)); })
  ]
};
```

It now produces proper imports:

```ts
import { ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer } from '@angular/core';
```

PR Close #58456
2024-11-04 18:15:00 +01:00
cexbrayat
a116a64d35 refactor(migrations): useFactory in provide-initializer migration (#58493)
The following provider:

```ts
{
  provide: APP_INITIALIZER,
  useFactory: (initService: InitService) => {
    return () => initService.init()
  },
  deps: [InitService],
  multi: true
}
```

was migrated into:

```ts
provideAppInitializer(() => { return ((initService: InitService) => {
  return () => initService.init()
})(inject(InitService)); })
```

This doesn't compile because there is an extra function:

```
✘ [ERROR] TS2345: Argument of type '() => () => void' is not assignable to parameter of type '() => void | Observable<unknown> | Promise<unknown>'.
  Type '() => void' is not assignable to type 'void | Observable<unknown> | Promise<unknown>'. [plugin angular-compiler]

    src/app/app.config.ts:7:26:
      7 │ ...ovideAppInitializer(() => { return ((initService: InitService) => {
```

It now migrates the provider into:

```ts
provideAppInitializer(((initService: InitService) => {
  return () => initService.init()
})(inject(InitService)))
```

PR Close #58493
2024-11-04 15:45:50 +01:00
Enea Jahollari
6819d6abf3 fix(migrations): flip the default standalone flag in route-lazy-loading migration (#58474)
Before v19, the default value of the standalone flag was false, this code change flips the logic in the migration to make it true by default.

PR Close #58474
2024-11-03 19:07:09 +01:00
Kristiyan Kostadinov
94eae783c1 refactor(migrations): attempt to correct initialization order in internal inject migration (#58427)
Updates the internal part of the `inject` migration to attempt to correct some cases where the declaration order of properties doesn't match the initialization order.

PR Close #58427
2024-10-31 09:17:51 +01:00
Kristiyan Kostadinov
70f8c99885 refactor(migrations): make it easier to delete nodes including comments (#58427)
We were repeating the logic that deletes a node together with all its comments in a few different places. These changes consolidate the logic under `ChangeTracker.removeNode`.

PR Close #58427
2024-10-31 09:17:51 +01:00
Kristiyan Kostadinov
d7afb0a086 refactor(migrations): internal inject migration applying some changes to abstract classes (#58427)
We were filtering out abstract classes pretty late in the migration which led to the internal part of it to make some changes that aren't finalized later. These changes fix the issue by filtering out abstract classes during analysis.

PR Close #58427
2024-10-31 09:17:51 +01:00
Matthieu Riegler
183af09059 refactor(migrations): Make the explicit standalone migration idempotent (#58418)
With this commit the  explicit standalone migration uses the presents of imports to make sure that we can safely remove the standalone prop
and not adding it again when re-run.

PR Close #58418
2024-10-30 11:55:11 -07:00
Pawel Kozlowski
3161360852 fix(migrations): properly migrate output aliases (#58411)
Before this fix the output migration was incorrectly assuming
that the @Output decorator takes its params as an object.
What happens in reality is that the @Output decorator is taking
alias as the only argument, without any object literal wrapper.

PR Close #58411
2024-10-30 10:01:28 -07:00
Pawel Kozlowski
db7ed20d7b fix(migrations): properly replace imports across files (#58414)
This change fixes a bug where the output migration was interacting
with the InputManager utility in the way that was resulting in
incorrect import replacements.

The fix consists of making sure that a new ImportManager instance
is created for each and every file containing @Output declarations.

PR Close #58414
2024-10-30 09:24:05 -07:00
Paul Gschwendtner
0d955f67ed refactor(migrations): gracefully handle metadata parsing errors in signal migration (#58413)
In 1P, we saw that a type of a target wasn't resolvable, referenced in a
`hostBindings#directive` field. This breaks the entire pipeline; so we
should handle gracefully but report an error.

Worst case scenario here is that we would miss some references to the
given directive/component. This is acceptable and we can continue
investigation why that given target was broken; especially since the
file was part of the target inputs- but seemingly not in the `tsconfig`.

PR Close #58413
2024-10-30 09:23:39 -07:00
Paul Gschwendtner
7f10343659 refactor(migrations): improve temporary variable insertion in signal migrations (#58413)
Fixes that the migrations weren't properly determing the highest block
of multiple shared references. The logic was flawed by checking the
`start` indices; because we also need to respect that the blocks
should enclose all references; and the block practically is a common
ancestor. This is not guaranteed without this commit.

Note: The logic assumes that all references are part of the same control
flow container; this is verified.

PR Close #58413
2024-10-30 09:23:39 -07:00
Kristiyan Kostadinov
4434f3c7a1 fix(migrations): inject migration always inserting generated variables before super call (#58393)
Fixes that if a class has a `super` call, the `inject` migration would always insert the generated variable before it, even if there's other code before the `super` call.

PR Close #58393
2024-10-28 12:39:03 -07:00
Kristiyan Kostadinov
26be4d64ae refactor(migrations): inject migration internal mode incorrectly migration properties initialized to identifiers (#58393)
Fixes that when the `inject` migration in internal mode was starting to visit the nodes one level down from the root when considering whether an expression contains local references. This lead it to skip over top-level identifiers and migrate some code incorrectly.

PR Close #58393
2024-10-28 12:39:03 -07:00
Kristiyan Kostadinov
b98400f582 fix(migrations): inject migration not inserting generated code after super call in some cases (#58393)
Fixes an issue where the `inject` migration was generating and attempting to insert code after a `super` call, but the string buffering implementation was dropping it if the statement right after the `super` call was deleted as a result of the migration.

PR Close #58393
2024-10-28 12:39:03 -07:00
Kristiyan Kostadinov
a2a9ac76f5 refactor(migrations): hoist uninitialized members to top of class if they are not combined in the internal migration (#58393)
When the internal mode for the `inject` migration is enabled, we find properties without initializers, we add their initializers and we prepend the `inject` calls before them. The remaining properties that couldn't be combined are left in place. This appears to break some internal cases.

These changes work around the issue by hoisting all the non-combined members above the `inject()` calls. This should be safe, because they don't have initializers and as such can't have dependencies.

PR Close #58393
2024-10-28 12:39:03 -07:00
Paul Gschwendtner
35d7ca55b2 test: support parallel tsurge unit combining in batch test infra (#58280)
This allows the batch test for the signal input migration to pass.

PR Close #58280
2024-10-25 18:47:41 +00:00
Paul Gschwendtner
dd686edfe9 refactor(migrations): update migrations to combine analysis data in parallel (#58280)
This is necessary given the previous Tsurge refactorings. It should
speed up migrations in the merge phase signficiantly and reduce memory
pressure. In 1P, we already have workers from analyze phase anyway— so
those can be re-used for parallel metadata merging.

PR Close #58280
2024-10-25 18:47:41 +00:00
Paul Gschwendtner
8143016b91 refactor(migrations): support parallel tsurge metadata merging (#58280)
This is helpful and important for large scale migrations where a single
call for merging _all_ unit data's can be subject to memory / disk
resource constraints. Consider a compilation unit data for every target
in Google3, and those being merged in a single program.

PR Close #58280
2024-10-25 18:47:41 +00:00
Pawel Kozlowski
cf70d626cd feat(migrations): print output migration stats in ng generate (#58321)
Propagates output migration stats to the ng generate schematic.

PR Close #58321
2024-10-23 08:03:31 -07:00
Pawel Kozlowski
bb286f65e7 feat(migrations): capture output migration stats (#58321)
This change captures different statistics from the run of the
output migration:
- total number of outputs detected
- number of problematic outputs that can't be migrated
- overall success rate

PR Close #58321
2024-10-23 08:03:30 -07:00
Kristiyan Kostadinov
42607bf0f2 fix(migrations): add outputs migration to combined shorthand (#58318)
Adds the `@Output` migration to the combined `@angular/core:signals` migration.

PR Close #58318
2024-10-23 08:02:50 -07:00
Andrew Kushnir
888657a12e Revert "refactor(migrations): support parallel tsurge metadata merging (#58280)" (#58313)
This reverts commit 21b6613b90.

PR Close #58313
2024-10-22 12:27:53 -07:00
Andrew Kushnir
1215927e5b Revert "refactor(migrations): update migrations to combine analysis data in parallel (#58280)" (#58313)
This reverts commit 8735543d06.

PR Close #58313
2024-10-22 12:27:53 -07:00
Andrew Kushnir
9aa686896d Revert "test: support parallel tsurge unit combining in batch test infra (#58280)" (#58313)
This reverts commit cb34e406ba.

PR Close #58313
2024-10-22 12:27:53 -07:00
Paul Gschwendtner
cb34e406ba test: support parallel tsurge unit combining in batch test infra (#58280)
This allows the batch test for the signal input migration to pass.

PR Close #58280
2024-10-22 11:29:16 -07:00
Paul Gschwendtner
8735543d06 refactor(migrations): update migrations to combine analysis data in parallel (#58280)
This is necessary given the previous Tsurge refactorings. It should
speed up migrations in the merge phase signficiantly and reduce memory
pressure. In 1P, we already have workers from analyze phase anyway— so
those can be re-used for parallel metadata merging.

PR Close #58280
2024-10-22 11:29:16 -07:00