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
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]>
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.
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.
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.
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.
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
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`.
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.
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.
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.
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.
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.
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.
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
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.
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.
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`.
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
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`.
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
`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.
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.
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.