Commit graph

883 commits

Author SHA1 Message Date
Kristiyan Kostadinov
2c6781071f fix(compiler-cli): error for type parameter declarations
Fixes an error that was heppning when a generic param has type parameters of its own. There were a few different issues going on:
1. In #67707 I had changed a bit how we pass the `genericContextBehavior` which ended up ignoring the `useContextGenericType` option from the environment.
2. All directives depend on themselves, but we were overridding the `genericContextBehavior` for the directive being processed.
3. The type translator wasn't handling type parameter declarations. Technically we shouldn't be able to hit a code path that has a type parameter, however it's also easy enough to handle so we might as well.

Relates to #67704.

(cherry picked from commit ab061a7610)
2026-04-07 16:29:37 +00:00
Kristiyan Kostadinov
d715c366d9 refactor(compiler-cli): fix failing tests
Fixes some tests that started failing after recent changes.

(cherry picked from commit fd95735594)
2026-04-06 12:33:09 -07:00
Andrei Chmelev
bba5ed8e64 fix(compiler-cli): prevent recursive scope checks for invalid NgModule imports
Avoid recursive local scope lookups when invalid NgModule imports create import cycles.

(cherry picked from commit fcd0bb0db8)
2026-03-27 16:10:08 +01:00
Kristiyan Kostadinov
67e0ba7e03 fix(compiler-cli): generic types not filled out correctly in type check block
Fixes a regression caused by the recent TCB changes where we moved the type parameter processing earlier in the pipeline and stopped properly accounting for the `TcbGenericContextBehavior`.

Fixes #67704.

(cherry picked from commit 9769560da7)
2026-03-17 12:21:31 -07:00
Kristiyan Kostadinov
26c43d14ba fix(compiler-cli): escape template literal in TCB
Fixes a regression introduced by #67381 where we weren't escaping backticks in template literals.

Fixes #67675.

(cherry picked from commit 2bd708fb6b)
2026-03-16 09:47:29 -07:00
Doug Parker
05d022d5e6 fix(compiler-cli): ignore generated ngDevMode signal branch for code coverage
The Angular compiler unconditionally adds a debug name transform for signals
which generates a conditional on `ngDevMode` (e.g., `ngDevMode ? { debugName: "xyz" } : []`).
During testing, `ngDevMode` is true, so the true branch executes but the
false branch is never executed. Consequently, coverage tools report the
false branch as an untested line/branch, preventing 100% test coverage.

This commit adds a synthetic `/* istanbul ignore next */` comment to the
generated false branch so that Istanbul ignores it. We only include the
istanbul comment (instead of additionally including c8) to focus on the
established standard for Angular CLI/Karma coverage while maintaining
compatibility with modern Vitest setups, since @vitest/coverage-v8 now
natively respects the fallback istanbul comment.

Fixes #64583

(cherry picked from commit dc4cf649b6)
2026-03-04 22:42:57 +00:00
SkyZeroZx
c0cb6040f8 fix(compiler-cli): detect uninvoked functions in defer trigger expressions
Wrap `@defer` trigger expressions (`when`, `prefetch when`, `hydrate when`)
in a conditional context within the TCB to enable TypeScript's TS2774
diagnostic for detecting functions used without invocation.

Previously, signals and functions passed to `when` triggers without
parentheses would silently evaluate to truthy, causing unexpected behavior.
Now the compiler reports an error when a function is used as a condition
without being called.

(cherry picked from commit f90e5565e0)
2026-02-20 16:57:08 +00:00
Kristiyan Kostadinov
81cabc1477 feat(core): add support for TypeScript 6
Updates the project to support TypeScript 6 and accounts for some of the breakages.
2026-02-17 08:40:38 -08:00
Leon Senft
3606902b33
refactor(forms): relax [formField] input type from FieldTree to Field
`FieldTree` was an unnecessarily specific type for the `[formField]`
input. It forced the directive to care about what _kind_ of `FieldTree`
was bound–specifically whether it was Reactive Forms compatible or not.
This made it difficult to author forms system-agnostic components with
passthrough `[formField]` inputs.
2026-02-11 11:45:20 -08:00
Angular Robot
11767cabe4 build: update Jasmine to 6.0.0
Jasmine enables `forbidDuplicateNames: true` by default. So we also need to desambiguate duplicate spec names.
2026-02-09 12:15:57 -08:00
Matthieu Riegler
43d61ecbb2 docs(docs-infra): extract call signature return type.
fixes #66799
2026-02-03 12:31:36 -08:00
Matthieu Riegler
72dfb4d92a docs(docs-infra): wrap getTextOfJSDocComment
This commits adds a wrapper around `ts.getTextOfJSDocComment` because of bugs that won't be fixed by the TS team (see microsoft/TypeScript#63027)
2026-01-29 13:16:00 -08:00
Kristiyan Kostadinov
d9c980a958 build: initial test of TypeScript 6
Resolves some initial test failures after updating to TypeScript 6.
2026-01-15 13:41:01 -08:00
Matthieu Riegler
72534e2a34 feat(compiler): Add support for the instanceof binary operator
Because why not ?

fixes #59975
2026-01-13 08:33:12 -08:00
Shuaib Hasan Akib
1b4dcc01ff docs: replace old https://angular.io/license with https://angular.dev/license 2026-01-12 13:41:30 -08:00
Miles Malerba
5671f2cc07
fix(forms): Rename signal form [field] to [formField]
This completes the rename started in #66136. `[field]` is too generic of
a selector for the forms system to own, and likely to cause naming
collisions with existing components. Therefore it is being renamed to
`[formField]`
2026-01-09 14:33:09 -08:00
Kristiyan Kostadinov
87a422358b refactor(compiler-cli): template type checking support for arrow functions
Updates the template type checker to support arrow functions. The main challenge was getting the current infrastructure not to rewrite references to arrow function parameters.
2026-01-09 10:35:37 -08:00
Kristiyan Kostadinov
a0dfa5fa86 feat(core): support rest arguments in function calls
Updates the template syntax to support rest arguments in function calls. This can be handy for functions with a variable number of arguments.
2026-01-07 12:37:52 -05:00
Kristiyan Kostadinov
6e18fa8bc9 feat(core): support spread elements in array literals
Expands the template syntax to support spread elements inside arrays. This can be handy for some bindings.
2026-01-07 12:37:52 -05:00
Kristiyan Kostadinov
e407280ab5 feat(core): support spread expressions in object literals
Adds support for spread expressions inside of object literals. This can be handy when constructing maps for `class` bindings.
2026-01-07 12:37:52 -05:00
Matthieu Riegler
640693da8e feat(compiler): Add support for multiple swich cases matching
consecutive `@case` blocks are now supported:

```ts
@switch (case) {
  @case (0)
  @case (1) {
    case 0 or 1
  }
  @case (2) {
    case 2
  }
  @default {
    default
  }
}
```

fixes #14659
2026-01-07 09:23:50 -05:00
Alan Agius
91dc91bae4
fix(core): sanitize sensitive attributes on SVG script elements
This commit updates the DOM security schema and sanitization logic to properly recognize and sanitize `href` and `xlink:href` attributes on SVG `<script>` elements.
2026-01-06 15:49:52 -05:00
SkyZeroZx
ed7bfb3c88 feat(docs-infra): Extracts aliases from doc entries
Implements a mechanism to extract alias names from a directive's selector.
2026-01-05 12:33:14 -05:00
Kristiyan Kostadinov
3a26244d61 fix(compiler-cli): fix up spelling of diagnostic
Fixes the spelling for the `component is missing a template` diagnostic and expands it a bit.
2026-01-02 08:27:27 +01:00
JoostK
106ba63650 fix(compiler-cli): ensure component import diagnostics are reported within the imports expression
PR #60455 improved error reporting for `@Component.imports` by scoping the diagnostic to an individual
element within the `imports` array, but this may introduce hard to track diagnostics when it ends
up being reported (far) away from the component itself.

This can be even more problematic when the diagnostic would end up being reported in a declaration file,
as happened in issue #65686; the declaration files of an imported library contained syntax that the
static interpreter did not support, hence the `@Component.imports` was rejected with a diagnostic reported
in the library's declaration file. This diagnostic isn't guaranteed to be reported (e.g. the CLI only
gathers Angular-specific diagnostics for Angular-compiled files, which excludes declaration files).

This commit changes the diagnostic location to ensure it is being reported within the `@Component.imports`
expression, in most cases retaining the desirable effect of #60455 while avoiding out-of-band diagnostics.
2026-01-02 08:21:08 +01:00
Alan Agius
d4111eebc6
refactor(compiler): remove unnecessary sanitization for safe attributes
Remove sanitization for attributes that cannot execute code (e.g. `javascript: URIs`).
2025-12-15 14:13:38 -08:00
Andrew Kushnir
8243bb3064 Revert "refactor(compiler): remove unnecessary sanitization for safe attributes"
This reverts commit 128aef0ede.
2025-12-12 12:59:47 -08:00
Alan Agius
128aef0ede
refactor(compiler): remove unnecessary sanitization for safe attributes
Remove sanitization for attributes that cannot execute code (e.g. `javascript: URIs`).
2025-12-12 08:05:58 -08:00
Kristiyan Kostadinov
8a3f3a91cf fix(compiler-cli): expand type for native controls with a dynamic type
We recently allowed users to have a dynamic input `type` with signal forms, but the logic that infers the value type falls back to `string` even though in theory it can be any of the other types.

These changes expand the inferred type to `string | number | boolean | Date | null` if we detect a dynamic `type` binding.
2025-12-09 13:01:30 -08:00
Matthieu Riegler
8199945637 refactor(core): add dedicated deprecated signatures for providedIn: any / NgModule.
Those were deprecated by #47616 back in v15.

fixes #65923
2025-12-09 10:38:09 -08:00
Kristiyan Kostadinov
ae1c0dc490 perf(compiler): chain query creation instructions
We always emit the query creation instructions in a group which makes them good candidates for chaining.
2025-12-09 09:24:36 -08:00
Kristiyan Kostadinov
6773d3b97d fix(compiler-cli): check that field radio button values are strings
Adds some type checking code which verifies that the bound `value` on a `Field` radio button is a string.

Fixes #65726.
2025-12-03 12:18:57 +01:00
Kristiyan Kostadinov
e30e61b789 fix(compiler-cli): avoid allocating an object for signals in production mode
Currently when the signal debug name transform sees something like `const foo = signal(0);`, it transforms the signal into `signal(0, {...(ngDevMode ? { debugName: 'foo' } : {})})`. After minification this becomes `signal(0, {})` which will allocate memory for the empty object literal.

These changes rework the logic to produce `signal(0, ...(ngDevMode ? [{ debugName: 'foo' }] : []))` which will be fully tree shaken away to `signal(0)`.
2025-12-02 15:06:51 +01:00
Alan Agius
1c6b0704fb
fix(compiler): prevent XSS via SVG animation attributeName and MathML/SVG URLs
This commit implements a security fix to prevent XSS vulnerabilities where SVG animation elements (`<animate>`, `<set>`, etc.) could be used to modify the `href` or `xlink:href` attributes of other elements to `javascript:` URLs.
2025-12-01 10:26:56 +01:00
AntonChesnokov
5bfa027d41 fix(compiler-cli): escape angular control flow in jsdoc
Escape @-prefixed template control flow constructs during doc extraction so JSDoc parsing keeps description text intact. Add regression coverage for @for snippets.
2025-11-25 11:33:25 -05:00
Leon Senft
3a1eb07c46 fix(forms): allow dynamic type bindings on signal form controls
The type checker will no longer prohibit binding the Signal Forms `[field]`
directive to an input with a dynamic `[attr.type]` or `[type]` binding.
2025-11-25 09:15:58 -05:00
Kristiyan Kostadinov
6b8720de91 fix(compiler-cli): do not type check native controls with ControlValueAccessor
Currently when we detect a `field` binding on a native element, we treat it as a built-in native control. This might not be the case if it's a pre-existing `ControlValueAccessor` relying on the CVA interop.

These changes try to detect any CVA-like directive on the element and disable the additional type checking if there are any.

Fixes #65468.
2025-11-24 13:08:42 -05:00
hawkgs
0f4b11c293 refactor(compiler-cli): add a resource debugName transform (#64172)
Add a TS transform for `resource` (and `httpResource`) `debugName`. Test the transformations.

PR Close #64172
2025-11-24 11:30:12 -05:00
Kristiyan Kostadinov
f7e58577a4 refactor(compiler-cli): rework type checking for signal forms
Reworks the way we approach type checking of signal forms to be closer to the behavior at runtime. There are a couple of scenarios that we handle:

1. For native controls, we now produce simplified type checking code that looks as follows:

```
var t1 = null! as number | string; // Type depends on the input `type`.
t1 = someField().value();
```

2. For custom controls we generate bindings to the individual inputs, rather than checking conformance against `FormValueControl`/`FormCheckboxControl`. This is closer to the behavior at runtime and it allows us to handle generic directives properly.
2025-11-12 13:13:48 -08:00
Kristiyan Kostadinov
a61e01d51f fix(compiler-cli): allow value to be set on radio fields
Updates the logic that checks for unsupported bindigns to allow `value` to be set on `radio` controls.
2025-11-07 11:57:50 -08:00
Kristiyan Kostadinov
165634264e fix(compiler-cli): do not flag custom control required inputs as missing when field is present
Adds some logic that won't report the `value` or `checked` inputs as missing when the `Field` directive is present since it will bind to the inputs implicitly.
2025-11-07 11:57:50 -08:00
Kristiyan Kostadinov
4d0778529f fix(compiler-cli): use any when checking field interface conformance
Switches to checking against `FormValueControl<any>` instead of `FormValueControl<unknown>` when checking whether custom controls conform to the interface.

Fixes #64946.
2025-11-07 11:57:50 -08:00
Miles Malerba
0efb3f6d1f refactor(forms): nicer type errors
By intersecting with `object` instead of `unknown` in the primitive and
`FormControl` cases, we get TypeScript to show nicer type errors that
mention `FieldTree<...>` insetad of `() => FieldState<...>`
2025-11-07 07:45:05 -08:00
Kristiyan Kostadinov
748caf9a74 test(compiler-cli): set up TCB tests for signal forms
Adds TCB-specific tests for the generated code in signal forms since they tend to be a bit easier to read and follow.
2025-11-05 17:35:43 +00:00
Kristiyan Kostadinov
3c7751020e refactor(compiler-cli): check that custom control conforms to control interfaces
Generates additional type checking code to ensure that custom control conform to either `FormValueControl` or `FormCheckboxControl`.
2025-11-05 17:35:43 +00:00
Kristiyan Kostadinov
04ed91071b refactor(compiler-cli): flag unsupported static bindings on field directives
Expands the diagnostic for unuspported bindings on fields to also capture static attributes.
2025-11-05 17:35:43 +00:00
Kristiyan Kostadinov
948e2f4f01 fix(compiler-cli): infer type of custom field controls
Adds the logic to infer the type of a custom field control that's on the same element as the `Field` directive.
2025-11-05 17:35:43 +00:00
Kristiyan Kostadinov
6b51fc3e9d fix(compiler-cli): infer types of signal forms set on native inputs
Sets up the logic for inferring the type of the signal form that is set on a native `input`, `textarea` or `select`.
2025-11-05 17:35:43 +00:00
Kristiyan Kostadinov
c5ac77cb32 refactor(compiler-cli): allow the forms module to be loaded in tests
Updates the testing utilities to allow for `@angular/forms` to be loaded.
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