2356 Commits
Author SHA1 Message Date
Matthieu Riegler 88a931b968 fix(compiler): length-prefix string literals and quoted map keys in ConstantPool keys
Previously, GenericKeyFn.keyOf() wrapped string literals and quoted object literal keys in double quotes without length-prefixing or escaping. As a result, distinct array or object literals extracted during the template compiler's pure function optimization phase (such as ['a', 'b'] and ['a","b'], or {'a': 1, 'b': 2} and {'a":1,"b': 2}) produced identical constant pool keys and erroneously shared the same constant factory.

Prefix string literals and quoted object literal keys with their length ("<length>:<value>") in GenericKeyFn.keyOf() so embedded quotes and delimiters cannot cause key collisions without needing to scan or escape the string.

Fixes #71914
2026-11-19 16:39:37 -08:00
aparzialeandMatthieu Riegler e4f67442bb feat(compiler): report unknown property bindings on explicit ng-template elements
Previously, property bindings on `<ng-template>` that were not claimed
by a matched directive were silently ignored by the type checker. This
was inconsistent with how bindings on regular elements are handled.

This check is added behind a temporary compiler flag `checkTypeOfNgTemplateBindings` which will be removed
in the next breaking change window.

When the flag is enabled, the type checker will report an error for any property binding on an `<ng-template>` that is not matched by a directive.

Fixes #69322

Co-authored-by: Matthieu Riegler <[email protected]>
2026-11-11 15:41:43 -08:00
Alex Rickabaugh 98b0f3b720 refactor(core): remove signal components prototype
Removes the unfinished prototype for signal-based components and directives
(the internal `signals: true` decorator flag):

* `@Directive`/`@Component` no longer accept the internal `signals` option.
* The compiler no longer reads it (ngtsc, JIT, linker, hybrid preprocessor)
  and no longer emits `signals: true` in definitions, `isSignal: true` in
  partial declarations, or the trailing `IsSignal` type argument of
  `ɵɵDirectiveDeclaration`/`ɵɵComponentDeclaration`.
* The runtime drops `DirectiveDef.signals`/`ComponentDef.signals`,
  `LViewFlags.SignalView` and the internal `ComponentMirror.isSignal`.

Signal inputs, model inputs and signal queries (input/query-level `isSignal`)
are unaffected.
2026-11-11 09:10:56 -08:00
Alex Rickabaugh ae9c706d14 refactor(compiler): remove selectorless prototype
Removes the experimental "selectorless" template syntax (`<MyComp>` / `@Dir(...)`)
which was never shipped. This deletes:

- compiler: lexer/parser support for component and directive tokens, the
  html `Component`/`Directive` nodes and the R3 `Component`/`Directive`
  (`TmplAstComponent`/`TmplAstDirective`) nodes together with their visitor
  methods and the `directives` field on elements/templates, the
  `selectorlessEnabled`/`enableSelectorless` parse options, direct pipe
  references (`BindingPipeType`), selectorless reference validation, the
  selectorless paths in the binder (`referencedDirectiveExists`),
  type-check ops, indexer, i18n and template pipeline.
- compiler-cli: the `_enableSelectorless` option, selectorless component
  analysis and `SelectorlessScope`, deferred selectorless dependencies,
  selectorless template symbols, out-of-band diagnostics and the related
  error codes (2024, 2025, 2026, 8018), the linker option, and the
  preprocessor/ng-analyze selectorless analysis.
- language-service: selectorless definitions, quick info, references and
  rename.
- the selectorless runtime and compiler tests.

`SelectorlessMatcher` is kept since it is used to match foreign components
(`foreignImports`) by tag name.
2026-11-11 09:10:56 -08:00
Kristiyan Kostadinov 67064752fc refactor(compiler-cli): move out HMR dependency extraction logic
Moves the HMR dependency extraction logic into the `compiler` package since it's only dealing with our own AST. This will allow us to drop the dependency on `compiler-cli` from the preprocessor.
2026-11-11 13:10:02 +01:00
Kristiyan Kostadinov e05aff7db3 refactor(compiler): move TCB generation tests into compiler
A while ago we moved the TCB generation logic from `compiler-cli` to `compiler`. These changes move over the tests.
2026-11-11 11:01:40 +01:00
Matthieu Riegler 225d600314 fix(compiler): disallow attribute and property names starting with a colon
Previously, binding to an attribute starting with a colon (such as
`[attr.:onclick]` or `[attr.:href]`) resulted in the leading colon being
stripped by `mergeNsAndName` only after attribute validation and security
context resolution had already taken place. This allowed `[attr.:onclick]`
to bypass event attribute validation, producing an `onclick` attribute binding.

Because attribute and property names starting with a colon are invalid syntax
in HTML/XML and Angular templates, this change rejects any attribute or property
binding whose name starts with a colon immediately during validation.

In addition, namespaced event attributes (such as `[attr.svg:onclick]`) are now
properly disallowed by inspecting the local name across element schemas and host
bindings.
2026-11-10 09:42:00 -08:00
Kam 5e9c18755c fix(compiler): convert &ngsp; to a space inside ngNonBindable
The lexer turns the &ngsp; pseudo-entity into the private-use character
U+E500, and the normal text path replaces it with a space through
replaceNgsp. NonBindableVisitor.visitText did not, so the character leaked
into the output when whitespace trimming did not run first, such as inside
a pre element or with preserveWhitespaces enabled.

Call replaceNgsp in NonBindableVisitor.visitText as well.

Fixes #71895
2026-11-10 09:37:10 -08:00
Matthieu Riegler 5cd01d6d8e refactor(compiler): check that ng-container don't have class bindings
This is the same change as #70808 but for g3 only due to its breaking nature.
2026-11-10 09:36:42 -08:00
Flarette 9731822b27 fix(compiler): report errors at arrow parameters
Template type checking dropped every TypeScript diagnostic that started
at an arrow function parameter. For example, with a component method
`takes(fn: (x: number) => number)`, the template expression
`takes((value) => () => 1)` compiled without the TS2345 error that
TypeScript reports at `value`.
2026-11-09 14:34:03 -08:00
lazerg f9fe21d67f fix(compiler): handle void expressions in constant literals
Array and object literals whose entries are all constants get pooled
through `GenericKeyFn.keyOf`, which had no case for `VoidExpr` and threw
when a `void` expression appeared inside such a literal.
2026-11-09 10:52:40 -08:00
Kristiyan Kostadinov 20dd959f4c fix(compiler): avoid compilation errors for invalid tracking functions
Fixes that when we generate code for an `@for` tracking function we had references to variables in a different scope. Now we produce a placeholder expression instead and let the template type checker flag the issues.
2026-10-30 07:29:52 +01:00
Kristiyan Kostadinov 9fe64d48d2 fix(compiler): avoid producing type errors for invalid @let usages
Previous we produced `undefined` when an `@let` was referenced incorrectly. This can cause type issues when the generated code is typed checked so instead we use the `invalid` instruction.
2026-10-30 07:29:52 +01:00
Kristiyan Kostadinov 36fed77553 refactor(compiler-cli): introduce placeholder instruction for invalid expressions
Adds the `ɵɵinvalid` instruction that we can use in places where an expression is used incorrectly, but we can't drop it without affecting the template's logic.
2026-10-30 07:29:52 +01:00
Yarchik 5244ea781d fix(compiler): skip escaped characters when looking for comments in expressions
The expression parser drops everything after the first `//` outside of quotes,
but it did not account for escaped characters. A regular expression ending with
an escaped slash, such as `url.replace(/^https?:\/\//, '')`, was cut off and
reported as an unterminated regular expression, and a string with an escaped
quote followed by `//`, such as `'it\'s // here'`, was cut off as well.
2026-10-25 07:38:39 -07:00
jhjh1214 8ffc232bbf fix(compiler): report errors for malformed template literal interpolations
The expression parser silently discarded any tokens that followed the
expression inside a template literal interpolation. For example,
`${a b}` was parsed as `${a}` and `${flags & 1}` as `${flags}`, without
a diagnostic. A template literal with an interpolation that was never
terminated was also accepted, because its lexer error was skipped in the
same way.

`parseTemplateLiteral` used a catch-all `advance()` to consume the `}`
that closes an interpolation, which also consumed anything else that was
left over. The closing brace is now expected explicitly, before
`rbracesExpected` is decremented so that error recovery still stops at
the brace of the interpolation, and lexer errors are reported.

Templates that were previously accepted with the extra tokens dropped
(or with an unterminated literal) now fail to compile with a parse
error. Valid expressions are not affected.
2026-10-24 13:54:50 -07:00
aparziale 1445af58e6 fix(language-service): resolve symbols for inputs with restricted access
When `strictInputAccessModifiers` is disabled (the default, even with
`strictTemplates`), bindings to input fields with restricted access
(private/protected/readonly) are type-checked through a temporary
variable rather than by assigning to the field directly. The type of
this variable was generated as an indexed access type
`(typeof _t1)["fieldName"]`, which TypeScript does not treat as a
reference to the class member. As a result, quick info, go to
definition, find references and rename did not work for such inputs,
e.g. for `readonly` signal inputs.

The type of the temporary variable is now generated as a type query
with a qualified name, `typeof _t1.fieldName`, which TypeScript
resolves as a regular reference to the class member. Reading a
private/protected field through the type query is an access violation,
so diagnostics are ignored for the type node, while the assignment into
the temporary variable remains fully type-checked. The symbol builder
now resolves the input symbol through the temporary variable's
declaration instead of bailing out.

Fixes #58284
2026-10-22 15:24:41 -07:00
Matthew Beck 8bf5f6fcd6 fix(compiler-cli): synthesize static ctorParameters on jit: true classes
When a jit: true component or directive has a non-empty constructor, emit the
static ctorParameters arrow function before the closing brace of the class to
match ngtsc's IvyTransformationVisitor.downlevelConstructor.
2026-10-22 08:02:13 +02:00
Kristiyan Kostadinov ec9bcab279 fix(compiler): avoid treating attributes with object prototype names as being translated
A bit of an edge case that I ran into while working on the preprocessor. If an attribute has the same name as a property on the object prototype, we were treating it as if it has i18n data.
2026-10-20 09:34:05 -07:00
Charles Lyding fa25145316 refactor(compiler): move indexing logic into @angular/compiler/indexing entrypoint
Move the template indexing files (`packages/compiler/src/indexer/*`) into a dedicated `@angular/compiler/indexing` secondary entrypoint and update all consumers in `@angular/compiler-cli` to import from `@angular/compiler/indexing` (using type-only imports for `@angular/compiler` where applicable).

Separating the indexer from the primary `@angular/compiler` entrypoint avoids bundling indexing logic into the main compiler bundle loaded at runtime for JIT compilation, and allows build and analysis tools to import indexing APIs without triggering the global `publishFacade` side effect in `@angular/compiler`.
2026-10-20 00:41:57 -07:00
Matthieu Riegler 47ad3758fe refactor(compiler): remove redundant 0.x version checks
This addresses a PR review comment by removing redundant checks that would otherwise fall through to returning true anyway.
2026-10-20 00:34:47 -07:00
Matthieu Riegler 3d104c0abb fix(compiler): default to Eager change detection for pre-v22 libraries in JIT
The `convertDeclareComponentFacadeToMetadata` function in the JIT compiler facade previously defaulted component change detection to `OnPush`. This caused components compiled with older versions of Angular (< 22) in partial compilation mode to incorrectly use `OnPush` in JIT (e.g., in Storybook or Jest), despite working properly with `Default` in the AOT linker.
Update the JIT facade to match the AOT linker behavior by checking the major version of the declaration. It defaults to `OnPush` only for components compiled with v22+ or the placeholder version, and uses `Default` change detection for older libraries.

Fixes #71107
2026-10-20 00:34:47 -07:00
Matthieu Riegler 918aca03d7 fix(compiler-cli): escape non-ascii characters in ngp string literals
Extend `escapeIdentifier` in `AbstractEmitterVisitor` with an `escapeNonAscii` option and expose a protected `escapeIdentifier` hook so `ngp`'s `ExpressionPrinter` escapes control and non-ASCII code units as `\uXXXX`, matching TypeScript's `escapeNonAsciiString` behavior on synthesized string literals. Add an i18n named placeholder test case (`// i18n(ph=...)`) to the preprocessor goldens and remove the `\uXXXX` normalization from `ngp_emit_normalizer`.
2026-10-20 07:03:15 +02:00
Kristiyan Kostadinov 89843cddfc fix(compiler-cli): source map generated code in preprocessor
Adds some logic to properly handle source maps for code generated by the preprocessor.
2026-10-16 17:48:35 -07:00
Kristiyan Kostadinov 7728f2765b refactor(compiler): resolve warning with internal tooling
Fixes that the top-level variables we generate from the constant pool cause a warning to be logged internally.
2026-10-14 13:04:08 -07:00
Amine d9bd68258d fix(compiler): check @boundary blocks in the control flow content projection diagnostic
Like `@if`, `@for` and `@switch`, a `@boundary` block copies the tag name
and attributes of its single root node, so the node can be projected into a
specific `ng-content` slot. The `controlFlowPreventingContentProjection`
diagnostic (NG8011) didn't look at `@boundary` blocks though, so an element
next to a second root node was silently projected into the default slot.

`@error` blocks are left out on purpose: they don't copy the tag name and
attributes of their root node, so the diagnostic's suggestions wouldn't apply.

Fixes #71288
2026-10-14 13:03:42 -07:00
Shuaib Hasan Akib 3aaf026486 fix(compiler): compare the operand in ReadTemporaryExpr.isEquivalent
`ReadTemporaryExpr.isEquivalent()` didn't take the expression it was
compared against and compared its own `xref` with itself, so a temporary
read was considered equivalent to any expression, including reads of other
temporaries and unrelated expressions like literals.

Compare against the given expression instead, like the other IR
expressions do: it's only equivalent to a read of the same temporary.

No miscompilation is known to be caused by this, since temporaries are
usually converted to variables before expressions are compared, but the
result was wrong for any caller that compared them earlier.
2026-10-14 13:03:14 -07:00
Kristiyan Kostadinov f2b1c1d3d7 fix(compiler): harden JIT against prototype pollution
Fixes a few places in the JIT compiler that were vulnerable against prototype pollution and code injection.
2026-10-12 16:09:57 -07:00
jhjh1214 8acf703db6 fix(compiler): do not scope comments placed inside of a selector
Comments are replaced with a placeholder before the styles are scoped. A
comment that is placed inside of a selector, e.g. `.a /* comment */ {}` or
`.a, /* comment */ .b {}`, ended up as its own selector part and got the
content attribute appended, which changed what the rule matches (e.g.
`.a[c] [c] {}` and `.a[c], [c] .b[c] {}`).

Parts that only consist of comment placeholders are now left untouched.
2026-10-12 16:08:52 -07:00
vslipchenko f1d1953fa8 fix(compiler): support dots in class binding names
Treat everything after the `class.` prefix as the class name, both in
template bindings and in `host` bindings. Previously the name was cut at
the next dot, so a binding like `[class.px-3.5]` silently applied `px-3`
instead of `px-3.5`. This made single class bindings unusable with class
names that contain a dot, which are common in Tailwind.
2026-10-12 16:06:16 -07:00