Commit graph

4821 commits

Author SHA1 Message Date
Kristiyan Kostadinov
fc95a9adff fix(migrations): replace leftover modules with their exports during pruning (#57684)
Currently during the module pruning stage of the standalone migration we assume that any leftover modules which only have `imports` and `exports` can safely be removed. That can be incorrect for the cases where some parts of the app were converted to standalone outside of the migration.

These changes update the logic so that such modules are replaced with the `exports` which are used within the specific component.

Fixes #51420.

PR Close #57684
2024-09-06 14:15:50 +00:00
Matthieu Riegler
1698bd3ed8 refactor(compiler-cli): Do extract symbols from private modules. (#57611)
Modules like `core/primitives` are considered private and their symbols shouldn't be exposed nor linked in the docs.

PR Close #57611
2024-09-06 14:15:18 +00:00
Paul Gschwendtner
227d13b86d refactor(migrations): preserve brace spacing when applying imports (#57672)
Currently the import manager always add a space after the import clause
brace. We should only do this if the existing import did the same.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
00852118cc refactor(migrations): preserve multi-line imports if possible when editing imports (#57672)
Currently whenever we apply the import manager changes in migations, we
leave the decision of multi-line or single-line to the TS printer.

This works, but in practice can cause signficiant file jumps/changes if
there are large imports that aren't wrapped for example, or the other
way around. We should try to be minimal here and preserve the existing
formatting, assuming that a multi-line import remains multi-line, while
a single-line import remains single-line if it already had many items in
a single line, intentionally.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
8f40b25635 docs(migrations): clarify usage of shouldMigrateInput config option (#57672)
Clarifies some details of the `shouldMigrateInput` configuration option
of the signal input migration.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
b0f5d5549e refactor(migrations): best effort mode should respect ignored inputs (#57672)
Whenever the signal input migration runs in VSCode, other inputs are
marked as incompatible via the config. Best effort mode currently skips
those incompatibilities and still migrates them. This is incorrect as
the config intends to skip those inputs, regardless of best effort mode.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
7e54a944cc refactor(migrations): avoid comments leaking from TCB into input migration (#57672)
The migration took a type from the directive handler metadata, and
inserted it into a synthetic node for the new input() call. This works
perfectly fine, but in some cases, I saw some `T:VAE` comments attached
🤯  These are from the type checker which attached
synthetic comments to the exact same node.

PR Close #57672
2024-09-05 19:33:03 +00:00
Pawel Kozlowski
68e5370a66 feat(migrations): remove complete calls for migrated outputs (#57671)
This change removes superflous .complete calls for the migrated outputs.

PR Close #57671
2024-09-05 14:13:42 +00:00
Pawel Kozlowski
f1bbbeab0c test(migrations): add more tests to output migration (#57671)
This change contains an additonal test that captures scenario
of the problematic .pipe usage outside of the directive class.

PR Close #57671
2024-09-05 14:13:42 +00:00
Paul Gschwendtner
f6c40f1ba1 refactor(migrations): expose all input migration helpers (#57659)
Instead of encouraging deep imports, we should expose commonly accessed
exports in a `index.ts` barrel file.

PR Close #57659
2024-09-04 20:07:18 +00:00
Paul Gschwendtner
c3f2420877 refactor(migrations): use proper suffix for object expansion input variables (#57659)
Whenever we migrate object expansion patterns, we may need a temporary
variable to generate a construct like:

```ts
const {bla: blaValue} = this;
const bla = blaValue();
```

We should instead use `blaInput` as the name for the temporary
variable. For narrowing constants, `blaValue` is correct, but here
it's an actual reference to the input / signal.

PR Close #57659
2024-09-04 20:07:18 +00:00
Paul Gschwendtner
aa439662af refactor(migrations): speed up migration for subset of signal inputs (#57659)
With the preparation work from previous commits, we are able to reduce
analysis time of the migration from e.g. whole Material repo 7seconds to
0.1seconds when the migration is invoked via the VSCode extension.

This is possible because we can avoid many expensive type checking
lookups if we know what inputs are actually migrated. We do this by
adding some naive pre-check to see if identifiers are possibly pointing
to a migrated input.

This is possible now because we no longer migrate aliased identifiers
for object expansion, but instead migrate directly at object
expansion declaration. This allows us to assume that all possible
references to inputs must go through identifiers that are named like
the original input class field name.

PR Close #57659
2024-09-04 20:07:18 +00:00
Paul Gschwendtner
f694acb587 refactor(language-service): improve error messaging for signal input refactoring (#57659)
Instead of printing the enum name as the reason why migration did not
complete, we should print some human-readable descriptions.

This commit implements this. This logic may also be useful for the
devkit comment generation, or CLI usage.

In addition, we expose another VSCode refactoring to try via best effort
mode. There is no way for prompting, or adding multiple actions for the
same refactoring, so we expose a new refactoring.

PR Close #57659
2024-09-04 20:07:18 +00:00
Paul Gschwendtner
d8338b5f87 refactor(migrations): generate blocks to support narrowing inside arrow function (#57659)
Whenever the signal migration discovers multiple references in the same
control flow container, it assumes narrowing and wants to preserve this
functionality. It does this by introducing temporary variables.

This works fine, but currently there is an edge case with arrow
functions, as those can also turn into blocks, but aren't considered as
such in the current code. This commit fixes this, so that arrow
functions will be converted to be block-based if necessary.

PR Close #57659
2024-09-04 20:07:17 +00:00
Pawel Kozlowski
9da21f798d feat(migrations): replace .next usage on outputs (#57654)
This commits extends the decorator-based output migration
to replace .next usage (not supported with the output function)
with .emit (supported in both decorator-based and function based
outputs).

PR Close #57654
2024-09-04 17:05:56 +00:00
Pawel Kozlowski
71f5ef2aa5 fix(migrations): change imports to be G3 compatible (#57654)
A set of fixes to the import paths - the goal is to make the
output migration compatible with the G3 infrastructure.

PR Close #57654
2024-09-04 17:05:56 +00:00
Paul Gschwendtner
a777bee3de refactor(migrations): improve element binding migration for input migration (#57645)
Currently we detect element bindings as normal references and inside
usages we simply unwrap its usages. This works, but breaks in situations
like the following:

- When the expressions are narrowed. Narrowing analysis does not support
  aliased inputs. E.g. `const {myInput: alias} = this`. We could add
  this, but it would complexify the logic.

- When binding patterns deeply access value properties directly. E.g.
  `const {myInput: {value}} = this;`

In addition, the current approach requires us to understand that aliases
may point to inputs. This means we need to check all identifiers if they
point to Angular inputs. We could optimize this, but it's much easier if
we can simply assume that we only need to "verify" identifiers that have
names of "known inputs". This would significantly speed up turnaround in
the language service integration.

In addition, it would be more _correct_, semantically to directly access
the value of the input at object expansion, versus later.

PR Close #57645
2024-09-03 14:29:55 -07:00
Paul Gschwendtner
0764981f3a refactor(migrations): add performance logging for input reference lookups (#57645)
Adds logic to capture performance timings when resolving input
references. This is useful for debugging and improving integration in
the VSCode extension.

PR Close #57645
2024-09-03 14:29:55 -07:00
Paul Gschwendtner
61dfb2b03f refactor(migrations): share ts.Printer for signal input migration (#57645)
Instead of re-creating printers everywhere, we should re-use the same
printer throughout the migration.

PR Close #57645
2024-09-03 14:29:54 -07:00
Paul Gschwendtner
ec94e1ecb0 refactor(migrations): move reference signal input migration into dedicated file (#57645)
Moves the rather complicated reference migration logic for the input
migration into a separate method. This cleans up the logic and makes way
for an additional complexity with regards to element bindings.

PR Close #57645
2024-09-03 14:29:54 -07:00
Paul Gschwendtner
1251ee0ac6 refactor(migrations): share logic for looking up property access (#57645)
This commit shares the logic for looking up a property access, using
`ts.Type` information. This is helpful in case where no linked TS
symbols are available; e.g. templates in test files without TCB.

This helper will be useful for handling object expansion in the signal
input migration; resolving references like `const {x} = this`.

PR Close #57645
2024-09-03 14:29:54 -07:00
Alex Rickabaugh
be2e49639b feat(core): introduce afterRenderEffect (#57549)
Implement the `afterRenderEffect` primitive, which creates effect(s) that
run as part of Angular's `afterRender` sequence. `afterRenderEffect` is a
useful primitive for expressing DOM operations in a declarative, reactive
way.

The API itself mirrors `afterRender` and `afterNextRender` with one big
difference: values are propagated from phase to phase as signals instead of
as plain values. As a result, later phases may not need to execute if the
values returned by earlier phases do not change.

PR Close #57549
2024-09-03 10:40:45 -07:00
Alan Agius
3896f86865 refactor(migrations): switch from esbuild to Rollup for schematics bundling (#57602)
Replaces esbuild with Rollup for bundling schematics to support code splitting, as esbuild does not handle code splitting when targeting CommonJS modules.

**Before:**
```
du -sh dist/bin/packages/core/npm_package/schematics
7.7M    dist/bin/packages/core/npm_package/schematics
```

**After:**
```
du -sh dist/bin/packages/core/npm_package/schematics
3.1M    dist/bin/packages/core/npm_package/schematics
```

PR Close #57602
2024-09-03 09:07:03 -07:00
Andrew Scott
36d8d19dc1 refactor(core): removing a pending task delays stability until the next tick (#57570)
This commit updates the public API for pending tasks to schedule an
application tick, effectively making the stability async when the last
task is removed.

PR Close #57570
2024-09-03 08:50:42 -07:00
Kristiyan Kostadinov
aa8eb15ddf build: delete v18 migrations (#57603)
We don't need to ship the migrations for v18 once we're in v19.

PR Close #57603
2024-09-03 07:59:10 -07:00
Pawel Kozlowski
e6e5d29e83 feat(core): initial version of the output migration (#57604)
Initial version of the migration that changes decorator-based
outputs to the equivalent form using new authoring functions.

PR Close #57604
2024-09-03 07:58:20 -07:00
Paul Gschwendtner
2679dcfd44 refactor(migrations): simplify signal input migration language-service integration (#57606)
Instead of some special hook that relies on mutation to filter inputs in
the signal input migration, we are now introducing a new configuration
interface where the language-service can pass a filter method.

This makes the code more readable. We also need the filter method to
support filtering based on directories. E.g. when the migration runs
against sub-folders, all inputs outside of the folder should be
considered incompatible; to not migrate incorrectly.

PR Close #57606
2024-09-03 07:57:04 -07:00
Paul Gschwendtner
a8e3ba9550 refactor(migrations): properly handle cases of --strict=false in signal input migration (#57629)
Sometimes `--strictPropertyInitialization` is not enabled, while strict
null checks is enabled. In those cases, `undefined` cannot be used as
initial value with `input()`, nor can we expand the type of the input.

We can migrate those instances to `undefined!` to preserve the original
semantics and behavior. In addition, in the future we may leave a TODO
or we may consider skipping migration of such inputs.

PR Close #57629
2024-09-03 07:55:09 -07:00
Paul Gschwendtner
a65e87457e refactor(migrations): add explicit test for non-null assertions (#57629)
Adds an explicit test to state the situation about non-null assertions
and that we don't remove the exclamation marks here for now.

PR Close #57629
2024-09-03 07:55:09 -07:00
Paul Gschwendtner
2ad9609a8d refactor(migrations): pass project-relative paths for tsurge replacements (#57584)
This allows for the replacements to be conveniently passed between
migration stages. This is especially relevant in 1P where stages may
have different root directories.

Tsunami attempts to relativize paths in general, similar to how we do
here, but this doesn't work with e.g. Funnel-based migrations where
replacements are serialized in between stages; and where the migration
stage at the end doesn't know about the previous root directory anymore.

PR Close #57584
2024-08-29 14:28:02 -07:00
Matthieu Riegler
6c2beba63d docs(docs-infra): Add dev-mode only mention for core/global (#57365)
PR Close #57365
2024-08-29 10:17:35 -07:00
Paul Gschwendtner
6e28f96d5f refactor(migrations): ensure control flow analysis of signal input migration works with all TS versions (#57566)
Ensures that the control flow analysis version of the signal input works
with all TS versions currently supported.

PR Close #57566
2024-08-29 07:51:38 -07:00
Paul Gschwendtner
5319d67d83 refactor(migrations): cleanup TODOs in signal input migration (#57566)
Cleans up remaining TODOs in the signal input migration, and other
small clean ups.

PR Close #57566
2024-08-29 07:51:38 -07:00
Paul Gschwendtner
82f4590216 refactor(migrations): avoid relative imports in schematic code (#57214)
This allows us to bundle e.g. the signal input migration into
language-service without duplicating code. Rollup with Bazel may end up
duplicating because it isn't able to associate the local sources with
the linked modules from `node_modules/@angular/compiler-cli`.

PR Close #57214
2024-08-29 07:50:41 -07:00
Paul Gschwendtner
1f067f4507 feat(language-service): add code reactoring action to migrate @Input to signal-input (#57214)
(experimental at this point)

Language service refactoring action that can convert `@Input()`
declarations to signal inputs.

The user can click on an `@Input` property declaration in e.g. the VSCode
extension and ask for the input to be migrated. All references, imports and
the declaration are updated automatically.

PR Close #57214
2024-08-29 07:50:41 -07:00
Matthieu Riegler
641f8f1e40 docs: Add mention to ENVIRONMENT_INITIALIZER (#57464)
Explicitly mention that `ENVIRONMENT_INITIALIZER` should not be async.

PR Close #57464
2024-08-29 07:43:48 -07:00
Vlad Boisa
cacf2b6fc6 docs(docs-infra): remove hash before link (#57351)
Remove hash in link for correct view

Fixes #57349

docs(docs-infra): change the link

Change the link with name of class and method

docs: fix the link name

PR Close #57351
2024-08-29 07:42:13 -07:00
Paul Gschwendtner
b7f3baf8b1 refactor(migrations): forward-fix conflicts with generic of ProgramInfo. (#57565)
One PR removed the generic of `ProgramInfo`, while another PR,
separately merged, introduced new instanes of `ProgramInfo`.

PR Close #57565
2024-08-28 09:17:33 -07:00
Paul Gschwendtner
29e526c147 refactor(migrations): allow tsurge migrations to run with just NgCompiler (#57562)
This is important so that migrations can easily be wired up in the
language service where only `NgCompiler` is available.

PR Close #57562
2024-08-28 08:47:45 -07:00
Paul Gschwendtner
c4681989ac refactor(migrations): properly handle multi query migration (#57556)
Properly handles queries with multiple results, by extracting the
type from the `QueryList`.

Also adds more tests and handles imports.

PR Close #57556
2024-08-28 08:43:38 -07:00
Paul Gschwendtner
86e6f7b5d6 refactor(migrations): initial migration logic for converting to signal queries (#57556)
Adds initial migration logic to convert decorator query declarations to
signal queries.

We will re-use more part of the signal input migration in follow-ups, to
properly migrate, and e.g. even handle control flow

PR Close #57556
2024-08-28 08:43:38 -07:00
Andrew Scott
226a67dabb fix(core): Schedulers run in zone above Angular rather than root (#57553)
This change updates the timers used in the coalescing and hybrid mode
schedulers to run in the zone above Angular rather than the root zone.
Running the timers in the root zone makes them impossible to flush when
using `fakeAsync` and also may make them invisible to other zones in the
hierarchy that might have desirable behaviors such as task/perf tracking.

fixes #56767

BREAKING CHANGE: The timers that are used for zone coalescing and hybrid
mode scheduling (which schedules an application state synchronization
when changes happen outside the Angular zone) will now run in the zone
above Angular rather than the root zone. This will mostly affect tests
which use `fakeAsync`: these timers will now be visible to `fakeAsync`
and can be affected by `tick` or `flush`.

PR Close #57553
2024-08-27 15:07:30 -07:00
Alex Rickabaugh
76b9e2b836 Revert "refactor(migrations): initial migration logic for converting to signal queries (#57525)" (#57555)
This reverts commit 6f5b435a69.

Reason: breaks g3

PR Close #57555
2024-08-27 14:03:06 -07:00
Alex Rickabaugh
0ba2a95bf6 Revert "refactor(migrations): properly handle multi query migration (#57525)" (#57555)
This reverts commit f454ad3bcf.

Reason: breaks g3

PR Close #57555
2024-08-27 14:03:06 -07:00
Kristiyan Kostadinov
96b698ce02 test: avoid leaking some LViews in tests (#57546)
We had some tests that were leaking LViews, because we were testing things like `createComponent`, but not destroying them afterwards. These changes clean up most of them, although there are a handful still left that I didn't have time to fully track down.

PR Close #57546
2024-08-27 13:29:08 -07:00
Kristiyan Kostadinov
a3cdbfe87f fix(core): avoid leaking memory if component throws during creation (#57546)
When we create the LView for a component, we track it in the `TRACKED_LVIEWS` map. It gets untracked when it is destroy, but if it throws during creation, the user won't have access to a `ComponentRef` in order to clean it up.

These changes automatically untrack the related LViews if the component couldn't be created.

PR Close #57546
2024-08-27 13:29:08 -07:00
Alan Agius
099955bdf3 build: remove Sourcemaps from Schematics bundles (#57545)
This commit reduces the bundle size of `@angular/core` by 19.5 MB by excluding sourcemaps from the schematics.

Since the `esbuild` rule doesn't allow disabling sourcemaps directly, we work around this by setting the sourcemaps to `external`. Afterward, we filter the output to include only the `.js` files.

PR Close #57545
2024-08-27 13:27:33 -07:00
Paul Gschwendtner
f454ad3bcf refactor(migrations): properly handle multi query migration (#57525)
Properly handles queries with multiple results, by extracting the
type from the `QueryList`.

Also adds more tests and handles imports.

PR Close #57525
2024-08-27 13:20:19 -07:00
Paul Gschwendtner
6f5b435a69 refactor(migrations): initial migration logic for converting to signal queries (#57525)
Adds initial migration logic to convert decorator query declarations to
signal queries.

We will re-use more part of the signal input migration in follow-ups, to
properly migrate, and e.g. even handle control flow

PR Close #57525
2024-08-27 13:20:19 -07:00
Chintan Kavathia
7b1e5be20b fix(core): fallback to default ng-content with empty projectable nodes. (#57480)
BREAKING CHANGE: Render default fallback with empty `projectableNodes`.

When passing an empty array to `projectableNodes` in the `createComponent` API, the default fallback content of the `ng-content` will be rendered if present. To prevent rendering the default content, pass `document.createTextNode('')` as a `projectableNode`.

For example:

```ts
// The first ng-content will render the default fallback content if present
createComponent(MyComponent. { projectableNodes: [[], [secondNode]] });

// To prevent projecting the default fallback content:
createComponent(MyComponent. { projectableNodes: [[document.createTextNode('')], [secondNode]] });

```

Fixes #57471

PR Close #57480
2024-08-27 13:15:17 -07:00