Commit graph

2328 commits

Author SHA1 Message Date
leonsenft
7c60a98b3c fix(compiler-cli): support import aliases in foreignImports (#68674)
Correctly matches and resolves foreign components when imported under an alias
name inside the component file.

PR Close #68674
2026-05-19 13:42:10 -07:00
leonsenft
d596d8bd0a refactor(compiler): support matching and validating foreign components in templates (#68674)
We extract the identifier name from the `foreignImports` expression in
`ComponentDecoratorHandler` and use a `SelectorlessMatcher` to match element
tags against these names. If an element matches both a regular Angular
directive and a foreign component, a conflict error is thrown.

In addition, we implement strict template semantic validation for these matched
foreign components within `TemplateSemanticsChecker`. Elements matched as
foreign components only support static attributes and property bindings. Any
event bindings, template references, or non-property input bindings (e.g.
class, style, or attribute bindings) trigger a semantic error diagnostic.

Finally, we skip standard DOM schema checks for foreign components to prevent spurious
validation errors since foreign components are not defined in standard HTML schemas.

PR Close #68674
2026-05-19 13:42:10 -07:00
Matthieu Riegler
872853fbcb docs(docs-infra): Show function args
With this change non-overloaded functions also show the params + return type in a dedicated block.
2026-05-18 13:22:28 -07:00
Leon Senft
88b0e420cf
refactor(compiler): add support for importing foreign components
- Added the ForeignComponent interface in @angular/core.
- Added Component.foreignImports for importing ForeignComponents (supporting direct references and adapter function wrappers).
- Updated the compiler to handle ForeignComponent in template dependencies.
- Updated ngtsc to extract foreignImports from standalone components.
2026-05-18 13:08:59 -07:00
Andrew Scott
13911b156b refactor(compiler-cli): Remove unused properties of IndexedComponent interface
These properties aren't used in the Kythe indexer and can be removed
2026-05-15 10:37:57 -07:00
Kristiyan Kostadinov
06f6dec7aa fix(compiler): type check invalid for loops
Currently if a `@for` loop doesn't have a `track` expression we don't produce an AST for it at all which means no type checking and language service support for it.

These changes make it so we produce the AST anyways since it gives the user more tools to resolve the issue (e.g. autocompletion when writing the `track` expression).
2026-05-13 11:26:42 -07:00
Matthew Beck
7ff4847e03 Revert "refactor(compiler-cli): drop @ts-ignore around fs.readFileSync"
Some checks are pending
DevInfra / assistant_to_the_branch_manager (push) Waiting to run
This reverts commit e0593ecc8b.
2026-05-12 15:20:55 -07:00
Kam
e0593ecc8b refactor(compiler-cli): drop @ts-ignore around fs.readFileSync
The `readFileBuffer` method in `node_js_file_system.ts` was wrapped in
`@ts-ignore` to suppress a TS2322 Buffer/Uint8Array typing error that
was fixed in the TypeScript 5.9.2 upgrade. The minimum supported
TypeScript is now 6.0, so the suppression is dead.
2026-05-12 13:21:53 -07:00
Kam
e661f4d255 refactor(compiler-cli): replace forEach with for...of in entry_point
Convert four `.forEach()` calls in `private_export_checker.ts` and
`reference_graph.ts` to `for...of`, matching the iteration style used
elsewhere in the compiler. The TODOs that forced these workarounds are
obsolete.
2026-05-11 18:29:04 -07:00
Kam
7a146238ba refactor(compiler-cli): drop @ts-ignore around jsDocParsingMode
The getters and setters for jsDocParsingMode in `host.ts` and
`ts_create_program_driver.ts` were suppressed with @ts-ignore to
support TypeScript 5.2, which lacked the property on `ts.CompilerHost`.
The minimum supported TypeScript is now 6.0, and `jsDocParsingMode`
is part of the public TypeScript API, so the suppressions can go.
2026-05-11 12:40:25 -07:00
Matthieu Riegler
7360c1da68 docs(docs-infra): improve api docs extraction
This allows us to show the API docs when the jsdoc block is at the top of a overloaded function (and not on the implementation signature).

eg: `injectAsync`
2026-05-11 12:03:39 -07:00
SkyZeroZx
307723a352 docs: add documentation for de-duplicate host directives 2026-05-07 17:53:42 -06:00
Matthieu Riegler
a7dab601fa refactor(core): use the @Service decorator where possible.
A few bytes to win.
Added only on the services that don't rely on constructor DI.
2026-05-07 17:03:30 -06:00
Andrew Scott
932a163cb6 refactor(compiler-cli): fix path normalization and trailing comments (#68454)
Ensure paths are normalized before comparison and key generation in tcb_adapter.ts to avoid failures on Windows.
Ensure a newline before appending imports in TypeCheckFile.render to prevent trailing comments from neutralizing them.

PR Close #68454
2026-05-07 15:42:33 -07:00
Andrew Scott
4f9c824dd9 feat(language-service): Typecheck templates which would require inline typecheck blocks (#68454)
This change updates the language service to generate TCBs for templates that would previously
have required inlining. The new strategy is to copy the original source and then do inlining
in the external TCB. This allows language features and type-checking in templates of non-exported
classes (such as test components) or classes with local, non exported dependencies.

PR Close #68454
2026-05-07 15:42:33 -07:00
Andrew Scott
7f0265e43a feat(language-service): compile non-exported classes if standalone (#68454)
Langauge service previously never compiled non-exported classes. This avoided issues
where test modules would cause diagnostic noise due to components appearing in
declarations of two modules, for example. This change updates the logic to ensure
non-exported, but standalone classes _are_ still compiled.

fixes #65515

PR Close #68454
2026-05-07 15:42:32 -07:00
Alan Agius
5b421c61cd
fix(core): disallow event attribute bindings in host bindings unconditionally
Moves the event attribute validation check outside of `ngDevMode` in the `elementAttributeInternal` instruction to ensure that bindings to event attributes like `on*` are always blocked at runtime.
2026-05-07 16:19:22 -06:00
Andrew Scott
bc655d006f refactor(compiler): Update indexer API to be generic
Rather than requiring TS AST in the indexer API, this update makes it generic with adapters to provide necessary information. This allows other analysis pipelines that don't use TS AST to work with the indexer.
2026-05-07 16:16:59 -06:00
Kristiyan Kostadinov
b225a5d902 fix(compiler): invalid type checking code if field name needs to be quoted
Fixes that we were producing invalid TypeScript if an input with an unsafe name (e.g. `aria-label`) is coerced.
2026-05-05 09:34:26 -07:00
Alex Rickabaugh
a4145dea06 Revert "fix(language-service): Add support for @Input with transforms"
This reverts commit dc9c72da9b. Reason: breaking
targets in g3.
2026-05-01 11:05:56 -07:00
Matthieu Riegler
dc9c72da9b fix(language-service): Add support for @Input with transforms
Prior to this change @Input with transforms were not linked by language service and you couldn't navigate on it.
2026-04-30 15:51:48 -07:00
Andrew Scott
2eae497a04 feat(compiler-cli): support external TCBs with copied content in specific mode
This change adds a new  that allows environments that cannot support inline TCBs (such as the language service or source-to-source transforms where TS compilation and emit are downstream) to still perform template type checking.

    Instead of inlining the TCB into the original source file when non-exported symbols are referenced, we now copy the file content to the .ngtypecheck.ts shim file and generate the external TCB there, if requested by the inlining mode. This preserves the local scope of the original file while keeping the original file unmodified.
2026-04-29 16:08:33 -07:00
Andrew Scott
c70625e806 refactor(compiler-cli): remove reflectionhost from environment
all necessary info is already available in the tcb meta objects. environments without full ts program no longer need a reflectionhost for tcb generation
2026-04-29 13:36:21 -07:00
Matthieu Riegler
37ec63e745 refactor(compiler): introduce default constant for legacyOptionalChaining flag
This will help patch the value in G3 to help land this change.
2026-04-29 10:01:13 -07:00
Matthieu Riegler
2896c93cc1
feat(compiler): Angular expressions with optional chaining returns undefined
To mitigate this breaking change,  this behavior can be disabled by wrapping expressions with the `$null` magic function.
: `$null(foo?.bar?.baz)`
2026-04-28 15:26:53 -07:00
Kristiyan Kostadinov
72be5be9c1 refactor(compiler-cli): remove checkTwoWayBoundEvents flag
Removes the `checkTwoWayBoundEvents` flag since the code it generates is quite breaking and we never got the chance to enable it. Also it caused our tests to misrepresent how the compiler behaves for actual users.
2026-04-28 10:31:42 -07:00
Kristiyan Kostadinov
6bd1721662 fix(compiler): let declaration span not including end character
Fixes that the span for `@let` declarations didn't include the end token.
2026-04-27 17:09:14 -07:00
SkyZeroZx
70c011e879 refactor(compiler): Removes unused compiler utility functions
Remove helper functions and constants across the compiler, as they are no longer required by current logic.
2026-04-27 17:00:44 -07:00
Matthieu Riegler
b2083a7fd2 build: cleanup workspace deps
Some of the deps are move down to the only targets that uses them.
2026-04-23 11:38:26 -07:00
Suraj Yadav
2c141c04cb refactor(compiler-cli): simplify Angular decorator stripping
Removes redundant decorator-stripping branches and consolidates
the transformation flow to reduce complexity and improve readability.
2026-04-22 11:07:35 -07:00
Kristiyan Kostadinov
8f3d0b9d97 feat(core): introduce @Service decorator
These changes introduce the new `@Service` decorator which is a more ergonomic alternative to `@Injectable`. The reason we're adding a new decorator is that `@Injectable` has been around since the beginning of Angular and it has a lot of baggage that adds unnecessary overhead for users that generally want to define a singleton service, available in their entire app. The key differences between `@Service` and `@Injectable` are:
1. `@Service` is `providedIn: 'root'` by default. You can opt into providing the service yourself by setting `autoProvided: false` on it.
2. `@Service` doesn't allow constructor-based injection, only the `inject` function.
3. `@Service` doesn't support the complex type signature of `@Injectable` (`useClass`, `useValue` etc.). Instead it supports a single `factory` function.

Example:

```ts
import {Service} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {AuthService} from './auth';

@Service()
export class PostService {
  private readonly httpClient = inject(HttpClient);
  private readonly authService = inject(AuthService);

  getUserPosts() {
    return this.httpClient.get('/api/posts/' + this.authService.userId);
  }
}
```
2026-04-22 11:01:01 -07:00
Kristiyan Kostadinov
7fa274510f refactor(compiler): move TCB generation logic into compiler
Moves the logic for generating type check blocks into the compiler since it isn't coupled to TypeScript anymore.

Note: the tests haven't been moved over, because they depend on the environment that's currently in `compiler-cli` and it still has some dependencies on TypeScript.
2026-04-15 19:43:29 +03:00
Andrew Scott
c2f4b2af7c refactor(compiler-cli): decouple SymbolReference from AST nodes in template checker
To support the need to resolve symbols without full AST access (e.g. when using virtual files), this commit decouples `ReferenceSymbol` from `ts.ClassDeclaration`.

Changes:
- Updated `ReferenceSymbol.target` to use `SymbolReference` instead of `ts.ClassDeclaration`.
- Removed `getReferenceTargetNode()` from `SymbolDirectiveMeta` and transitioned to `getSymbolReference()`.
- Refactored `getTsSymbolOfReference` in `checker.ts` to handle `SymbolReference` and resolve it to a `ts.Symbol` using a position-optimized AST traversal. This avoids using the private `getTokenAtPosition` API and avoids full file scans by only traversing nodes containing the target position.
2026-04-14 12:32:48 +03:00
Kristiyan Kostadinov
e5f96c2d88 fix(compiler-cli): animation events not type checked properly when bound through HostListener decorator
Fixes that we weren't inferring the type of `animate.` event correctly, if they're bound through a `@HostListener` decorator.
2026-04-13 11:05:16 +03:00
Kristiyan Kostadinov
65bf054ee4 refactor(compiler-cli): fix typo
Fixes a typo in the name of `OutOfBandDiagnosticCategory`.
2026-04-13 11:05:16 +03:00
Matthieu Riegler
47fcbc4704 feat(compiler): allow safe navigation to correctly narrow down nullables
The commit updates the TCB for safe navigation expressions to allow for correct narrowing of nullables.

This will trigger the `nullishCoalescingNotNullable` and `optionalChainNotNullable` diagnostics on exisiting projects.
You might want to disable those 2 diagnotiscs in your `tsconfig` temporarily if you want to update your project without having to fix all the issues at once.

Narrowing can be disabled altogether with `strictSafeNavigationTyes: false`.

fixes #37619

BREAKING CHANGE: This change will trigger the `nullishCoalescingNotNullable` and `optionalChainNotNullable` diagnostics on exisiting projects.
You might want to disable those 2 diagnotiscs in your `tsconfig` temporarily.
2026-04-09 18:26:08 +03:00
Andrew Scott
6fee6514c2 refactor(compiler-cli): decouple SymbolBuilder from BoundTarget and minimize adapter surface
Decouple `SymbolBuilder` from the full `BoundTarget` interface by introducing a purpose-built `SymbolBoundTarget` interface containing only the 4 methods required for symbol resolution. This eliminates the need for the large, pass-through `BoundTargetAdapter` and further isolates `SymbolBuilder` from compiler-internal implementation details.

Also minimize `TypeCheckableDirectiveMetaAdapter` by redefining `SymbolDirectiveMeta` to not extend `DirectiveMeta`, exposing only the properties actually used by `SymbolBuilder`.

Removed dead code `getDirectiveMeta` in `template_symbol_builder.ts` which was unused.

These changes improve maintainability and ensure a cleaner architecture by strictly defining the boundaries of what `SymbolBuilder` needs from the rest of the system.
By limiting the required inputs to only what's necessary for the implementation, we make it easier to re-use
the implementation between different compiler architectures
2026-04-08 11:33:41 -07:00
Andrew Scott
30c950f133 refactor(compiler-cli): Fix regressions caused by ts.typechecker removal
removing ts.typechecker in a prior refactor caused some regressions, particularly when multiple directives
appear on a single elemnt. this is now addressed by using an id for directives and storing that in the tcb comment
2026-04-08 08:14:44 -07:00
Kristiyan Kostadinov
ab061a7610 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.
2026-04-07 09:29:29 -07:00
Andrew Scott
9218140348 fix(compiler-cli): resolve TCB mapping failure for safe property reads with as any
- Fixes TemplateSymbolBuilder.getTcbPositionForNode to recursively unwrap AsExpression and NonNullExpression nodes.
- Added a test case in type_checker__get_symbol_of_template_node_spec.ts to verify symbol mapping when strictSafeNavigationTypes is false.
- Note: The issue likely broke in commit 13c8df67d9.
2026-04-06 13:16:19 -07:00
Matthieu Riegler
f3c471e0d5 refactor(compiler): remove fullTemplateTypeCheck compiler option.
The option was deprecated back in v13. Users should use `strictTemplates: true`.
2026-04-06 11:55:09 -07:00
Andrew Scott
13c8df67d9 refactor(compiler-cli): decouple TemplateSymbolBuilder from ts.TypeChecker
This updates the SymbolBuilder to no longer use ts.TypeChecker internally to
build symbols for the language service. These lookups are deferred/done later
using the newly expanded template type checker API.
2026-04-06 10:55:40 -07:00
Andrew Scott
5600c4fbd9 refactor(compiler-cli): tag host directives in TCB
Add HOST_DIRECTIVE expression identifier to TCB comments to identify host directives.
2026-04-06 10:55:40 -07:00
Kristiyan Kostadinov
57432f1b6a refactor(compiler-cli): merge duplicate directive matches and report conflicts
Implements the logic at the compiler level that will de-duplicate host directives and merge them together. It will also report if a conflict is detected during merging.
2026-04-03 09:44:39 -07:00
Kristiyan Kostadinov
22f9ee1be6 refactor(compiler): require a reference in DirectiveMeta
Requires the `DirectiveMeta` to have a `ref` so that we can find duplicates easily.
2026-04-03 09:44:39 -07:00
Kristiyan Kostadinov
d15ceff617 refactor(compiler-cli): move ClassPropertyMapping into compiler
Moves the `ClassPropertyMapping` into the compiler, rather than having to pass around the limited `InputOutputPropertySet` interface that is only implemented by `ClassPropertyMapping`.
2026-04-03 09:44:39 -07:00
Kristiyan Kostadinov
927ae3abc8 refactor(compiler): move matchSource into base metadata
Moves the `matchSource` into the base metadata so the binder can use it.
2026-04-03 09:44:39 -07:00
Kristiyan Kostadinov
4651b93a92 refactor(compiler-cli): pre-compute key
Updates the TCB metadata to pre-compute and store the `TcbReferenceKey`, instead of computing it on the fly.
2026-04-03 09:44:39 -07:00
Kristiyan Kostadinov
8fe025f514 feat(core): drop support for TypeScript 5.9
Drops support for TypeScript 5.9.

BREAKING CHANGE:
* TypeScript versions older than 6.0 are no longer supported.
2026-04-03 09:44:11 -07:00
SkyZeroZx
7f9450219f feat(compiler-cli): Adds warning for prefetch without main defer trigger
Emit a warning when an `@defer` block uses `prefetch` triggers but does not define an explicit main trigger.

Closes #52746
2026-04-02 12:21:09 -07:00