Commit graph

108 commits

Author SHA1 Message Date
Kristiyan Kostadinov
f20103a1d7 fix(compiler-cli): report invalid bindings on form controls
Adds validation that users don't bind to unsupported properties on nodes with the `Field` directive.
2025-11-05 17:35:43 +00:00
Jessica Janiuk
e039c6be02 refactor(compiler): Throw an error when old and new animations are used together (#64569)
This adds a new compilation error if someone attempts to put legacy animations and `animate.enter` or `animate.leave` in the same component.

PR Close #64569
2025-10-22 17:14:47 +00:00
SkyZeroZx
563dbd998c feat(compiler-cli): Adds diagnostic for misconfigured @defer triggers (#64069)
Warns when @defer blocks define unreachable or redundant triggers, such as multiple main triggers, ineffective prefetches, or timer delays not scheduled before rendering.

PR Close #64069
2025-10-13 11:06:01 -07:00
Matthieu Riegler
6dff287bb8 refactor(compiler-cli): Add a diagnostic to detect forbiden invocations of required initializers (#63614)
The diagnostic will raise an error when required initializers (input, model, queries) are invoked the context of property initializers and contructors.

Docs will be provided in a follow-up

fixes #63602

PR Close #63614
2025-09-15 19:34:32 +00:00
Jonathan Meier
be7110342b fix(compiler-cli): disallow compiling with the emitDeclarationOnly TS compiler option enabled (#61609)
Running the Angular compiler with declaration-only emission is dangerous
because Angular does not yet support this mode as it relies on the Ivy
compilation which does not run in this mode

In the best case, everything works fine as incidentally there's no
difference in the emitted type declarations (e.g. this is the case for
TS files containing no Angular annotations or only `@Injectable`
annotations).

In the worst case, compilation silently fails in that the compilation
succeeds but the resulting type declarations are missing the Angular
type information and are therefore incomplete. This happens for all
components, directives and modules.

BREAKING CHANGE: The Angular compiler now produces an error when the
the `emitDeclarationOnly` TS compiler option is enabled as this mode is
not supported.

PR Close #61609
2025-08-14 13:03:54 +02:00
Joey Perrott
23d58777b4 build: migrate to new toolchain usage for api goldens (#62688)
Migrate api golden usage to be based on rules_js toolchain implementation

PR Close #62688
2025-07-17 18:13:42 -04:00
Rafael Camara
5abfe4a899 feat(compiler-cli): add diagnostic for uninvoked functions in text interpolation (#59191)
This commit adds a new extended diagnostic to detect uninvoked functions in text interpolation.

PR Close #59191
2025-07-16 16:30:37 -04:00
Kristiyan Kostadinov
a70f03a9b4 fix(compiler): move defer trigger assertions out of parser (#61747)
When defer blocks have a reference-based trigger without a parameter, we infer it from the placeholder block. This requires some validations like ensuring that there's only one element in the placeholder. The validations are currently implemented at the parser level which can affect tools like linters that need to pass `preserveWhitespaces: true` in order to get accurate source mappings.

These changes move the validations into the template type checker so that they still get flagged, but much later in the process. Moving them over involves a bit more work, because the template type checker also sets `preserveWhitespaces: true`.

Fixes #61725.

PR Close #61747
2025-05-30 13:44:58 -04:00
Jonathan Meier
77fa204ad1 fix(compiler-cli): rename flag for enabling fast type declaration emission (#61353)
Rename the flag `_geminiAllowEmitDeclarationOnly` to
`_experimentalAllowEmitDeclarationOnly` as a follow-up on a comment in
PR #61334.

PR Close #61353
2025-05-19 08:27:43 +00:00
Jonathan Meier
e62fb359d6 feat(compiler-cli): add experimental support for fast type declaration emission (#61334)
In declaration-only emission mode, the compiler extracts the type
declarations (.d.ts) files without full type-checking, which is possible
with sufficient type annotations on exports that can be ensured by the
`isolatedDeclarations` TS compiler option.

This allows us to decouple type declaration emission from the actual
full compilation doing the type-checking, thereby removing the
edge between dependent TS files in the build action graph. In other
words, the compilation of a TS file no longer indirectly depends on the
compilation of all the TS files it imports through its dependency on
their type declarations, because the type declarations themselves no
longer depend on the compilation of their associated TS file.

Without the coupling between type declaration emission and compilation,
compilation time of a TS project is no longer bound dependent on the
depth of the TS dependency tree as we can now build the entire project
with just two entirely parallel phases: 1) emit the type declarations of
all TS files in parallel and 2) compile all TS files in parallel.

Since the Angular compiler adds static metadata fields to components,
directives, modules, pipes and services based on their respective class
annotations, it needs to actively partake in the type declaration
emission in order to provide the types for these static fields in the
declaration.

In this change, we add experimental support for a declaration-only
emission mode based on the local compilation mode, which already
operates without type-checking and access to external type information,
i.e. the same environment as is required for declaration-only emisssion.

Apart from the same restrictions applied in local compilation mode,
there are a few more restrictions imposed on code being compatible with
this initial and experimental implementation:

* No support for `@NgModule`s using external references.
* No support for `hostDirectives` in `@Component`s and `@Directive`s
  using external references
* No support for `@Input` annotations with `transform`.

PR Close #61334
2025-05-14 14:07:37 -07:00
Kristiyan Kostadinov
7118dac442 refactor(compiler-cli): add selectorless-related analysis to components (#61100)
Adds the logic to determine whether a component is selectorless and to track which symbols are used in the template.

PR Close #61100
2025-05-05 14:38:12 -07:00
Kevin Brey
c889382a20 feat(compiler-cli): detect missing structural directive imports (#59443)
Adds a new diagnostic that ensures that a standalone component using custom structural directives in a template has the necessary imports for those directives.

Fixes #37322

PR Close #59443
2025-04-29 09:43:12 -07:00
Kristiyan Kostadinov
e89ebf3dc7 refactor(compiler-cli): add infrastructure for new diagnostics (#60977)
We need a couple of custom diagnostics for selectorless. These changes add the infrastructure so they can be reported.

PR Close #60977
2025-04-24 13:02:39 -07:00
Enea Jahollari
7a971766dc feat(compiler): add extended diagnostic for uninvoked track function on @for blocks (#60495)
The compiler will warn devs when they haven't invoked the track function passed to track in @for blocks

PR Close #60495
2025-04-08 10:10:33 -07:00
Andrew Scott
5948cd03c5 fix(compiler-cli): Produce fatal diagnostic on duplicate decorated properties (#60376)
This prevents the compilation and language service from crashing.

fixes https://github.com/angular/vscode-ng-language-service/issues/2091

PR Close #60376
2025-03-27 20:26:42 +00:00
Miles Malerba
bec1610da2 feat(compiler-cli): add extended diagnostic for invalid nullish coalescing (#60279)
The semantics for nullish coalescing (`??`) in Javascript/Typescript
differ slightly from the semantics in Angular templates. Mixing nullish
coalescing with logical and/or without parentheses is an error in
Javascript. This PR adds an extended diagnostic that can be enabled to
treat it as an error in Angular templates as well.

PR Close #60279
2025-03-19 10:21:48 +01:00
Kristiyan Kostadinov
bf2b0253bc refactor(compiler-cli): move typeCheckHostBindings option (#60267)
Moves the `typeCheckHostBindings` option into `StrictTemplateOptions` and renames the latter.

PR Close #60267
2025-03-17 14:28:41 +01:00
Kristiyan Kostadinov
1971e57a45 feat(compiler-cli): support type checking of host bindings (#60267)
Historically Angular's type checking only extended to templates, however host bindings can contain expressions as well which can have type checking issues of their own. These changes expand the type checking infrastructure to cover the `host` object literal, `@HostBinding` decorators and `@HostListener` with full language service support coming in future commits.

Note that initially the new functionality is disabled by default and has to be enabled using the `typeCheckHostBindings` compiler flag.

PR Close #60267
2025-03-17 14:28:41 +01:00
Andrew Kushnir
d0ad030ec7 Revert "feat(compiler-cli): detect missing structural directive imports (#59443)" (#59544)
This reverts commit ed705a856a.

PR Close #59544
2025-01-15 13:38:37 -08:00
Kevin Brey
ed705a856a feat(compiler-cli): detect missing structural directive imports (#59443)
Adds a new diagnostic that ensures that a standalone component using custom structural directives in a template has the necessary imports for those directives.

Fixes #37322

PR Close #59443
2025-01-15 13:59:37 -05: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
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
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
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
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
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
Enea Jahollari
c8e2885136 feat(compiler): Add extended diagnostic to warn when there are uncalled functions in event bindings (#56295) (#56295)
The diagnostic will catch issues like:

```html
<button (click)="increment"></button>
<button (click)="increment; decrement"></button>
<button (click)="true ? increment : decrement"></button>
<button (click)="nested.nested1.nested2.increment"></button>
```

PR Close #56295

(cherry picked from commit fd6cd0422d)

PR Close #56295
2024-07-03 15:36:39 +00:00
Jessica Janiuk
ec89fb6242 Revert "feat(compiler): Add extended diagnostic to warn when there are uncalled functions in event bindings (#56295)" (#56810)
This reverts commit fd6cd0422d.

PR Close #56810
2024-07-02 14:14:50 +00:00
Enea Jahollari
fd6cd0422d feat(compiler): Add extended diagnostic to warn when there are uncalled functions in event bindings (#56295)
The diagnostic will catch issues like:

```html
<button (click)="increment"></button>
<button (click)="increment; decrement"></button>
<button (click)="true ? increment : decrement"></button>
<button (click)="nested.nested1.nested2.increment"></button>
```

PR Close #56295
2024-07-01 20:31:19 +00:00
Kristiyan Kostadinov
4d18c5bfd5 fix(compiler-cli): flag all conflicts between let declarations and local symbols (#56752)
Expands the check around conflicting `@let` declarations to also cover template variables and local references.

PR Close #56752
2024-07-01 14:03:57 +00:00
Kristiyan Kostadinov
9aea8a0576 refactor(compiler-cli): add diagnostic for duplicate let declarations (#56199)
Adds a template diagnostic that will flag cases where multiple `@let` declarations use the same name.

PR Close #56199
2024-06-04 17:28:03 +00:00
Kristiyan Kostadinov
695126453e refactor(compiler-cli): integrate let declarations into the template type checker (#56199)
Integrates let declarations into the template type checker by producing corresponding constants in the TCB.

This also includes a couple of custom diagnostics to flag usages of let before they're declared and illegal writes to let declarations. We can't rely on TS for these checks, because it includes the variable name in the diagnostic.

PR Close #56199
2024-06-04 17:28:03 +00:00
Kristiyan Kostadinov
fb351300c3 build: update to latest dev infra code (#56128)
Updates the repo to the latest dev infra code which involves updating a patch and renaming all the golden files to end with `.api.md`.

PR Close #56128
2024-05-28 14:42:31 +02:00
Kristiyan Kostadinov
78188e877a fix(compiler-cli): add diagnostic if initializer API is used outside of an initializer (#54993)
Adds a rule that will produce a diagnostic when an initializer-based API is used outside of an initializer.

Fixes #54381.

PR Close #54993
2024-03-28 09:17:02 -07:00
Paul Gschwendtner
64ae07766e refactor(compiler-cli): support enforcing field access for initializer APIs (#54981)
An initializer API like `input`, `output`, or signal queries may not be
compatible with certain access levels. E.g. queries cannot work with ES
private class fields.

This commit introduces a check for access levels into the initializer
API recognition— enforcing that every initializer API *clearly*
specifies what type of access is allowed.

PR Close #54981
2024-03-27 09:54:45 -07:00
Dylan Hunn
ef32b5322e refactor(compiler): Delete TemplateDefinitionBuilder and helpers (#54757)
`TemplateDefinitionBuilder` is the legacy template compiler, and was replaced by Template Pipeline as the default in v17.3.

This PR attempts to delete `TemplateDefinitionBuilder`, `ExpressionConverter`, and various helpers (i18n context, style builder, property visitors, etc).

Consider this a first pass: a lot of code has not yet been deleted (e.g. old TDB-specific test cases), and I'm sure I have missed additional helper code.

PR Close #54757
2024-03-08 16:51:01 -08:00
Payam Valadkhan
27886cccce refactor(compiler-cli): use a more generic error for unsupported expressions in local compilation mode (#54366)
A new error code `LOCAL_COMPILATION_UNSUPPORTED_EXPRESSION` is added for this purpose, replacing a narrow one.

PR Close #54366
2024-02-12 08:49:03 -08:00
Payam Valadkhan
df74ed94e2 refactor(compiler-cli): upgrade error codes and messages for unresolved symbol errors in local compilation mode (#54230)
A single error code is created to unify the common error pattern in local compilation mode where an imported const cannot be resolved, but needs to be resolved. This mainly happens for Angular decorator fields such as @Component.template.

The error messages are also upgraded to be more centered around this unifying theme.

PR Close #54230
2024-02-06 21:33:29 +00:00
Paul Gschwendtner
f7da77b90d refactor(compiler-cli): detect output() function (#54217)
As we are introducing the new `output()` function as an inituive
alternative to `@Output()` that matches with signal-based inputs,
this commit prepares the compiler to detect such initializer-based
outputs.

PR Close #54217
2024-02-05 15:08:34 +00:00
Payam Valadkhan
fc55de1416 refactor(compiler-cli): incorporate LocalCompilationExtraImportsTracker in the compilation workflow (#53543)
This commit includes a skeleton of how the tool `LocalCompilationExtraImportsTracker` is used in the overall compilation workflow end-to-end.

First of all, a new option `generateExtraImportsInLocalMode` is added, whose presence will make `LocalCompilationExtraImportsTracker` part of the compilation process. When this option is set an instance of `LocalCompilationExtraImportsTracker` is created within the NgCompiler. Then it is passed to the Ivy transformer and plumbed all the way down and the extra imports registered in it are added to the `ImportManager` instances before the imports are added from `ImportManager` to the generated file. This required adding a new method `generateSideEffectImport` to the `ImportManager`, which is an empty method and will be implemented in the subsequent commits.

This commit expected to make no change in the compilation behavior as the methods are not implemented yet.

PR Close #53543
2024-01-30 15:05:42 +00:00
Dylan Hunn
47e6e84101 feat(compiler): Add a TSConfig option useTemplatePipeline (#54057)
The Template Pipeline is a brand new backend for the Angular compiler, replacing `TemplateDefinitionBuilder`. It generates the Ivy instructions corresponding to an input template (or host binding). The Template Pipeline has an all-new design based on an intermediate representation compiled over many phases, which will allow us to experiment with compiler changes more easily in the future.

With this commit, the template pipeline can now be enabled in any project via the `useTemplatePipeline` TSConfig option. However, it is still disabled by default.

PR Close #54057
2024-01-24 18:36:23 -05:00
Paul Gschwendtner
17a47c4c54 refactor(compiler-cli): additional diagnostics for signal-based queries (#54019)
This commit introduces three additional diagnostics for queries:

- If a query (either using decorator or signal-based) is declared on a
  static class member, a diagnostic is raised.
- If a signal-based query is mixed with a query decorator, a diagnostic
  is raised. Similar to signal inputs.
- If a singal-based query is also declared in the directive/component
  class decorator metadata, a diagnostic is raised.

PR Close #54019
2024-01-24 16:13:31 +01:00
Payam Valadkhan
3e1384048e feat(compiler-cli): support host directives for local compilation mode (#53877)
At the moment local compilation breaks for host directives because the current logic relies on global static analysis. This change creates a local version by cutting the diagnostics and copying the directive identifier as it is to the generated code without attempting to statically resolve it.

PR Close #53877
2024-01-22 14:44:24 +01:00
Andrew Kushnir
a2aa23d8b5 refactor(compiler): add support for internal deferredImports field (#53591)
This commit updates the logic to add support for internal `deferredImports` field in compiler.

PR Close #53591
2024-01-10 15:28:58 -08:00
Andrew Kushnir
d28cf00df6 refactor(compiler-cli): add an internal config to enforce explicit deps in @defer for local compilation mode (#53591)
This commit adds an internal config option to enforce explicit deps in `@defer` for local compilation mode.

PR Close #53591
2024-01-10 15:28:58 -08:00
Paul Gschwendtner
e934f3a581 refactor(compiler-cli): add diagnostic for inputs declared on static members (#53808)
Currently when someone declares a signal or non-signal input on a static
class member, the compiler will not yield any diagnostic. We can detect
these mistakes and report a diagnostic to help our users.

PR Close #53808
2024-01-10 12:21:06 +00:00
Paul Gschwendtner
40b0467d3e refactor(compiler-cli): diagnostics ensuring signal inputs are declared properly (#53808)
This commit addds two diagnostics for two scenarios where signal inputs
are declared incorrectly:

- a signal input is also annotated with `@Input` in the TypeScript
  sources.
- a signal input is also declared in the `inputs` option of
  `@Directive/`@Component`.

PR Close #53808
2024-01-10 12:21:05 +00:00
Kristiyan Kostadinov
e620b3a724 fix(compiler-cli): add compiler option to disable control flow content projection diagnostic (#53311)
These changes add an option to the `extendedDiagnostics` field that allows the check from #53190 to be disabled. This is a follow-up based on a recent discussion.

PR Close #53311
2023-12-05 17:21:16 -08:00
Kristiyan Kostadinov
4c1d69e288 fix(compiler-cli): add diagnostic for control flow that prevents content projection (#53190)
This is a follow-up to the fix from #52414. It adds a diagnostic that will tell users when a control flow is preventing its direct descendants from being projected into a specific component slot.

PR Close #53190
2023-11-28 11:18:43 +01:00
Kristiyan Kostadinov
f63c0f6e1c Revert "fix(compiler-cli): add diagnostic for control flow that prevents content projection (#52726)" (#53012)
This reverts commit b4d022e230.

PR Close #53012
2023-11-17 11:52:02 -08:00