Commit graph

1767 commits

Author SHA1 Message Date
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
Miles Malerba
2d85ae5811 feat(forms): add [formField] directive
This will replace the `[field]` directive, since `[field]` is a very
generic name for signal forms to commandeer

refactor(forms): hook up `formField` directive in compiler

Hooks up the `formField` direcive to get the same treatment as the
`field` directive in the compiler.

apply updated formatting
2026-01-06 17:21:06 -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
41eacff363 test(compiler): switch compliance tests to es2022
Sets up the compliance tests to target es2022 since that's the default in the CLI. Also updates all of the tests, primarily because the generated output for static properties has changed.
2026-01-02 08:29:12 +01: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
Joey Perrott
aa92f19307 build: update to bazel version 8.4.2
Update bazel to use version 8.4.2
2025-12-08 10:21:59 -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
Matthieu Riegler
f35b2ef47c refactor(compiler): Generate the controlCreate instruction after the native element has been created
This is necessary to exclude a race condition where the MutationObserver initialized by the instruction fired before the inputs are binded.

fixes #65678
2025-12-02 12:59:49 +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
Alan Agius
26fed34e0e
build: format md files
This commit configures prettier to format markdown files.
2025-11-06 10:03: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
Leon Senft
41be02da2f perf(forms): implement change detection for field control bindings
For each field state property, check if it has changed since the last
time it was checked before writing it the corresponding form control
property.

The `pattern` and `required` properties of the field state now return a
default value rather than `undefined` if not defined by metadata.
2025-11-05 00:11:22 +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
Matthieu Riegler
62cda789a8 refactor(compiler): Improve pipe in track expression error (#64321)
Throw a parse error for a better context awareness.

fixes #64316

PR Close #64321
2025-10-13 08:59:56 -07:00
Miles Malerba
2fdd4da2a8 refactor(forms): rename the control directive to the field directive (#64300)
Renames the control directive and the input that users set to bind a
field to a UI control.

Previously users would do:

```
<input [control]="someField">
```

Now users will do:

```
<input [filed]="someField">
```

PR Close #64300
2025-10-13 08:59:13 -07:00
Kristiyan Kostadinov
d73d9acbfb build: fix broken test (#64319)
Fixes a test that didn't exist when the recent metadata PR was created.

PR Close #64319
2025-10-09 11:35:29 -07:00
Kristiyan Kostadinov
ab98b2425f fix(compiler-cli): capture metadata for undecorated fields (#63957)
Currently if `TestBed.overrideComponent` is used on a class that uses initializer APIs (e.g. `input()`), the initializer metadata will be wiped out, because `overrideComponent` re-compiles the class with the information set by `setClassMetadata`. `setClassMetadata` only captures decorated members at the moment.

These changes introduce some logic to capture the new initializer-based APIs in `setClassMetadata` as well.

Fixes #57944.

PR Close #63957
2025-10-09 14:02:16 -04:00
Kristiyan Kostadinov
ddeef60db2 refactor(compiler): support viewport trigger options in pipeline (#64130)
Updates the template pipeline to support options for the `viewport` triggers.

PR Close #64130
2025-10-09 05:32:20 -07:00
Kristiyan Kostadinov
e2367c8855 refactor(compiler-cli): type check viewport trigger options (#64130)
Updates the template type checker to check the options of the `viewport` trigger against `IntersectionObserver`.

PR Close #64130
2025-10-09 05:32:20 -07:00
Leon Senft
effccffde0 refactor(core): add framework support for binding form controls (#63773)
Move most of the implementation of the `Control` directive into core
framework instructions. This allows field state changes to be propagated
to their corresponding UI controls directly during execution of a
template update block, instead of relying on `effect()`s to synchronize
each change later during the update (and too late in the case of
required inputs).

* Define a private API in `@angular/core` for signal forms to implement:
  * `ɵControl` for the `Control` directive.
  * `ɵFieldState` for the control's associated `FieldState`.
* Emit specialized instructions when compiling a `[control]` binding:
  * `ɵɵcontrolCreate` sets up the `ɵControl` directive if present,
    determines whether it's bound to a native control element or a
    custom control component, and adds the appropriate event listeners
    to notify the `ɵFieldState` of UI changes.
  * `ɵɵcontrol` propagates changes from `ɵFieldState` properties to their
    corresponding UI control properties (in additional to binding the `control`
    property itself).

PR Close #63773
2025-10-04 13:21:55 -07:00
Leon Senft
42e1062bc5 refactor(core): add specialized instruction for [control] bindings (#63773)
* Emit a `ɵɵcontrol` instruction in place of `ɵɵproperty` for property
  bindings named "control". This instruction cannot be chained, but is
  otherwise functionally equivalent.

* Upcoming changes will use the `ɵɵcontrol` instruction to bind a signal
  form field to a UI control (be it a native element or custom directive).

PR Close #63773
2025-10-04 13:21:55 -07:00
Alan Agius
fc643c9044 build: adopt moduleResolution: "bundler" (#64125)
This commit updates the TypeScript configuration across the project to use `moduleResolution: "bundler"`. This modernizes our module resolution strategy to align with current TypeScript best practices and bundler behaviors.

The following changes are included:
- Updated `tsconfig.json` files to set `moduleResolution` to `"bundler"`.
- Updated the `rules_angular` bazel dependency to a version compatible with these changes.
- Adjusted related test files and golden files to reflect the new module resolution strategy.

PR Close #64125
2025-09-29 14:20:23 -04:00
Joey Perrott
758f0883f5 test(core): remove shelljs from core schematics tests (#64042)
Remove shelljs usage from core schematic tests and use builtins instead

PR Close #64042
2025-09-26 13:14:09 -04:00
SkyZeroZx
3bd91ded43 fix(compiler-cli): resolve import alias in defer blocks (#63966)
Fixes an error where using an alias in a defer block caused the compiler CLI to fail when parsing. The resolution logic in ComponentDecoratorHandler was updated to correctly handle deferred dependencies with aliased imports.

PR Close #63966
2025-09-22 15:52:16 +00:00