Commit graph

3322 commits

Author SHA1 Message Date
Kristiyan Kostadinov
33fe252c58 fix(compiler-cli): do not report unused declarations coming from an imported array (#57940)
Some apps follow a pattern where they have an array of common declarations which is imported in most standalone components, but only some of the declarations are used. Such cases will currently raise the unused imports diagnostic but can be hard to fix, because it would require either removing declarations from the common array which can break other components, or copying only the necessary declarations from the array. Since neither of these solutions is great, this commit tweaks the logic for the diagnostic so that unused imports coming from _exported_ arrays are not reported (either from the same file or another one).

PR Close #57940
2024-09-30 13:27:29 -07:00
Alex Rickabaugh
d9687f43dd feat(compiler-cli): 'strictStandalone' flag enforces standalone (#57935)
Add the `strictStandalone` flag to `angularCompilerOptions`. When set to
true, the compiler will require that all declarations of components,
directive, and pipes be standalone. When `standalone: false` is provided,
an error is raised.

Note that until the default value of the standalone flag is flipped, this
does not catch the case where a declaration does not specify a value for
`standalone`.

The default value of the `strictStandalone` flag is `false`.

PR Close #57935
2024-09-26 14:22:24 -07:00
Enea Jahollari
39ccaf4cc4 fix(compiler-cli): correctly get the type of nested function call expressions (#57010)
This PR fixes a bug where the type of a nested function call expression was incorrectly being returned as null.

PR Close #57010
2024-09-26 14:13:03 -07:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +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
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
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
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
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
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
Kristiyan Kostadinov
a2e4ee0cb3 feat(compiler): add diagnostic for unused standalone imports (#57605)
Adds a new diagnostic that will report cases where a declaration is in the `imports` array, but isn't being used anywhere. The diagnostic is reported as a warning by default and can be controlled using the following option in the tsconfig:

```
{
  "angularCompilerOptions": {
    "extendedDiagnostics": {
      "checks": {
        "unusedStandaloneImports": "suppress"
      }
    }
  }
}
```

**Note:** I'll look into a codefix for the language service in a follow-up.

Fixes #46766.

PR Close #57605
2024-09-03 14:30:56 -07:00
Matthieu Riegler
39b7be8588 refactor(compiler-cli): Add support for inheritance in API extraction (#57588)
This commit adds the `extends` and `implements` properties to the `ClassEntry` & `InterfaceEntry`

PR Close #57588
2024-09-03 07:47:24 -07:00
Andrew Kushnir
001f319865 Revert "refactor(compiler-cli): extract function overload separatly (#56489)" (#57594)
This reverts commit 37b88a5a98.

PR Close #57594
2024-08-29 16:21:46 -07:00
Matthieu Riegler
01030d58a7 docs(docs-infra): Add support for cross-links on API pages (#57346)
PR Close #57346
2024-08-29 13:39:58 -07:00
Matthieu Riegler
ea3d37687b refactor(compiler-cli): Add a map of every symbols used inside a package (#57346)
This commit changes the structure of the API extraction files to include all symbols used inside a package.

The structure is a `Map`, Symbol => package
eg: 'ApplicationRef' => '@angular/core'

PR Close #57346
2024-08-29 13:39:58 -07:00
Kristiyan Kostadinov
8bcc663a53 feat(core): drop support for TypeScript 5.4 (#57577)
TypeScript 5.4 is no longer supported.

BREAKING CHANGE:
* TypeScript versions less than 5.5 are no longer supported.

PR Close #57577
2024-08-29 10:19:20 -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
Matthieu Riegler
37b88a5a98 refactor(compiler-cli): extract function overload separatly (#56489)
in order for the docs to process function entry, this commit refactor function extraction by keeping the implementation as a the default entry and adds all the overloads into a separate array of entries.

PR Close #56489
2024-08-29 07:49:38 -07:00
Doug Parker
dab722f9c8 refactor(compiler): add i18nPreserveWhitespaceForLegacyExtraction (#56507)
This configures whether or not to preserve whitespace content when extracting messages from Angular templates in the legacy (View Engine) extraction pipeline.

This includes several bug fixes which unfortunately cannot be landed without changing message IDs in a breaking fashion and are necessary to properly trim whitespace. Instead these bug fixes are included only when the new flag is disabled.

PR Close #56507
2024-08-27 13:13:56 -07:00
Charles Lyding
4716c3b966 perf(compiler-cli): reduce duplicate component style resolution (#57502)
Previously, the component handler was processing and resolving stylesheets
referenced via `styleUrl`/`styleUrls` multiple times when generating the
compiler metadata for components. The style resource information collection
for such styles has been further consolidated to avoid repeat resource loader
resolve calls which potentially could be expensive. Further optimization is
possible for the inline style case. However, inline styles here only require
AST traversal and no potentially expensive external resolve calls.

PR Close #57502
2024-08-26 09:13:18 -07:00
Kristiyan Kostadinov
b063468027 feat(core): support TypeScript 5.6 (#57424)
Updates the repo to add support for the upcoming TypeScript 5.6.

PR Close #57424
2024-08-19 22:45:45 -07:00
Charles Lyding
9e87593055 feat(compiler-cli): ensure template style elements are preprocessed as inline styles (#57429)
Previously, style elements within a template were used directly and not provided
to the optional transformation step that may be present on the resource host interface.
This causes such styles to not be processed by the Angular CLI's stylesheet pipeline
and could cause the styles to not work properly on all browsers. The style elements
are now processed in the same manner as inline styles within a component's metadata.
Link elements within a stylesheet were already being processed as `styleUrls`
equivalent and there is no behavior change in that regard.

PR Close #57429
2024-08-19 22:45:20 -07:00
Matthieu Riegler
04911d7599 docs(docs-infra): Add support for function/method overloads (#57255)
PR Close #57255
2024-08-13 12:09:01 -07:00
Angular Robot
7af483ef1e build: update dependency @babel/core to v7.25.2 (#57191)
See associated pull request for more information.

PR Close #57191
2024-08-13 09:29:34 -07:00
Kristiyan Kostadinov
ca55b3d454 fix(compiler-cli): generate valid TS 5.6 type checking code (#57303)
Currently in some scenarios the compiler generates code like `null as any ? foo : bar` which will be invalid with [an upcoming TypeScript change](https://devblogs.microsoft.com/typescript/announcing-typescript-5-6-beta/#disallowed-nullish-and-truthy-checks). These changes switch to generating `0 as any` which is exempt from the change.

**Note:** I'm not starting the work to fully get us on TS 5.6 until the 18.2 release comes out, but this change is necessary to unblock an internal team.

PR Close #57303
2024-08-08 08:30:12 -07:00
Kristiyan Kostadinov
d9d68e73d2 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 rename the parameters to reduce the change for conflicts.

Fixes #57168.

PR Close #57181
2024-08-07 17:25:05 +00:00
JoostK
0b1dd39663 perf(compiler-cli): improve performance of interpolatedSignalNotInvoked extended diagnostic (#57291)
This commit addresses a performance bottleneck in the `interpolatedSignalNotInvoked` extended
diagnostic by querying directive metadata instead of consulting the type-checker to determine if
a property binding corresponds with an input.

Fixes #57287

PR Close #57291
2024-08-07 16:47:24 +00:00
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
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
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
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
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
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
a22f1428b7 refactor(compiler): support use of poisoned data as private compiler option (#57082)
This allows use of poisoned data for migrations. Right now, migrations
often enable this flag by creating some deeper structures of the
Angular compiler, but with this change it's easier to enable as a
private compiler option.

This is helpful for migrations, specifically the signal input migration
as it allows us to generate as much TCB code as possible, for reference
resolution.

PR Close #57082
2024-07-23 10:28:10 -07:00
Paul Gschwendtner
bf853b7c67 refactor(compiler): expose information about inputs from inputs field (#57082)
This commit exposes metadata about inputs that are defined inside
the `inputs` field of `@Directive` or `@Component` class decorators

This is useful and necessary information for migrations, like the
signal inputs migration.

PR Close #57082
2024-07-23 10:28:10 -07:00
Kristiyan Kostadinov
d4ff6bc0b2 fix(compiler-cli): add warning for unused let declarations (#57033)
Adds a new extended diagnostic that will flag `@let` declarations that aren't used within the template. The diagnostic can be turned off through the `extendedDiagnostics` compiler option.

PR Close #57033
2024-07-23 08:27:17 -07:00
Kristiyan Kostadinov
6c2fbda694 fix(compiler-cli): extended diagnostic visitor not visiting template attributes (#57033)
Fixes that the visitor which is used to implement template diagnostics isn't visiting the template attributes of structural directives.

PR Close #57033
2024-07-23 08:27:17 -07:00
Andrew Scott
4ac39aeea9 Revert "fix(compiler-cli): add warning for unused let declarations (#57033)" (#57088)
This reverts commit c76b440ac0.

PR Close #57088
2024-07-22 15:28:03 -07:00
JoostK
08c5977bd5 fix(compiler): limit the number of chained instructions (#57069)
Some Angular template instructions that follow each other may be chained
together in a single expressions statement, containing a deeply nested
AST of call expressions. The number of chained instructions wasn't previously
limited, so this could result in very deep ASTs that cause stack overflow
errors during TypeScript emit.

This commit introduces a limit to the number of chained instructions to
avoid these problems.

Closes #57066

PR Close #57069
2024-07-22 11:50:12 -07:00
Angular Robot
38e4802c7f build: update babel dependencies (#57045)
See associated pull request for more information.

Closes #56996 as a pr takeover

PR Close #57045
2024-07-19 13:46:00 -07:00
Kristiyan Kostadinov
c76b440ac0 fix(compiler-cli): add warning for unused let declarations (#57033)
Adds a new extended diagnostic that will flag `@let` declarations that aren't used within the template. The diagnostic can be turned off through the `extendedDiagnostics` compiler option.

PR Close #57033
2024-07-19 11:50:32 -07:00
Matthieu Riegler
e958fa8a3c refactor(compiler): include public constructor paramters to class properties. (#56315)
Public properties declared in the constructor are part of the public API and we should extract them.

Fixes #56310

PR Close #56315
2024-07-15 11:39:21 -07:00
Paul Gschwendtner
4bb558ab0c feat(language-service): support writing code refactorings (#56895)
In addition to quick fixes, this commit adds the ability to write
code refactoring actions that can be applied by users.

For example, we may implement a migration as a code refactoring action.
Notably the quick fix support, existing already, is insufficient as it
only allows for edits to be applied based on diagnostics shwon in e.g.
VSCode.

PR Close #56895
2024-07-15 11:35:40 -07:00
Kristiyan Kostadinov
f0d6d0688d fix(compiler-cli): avoid emitting references to typecheck files in TS 5.4 (#56961)
In #56358 we removed most of the places that untag the references to typecheck files, because it was causing the compiler to throw error when it produces diagnostics. This appears to have caused a regression in TS 5.4 which now emits the synthetic references.

These changes add tagging right before the program emits.

Fixes #56945.

PR Close #56961
2024-07-15 11:22:00 -07:00
Matthieu Riegler
38b93201c5 refactor(compiler-cli): Extract call signatures from interfaces. (#56973)
This commit adds support for extracting call signals from interfaces.

fixes #56969

PR Close #56973
2024-07-15 11:07:57 -07:00