Commit Graph

12244 Commits

Author SHA1 Message Date
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
Paul Gschwendtner ebe0c168e2 refactor(migrations): share reference migration code of signal input migration (#57766)
The reference migration code of the signal input migration should be
re-usable as the queries migration needs the exact same.

This builds on top of the shared reference resolution logic from
previous commits. Similarly this commit introduces a small "host" for
providing necessary configurable information about what references
should be migrated; supporting e.g. "input incompatibilities".

This is important as e.g. queries may also be incompatible for migration
and references to such, should not be migrated.

PR Close #57766
2024-09-11 14:26:58 +00:00
Paul Gschwendtner acafa3b91d refactor(migrations): add own build file for tsurge AST helpers (#57766)
This separates tsurge from its optional AST helpers more cleanly.

PR Close #57766
2024-09-11 14:26:58 +00:00
Paul Gschwendtner 85018fbd88 refactor(migrations): rename reference migration folder of signal input migration (#57766)
This makes it more aligned with the reference resolution folder that
we've added in the previous commit.

PR Close #57766
2024-09-11 14:26:58 +00:00
Paul Gschwendtner 12f9d2ab5a refactor(migrations): make input migration reference resolution re-usable (#57766)
Allows us to re-use the reference resolution that works within TS code,
Angular templates, or host bindings. This is helpful for queries
migration which also needs to migrate many references, or allows use in
the output migration.

This is achieved by introducing an abstraction of the "known inputs"
registry we have already, but making it more generic to work with _any_
class fields. Known inputs can then implement/extend this. Queries
similarly.

The "known fields" construct gives insight on field unique IDs etc. This
is then used by the reference resolution to determine if it's a
reference that needs to be captured.

We may move all of this code to Tsurge eventually; depending on how
useful it is. We'll discuss.

PR Close #57766
2024-09-11 14:26:58 +00:00
Paul Gschwendtner 685866dfb4 refactor(migrations): correct catalyst import in signal input migration (#57750)
The paths changed as part of an LSC a while ago. This commit updates
the migration to reflect this.

PR Close #57750
2024-09-10 16:37:15 +00:00
Paul Gschwendtner 6fa1b3859c refactor(migrations): do not fail on templates that are string concatenated (#57735)
This is a pattern sometimes seen in test components. We shouldn't fail
the migration unexpectedly here.

PR Close #57735
2024-09-09 17:16:14 +00:00
Paul Gschwendtner b039aed18f refactor(migrations): gracefully handle resource loading issues (#57735)
This can happen when we manually parse templates and end up with an
invalid URL. We should not fail the migration in those cases.

PR Close #57735
2024-09-09 17:16:14 +00:00
Pawel Kozlowski cbec46a51d feat(migrations): migrate .pipe calls in outputs used in tests (#57691)
This change uses the outputToObservable utility function to
convert migrated outputs to Observables. This happens only
in test files as it is a common practice to use RxJS to listen
to events raised by the component under test.

PR Close #57691
2024-09-09 14:10:37 +00:00
Pawel Kozlowski 3a264db866 fix(migrations): properly handle comments in output migration (#57691)
This change contains a fix that takes into account comments
attached to outputs and preserves / removes those as needed.

PR Close #57691
2024-09-09 14:10:37 +00:00
Kristiyan Kostadinov 40ff18f87a fix(compiler): produce less noisy errors when parsing control flow (#57711)
Currently several parsing errors in the new control flow (e.g. missing `track` expression) produce errors whose span targets the entire block. This can be really noisy in the IDE where the error can span many lines in the template.

These changes switch to highlighting just the start of the block.

PR Close #57711
2024-09-09 14:10:01 +00:00
Paul Gschwendtner 4f52678560 refactor(migrations): avoid flow node traversal limit by optimizing traversal (#57719)
Instead of traversing the same paths multiple times, we should avoid
this extra work and optimize. This solves some issues in super large
files with extremely complex flow graphs. E.g. large `ngOnChanges`
functions in Pantheon.

For an example of a flow graph where it doesn't make sense to re-visit
nodes that have multiple incoming edges, see this internal screenshot:
https://screenshot.googleplex.com/6ub4e5e5gbzJAvH

PR Close #57719
2024-09-08 17:11:51 +00:00
Paul Gschwendtner 2e60eb08f4 refactor(migrations): ensure project paths respect root directories (#57677)
Migrations may resolve files in e.g. `blaze-out` and try to compute a
path for the file that is "recognizable" across workers. E.g. in one
worker, it may be the actual `.ts` file inside the source tree, while in
the other, the file may be inside `blaze-out`.

Tsurge currently expects project relative paths to be passed around.
Those project relative paths are currently only based on the single root
directory. Hence paths inside `blaze-out` would actually not be
recognizable.

The fix idea here is that we introduce a structure for Project files.
This structure will contain two fields:

- an ID of a file. This is similar to a module ID in the project. Those
  are resolved with respect to all root directories. This matches the
  conceptual virtual roots of `tsconfig#rootDirs`. The IDs can be used
  for matching files across workers, assuming those are executing using
  the same root directories, and handle the same overall project (e.g.
  google3).

- a path relative to the primary project root. Multiple roots may be
  configured, but the primary project root, is the directory that
  contains all others. See: `tsconfig.rootDir`. This path is NOT
  necessarily useful for matching files between stages etc, but it's
  useful for writing replacements for a given file to disk.

Note that those two things cannot be combind into one conceptual
"project relative path" because a path relative to the most appropriate
root directory cannot be used for safe replacements. E.g. consider a
replacement matches a file from a root directory like `/sub/`. The path
inside `/sub/` would then omit the `/sub/` and later on when writing
replacements, we wouldn't know which root directory it actually was part
of. Hence the concept of a "project root relative path" and the "ID".

ds

PR Close #57677
2024-09-06 19:44:07 +00:00
Matthieu Riegler 6ea8e1e9aa feat(core): Add a schematics to migrate to standalone: false. (#57643)
With the framework enabling `standalone` by default (making module based an opt-in), the migration will migrate none-standalone existing components and add `standalone: false` to the decorator.

PR Close #57643
2024-09-06 15:08:51 +00:00
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
Dylan Hunn f063a75eae refactor(language-service): Allow language service diagnostics to be ignored (#57675)
Add a check to the language service that ignores specified diagnostic codes. This will be useful in g3.

The codes to ignore are exposed as part of the PluginConfig.

Fixes github.com/angular/vscode-ng-language-service/issues/1243

PR Close #57675
2024-09-06 14:14:47 +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 cf88d8a8c1 refactor(language-service): align signal input refactoring messages (#57672)
This ensures they follow the same pattern.

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