257 Commits
Author SHA1 Message Date
Kristiyan Kostadinov e11dea88b9 fix(compiler-cli): handle typeof when analyzing imports in preprocessor
When TS emits re-exported `as const` arrays in .d.ts, it may emit something like `typeof import('...').Foo` for elements that aren't directly imported in the file. These changes update the preprocessor to resolve them correctly.

(cherry picked from commit 3492295b9a)
2026-11-23 12:31:20 +01:00
Angular Robot 597b3ecd50 build: update dependency @angular/compiler to v22.3.0
See associated pull request for more information.
2026-11-18 12:39:53 -08:00
Andrew Scott b64e8b591e refactor(compiler-cli): attribute NgModule scope queries in perf summaries
In normal perf tracing mode, `ngp.rust.Summary` records top-5 `slowest` entries with `file` paths read from each query span's `file` field. That field was populated from `QueryKey::file_id()`, which returns `None` for `NgModuleExportsScope(ReferenceId)` and `NgModuleImportsScope(ReferenceId)`, leaving their `slowest` entries without file paths unless detail mode was enabled.

Add `QueryKey::perf_file_id()` to return `Some(reference_id.file)` for NgModule scope queries as well, and use it in `QueryEngine::execute` when creating the perf span. Keeping `QueryKey::file_id()` unchanged avoids marking NgModule files dirty or emitting them in `invalidatedPaths` when a downstream dependent evicts a cached scope key.

(cherry picked from commit 7b50ce3be2)
2026-11-18 18:11:41 +00:00
Andrew Scott b25324303f refactor(compiler-cli): support go-to-definition for templateUrl and styleUrls
Add getDefinitionForExpressionAtPosition in the preprocessor language service DefinitionBuilder, matching the ngtsc language service structure, to resolve component templateUrl and styleUrls string literals to their target files.

(cherry picked from commit a9d35bad83)
2026-11-18 18:11:22 +00:00
Andrew Scott fb91797c0f refactor(compiler-cli): skip redundant didChange notifications in TsGoFacade
Cache the last sent document content in TsGoFacade.ensureDocument and skip sending textDocument/didChange when the content is unchanged, avoiding unnecessary cancellation of concurrent in-flight TypeScript 7 language server requests.

(cherry picked from commit b208470321)
2026-11-18 18:11:22 +00:00
Andrew Scott eb57119515 refactor(compiler-cli): configure VS Code extension host launch for ngp language service
Add VS Code launch and task configurations for launching and debugging the ngp-vscode-ng-language-service extension host in the monorepo, and fix build and runtime resolution issues when running outside Bazel:

- Add 'NGP VSCE: Launch Dev Client' and compound attach configs in .vscode/launch.json and 'NGP VSCE: build' task in .vscode/tasks.json.
- Update ngp-vscode-ng-language-service/build.js to use server/esbuild-tsconfig.json, mark @typescript/native-preview external, and define import.meta.url via banner.
- Update ngp-vscode-ng-language-service/tsconfig.json for TypeScript 7 compatibility (remove baseUrl, use relative paths, and specify node types).
- Resolve platform tsc/tsgo binary via createRequire from @typescript/native-preview/package.json so pnpm workspace layouts work, and await clientReady before sending angular/setTsApiPipe from fallback ts7Client.
- Allow analyzer_loader.ts to locate ng_analyze_wasm.js when walking up from a realpath'd bundle inside bazel-out.

(cherry picked from commit 6d49c19e22)
2026-11-18 18:11:22 +00:00
Andrew Scott 48c7c0dcde build(compiler-cli): update TypeScript 7 language service dependency to 7.1.0-dev
Upgrades the TypeScript 7 dependency in the preprocessor language service
and VS Code extension from the frozen @typescript/[email protected]
package to npm:[email protected], updates binary lookup for
@typescript/typescript-<platform>-<arch> (tsc), updates subpath imports from
/unstable/async to /async, and replaces api.updateSnapshot() with
api.getCurrentLanguageServerSnapshot().

(cherry picked from commit f442d775f0)
2026-11-18 18:11:22 +00:00
Andrew Scott 1ae2753b20 refactor(compiler-cli): skip module_export_map walks when strategy ignores owning references
`propagate_owning_reference_validated` and `resolve_host_directive` resolve a
package entry point and compute its `ModuleExportMap` so declarations and host
directives in `.d.ts` files inherit the package's published specifier and
export name. Under `PrefixImportStrategy`, `uses_owning_reference()` is `false`
and `emit` always derives module specifiers and export names directly from each
symbol's declaring file, ignoring `owning_reference` (matching `ngtsc` omitting
`AbsoluteModuleStrategy` when `_useHostForImportGeneration` is enabled).

(cherry picked from commit b2b4b1755c)
2026-11-16 22:42:01 +00:00
SkyZeroZx cb7b7a4d75 fix(compiler-cli): avoid repeating the error code in preprocessor extended diagnostics
The preprocessor's copy of formatExtendedError also prefixed the message with its own error code. It now matches ngtsc and only carries the text and the documentation link.

(cherry picked from commit e4807c3c0c)
2026-11-14 00:22:32 +00:00
Charles Lyding 749cc3f5b5 refactor(compiler-cli): cache module resolutions and track unresolved imports in preprocessor
Previously, `QueryEngine` invoked `AnalysisHost::resolve` directly on every
syntactic dependency scan, cross-file constant evaluation, export-map walk,
and NgModule scope traversal without an engine-level cache. For asynchronous
bundler hosts, repeating identical `(importer, specifier, kind, type_only,
attributes)` lookups across queries and rebuilds would generate redundant
cross-boundary round-trips. In addition, failed module resolutions only
recorded `UNRESOLVED_IMPORTS_FILE_ID` during the Stage-1 static dependency
scan of `.ts` sources. That scan does not resolve the specifiers of `.d.ts`
files, so a failed lookup made from one, such as a re-export to a missing
target, was untracked and not re-run when the target was later created.
Deleting a resolved file also left importers holding stale cached dependency
edges.

Introduce `ResolutionCache` on `QueryEngine` to memoize completed module
resolution outcomes per importer `FileId` and request key while maintaining
both a target-to-importer reverse index and an unresolved-importer index.
Route query-time module lookups through `QueryContext::resolve_request`,
`resolve_from_id`, and `resolve_from_path` so every resolution records the
importer dependency and every failed lookup—including negative cache hits—
records `UNRESOLVED_IMPORTS_FILE_ID`. Classify pure re-exports in
`analyze_file_syntax` with `ImportKind::ReExport` so syntactic dependency
discovery shares cached resolutions with cross-file evaluation and export-map
queries.

On `invalidate_file_id`, drop only the edited importer's cached resolutions
so edits to a leaf module preserve cached resolutions across its importers.
On `FileUpdateType::Deleted`, evict queries derived from importers that had
resolved to the deleted target while keeping their `ParseFile` results
cached. On `invalidate_module_resolution`, stop serving every cached
resolution and re-run importers with previously unresolved specifiers. The
superseded entries are kept as stale rather than dropped, so the reverse
index still covers importers whose queries stay cached and that therefore do
not resolve again, and a lookup that the host answers after the change is
not memoized.

When a host resolution changes a module's `IdKind`, also evict the importers
whose cached resolutions report the previous kind. The resolution that
changed the kind is not memoized, so the query re-run that follows asks the
host again.

(cherry picked from commit 8ee9520035)
2026-11-14 00:02:33 +00:00
Kristiyan Kostadinov ed1544b151 refactor(compiler-cli): remove unused serving infrastructure from preprocessor
We had some code we used earlier to check apps against the preprocessor. These changes clean it up since it's not used anymore and it includes dependencies on TypeScript and esbuild.

(cherry picked from commit 8be02a66d3)
2026-11-12 10:35:41 +01:00
Angular Robot 4fb7a11995 build: update dependency @angular/compiler to v22.3.0-rc.0
See associated pull request for more information.
2026-11-11 17:02:06 -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
aparziale 08d41a9e94 fix(compiler-cli): suggest ngProjectAs in control flow content projection diagnostic
Previously, the NG8011 diagnostic suggested wrapping the content of the control
flow block in an `<ng-container/>` that matches the slot selector. This
suggestion is misleading: for element selectors (e.g. `select="my-title"`) a
plain `<ng-container>` can never match the slot, and the actual solution,
`ngProjectAs`, was never mentioned.

The suggestion now shows the exact `<ng-container ngProjectAs="...">` usage for
the matched slot selector and clarifies when to use it versus splitting the
content across multiple blocks, aligning the message with the NG8011 error page
on angular.dev.

Fixes #59398
2026-11-11 13:56:11 -08:00
Andrew Scott 94771961a6 refactor(compiler-cli): remove synchronous *Sync preprocessor APIs
Remove the synchronous *Sync methods and sync-only fallbacks from
HybridCompiler, IAnalyzer, DependencyTemplates, processor, indexer,
SidecarAnalyzer, WasmAnalyzer, and NapiAnalyzer.
2026-11-11 13:49:47 -08:00
Andrew Scott e1e0e3aa6e refactor(compiler-cli): migrate preprocessor language-service and tests to async APIs
Migrate preprocessor language-service, ngp-vscode-ng-language-service,
preprocessor tests, and ngp_test_driver to use the async HybridCompiler
and IAnalyzer methods instead of synchronous *Sync lookups.
2026-11-11 13:49:47 -08:00
Andrew Scott 05b3b6e87a refactor(compiler-cli): exclude output directories from hybrid preprocessor tsconfig globs
When a tsconfig has no `exclude` (including through `extends`), TypeScript skips `outDir` and `declarationDir` while expanding `include` globs. ng-analyze didn't, so emitted `.d.ts` and `.js` files inside the project could get picked up as sources.
2026-11-11 12:28:30 -08:00
Matthieu Riegler 37c1919831 refactor(compiler-cli): remove dependencies on deprecated webmcp packages
We don't need them any more.
2026-11-11 11:49:59 -08:00
Charles Lyding ba7d313030 refactor(compiler-cli): drop filesystem type parameter from preprocessor query engine
After routing module resolution, component resource resolution, and file
loading through `AnalysisHost`, the `Fs` type parameter on `QueryEngine`
and `QueryContext` no longer described any state the engine holds. It
survived only as a `PhantomData` marker, yet it still forced roughly a
hundred query, evaluator, analyzer, and compiler functions to carry a
`ResourceResolverFs + Clone + 'static` bound and kept the engine's types
tied to the filesystem implementation that hosts are meant to abstract
away.

Make `QueryEngine`, `QueryContext`, and the `QueryCtx` aliases concrete
types and remove the marker field, then drop the bound from every
function, method, and helper type that existed only to thread it
through, including the NgModule scope `ScopeEnv` and `Resolver`, the
streaming coordinator, and `DirtyFilesSnapshot`. The filesystem type now
appears only on the `new`, `new_with_options`, and `new_default`
constructors that wrap a filesystem and resolver in a `DefaultFsHost`, so
existing callers infer it as before, while `new_with_host` and
`new_default_with_host` accept any host directly. Tests that named
`QueryEngine<OverlayFileSystem>` now use the plain engine type, and
imports left unused by the removal are dropped.

Also reword the preprocessor contributor guideline on paths and module
resolution to describe the host boundary: analysis code resolves and
loads only through `AnalysisHost`, only host implementations touch a
filesystem or `oxc_resolver`, path arithmetic applies solely to
path-backed module IDs, and the TypeScript code-generation layer remains
a pure consumer of pre-resolved metadata. There is no change in
behavior.
2026-11-11 10:26:46 -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
Charles Lyding 1eba558934 refactor(compiler-cli): route preprocessor query engine I/O through AnalysisHost
Even with `AnalysisHost` and `DefaultFsHost` available, `QueryEngine`,
component resource loaders, and cross-file constant evaluation still held
a concrete filesystem and `oxc_resolver` instance and performed synchronous
file reads and specifier lookups directly. That prevented asynchronous,
filesystem-free bundler hosts from driving analysis and left synchronous
helper entry points able to bypass the host boundary.

Replace `fs` and `resolver` on `QueryEngine` with `Arc<dyn AnalysisHost>`,
retaining a temporary `PhantomData` marker for `Fs` so generic parameter
removal across query and evaluator signatures stays isolated to a separate
follow-up change. Existing constructors wrap `DefaultFsHost` to preserve
current behavior, while `new_with_host` and `new_default_with_host` allow
injecting custom asynchronous hosts directly.

Route file parsing, syntax-level static and dynamic dependency discovery,
ambient `.d.ts` scanning, local-compilation extra import checks, export-map
traversal, host-directive package resolution, and cross-file symbol chasing
through `AnalysisHost`, deleting the synchronous `resolve_specifier` helper
so future call sites cannot bypass the host. Convert Stage-1 and Stage-2
component `templateUrl` and `styleUrl` loading to asynchronous host calls
that concurrently resolve resources and static/dynamic module specifiers in
a single wave, fall back to `AnalysisHost::load` when inline resource text
is omitted, and exclude `external` modules from the program closure while
still reading their metadata on demand.

Ambient global lookups read the tsconfig's `.d.ts` files through the host
as well, so they become asynchronous, and the lock that serializes their
scan is now an async mutex, held across host loads without blocking a pool
thread.

When a host resolution reports a different `IdKind` for a module that is
already interned, the host still wins, but whatever was computed under the
previous kind is now evicted. Queries still running at that point are not
in the reverse index yet, so any that read the module re-run before
returning, letting every caller see a result computed under the current
kind. A host that keeps flipping a module's kind stops the re-runs after
three, and the last result is returned without being cached.
2026-11-11 08:36:46 -08:00
Andrew Scott b89e88eb8c refactor(compiler-cli): support incremental invalidation and dependency prefetch in sidecar mode
Update the preprocessor sidecar and incremental pipeline so persistent
builds can reuse HybridCompiler and SidecarAnalyzer across runs:

- Convert numeric FileUpdateType values to string enum variant names in
  SidecarAnalyzer.invalidateFiles to match ng-analyze's serde JSON
  representation (same as WasmAnalyzer) and preserve workspaceName in
  compilerOptions.
- Prefetch cross-file component dependency metadata and record it in
  HybridCompiler.metadataByFile before computing bound fingerprints in
  ensureBoundWithMetadata so sidecar mode can compute bound fingerprints
  without falling back to synchronous getMetadataForFileSync.
- Add HybridCompiler.applyInvalidations and cache reused source maps
  across persistent run() invocations in ngp.ts.
2026-11-11 08:25:33 -08:00
Kristiyan Kostadinov 50142d36f3 refactor(compiler-cli): remove remaining references to ngtsc in preprocessor
Removes the last remaining imports of `@angular/compiler-cli` from the preprocessor.
2026-11-11 16:01:26 +01:00
Kristiyan Kostadinov 8c103c6302 refactor(compiler-cli): don't depend on ngtsc for error codes
Now that the error codes source of truth is within the preprocessor, we don't need to depend on ngtsc for it.
2026-11-11 11:00:51 +01:00
Matthew Beck d3dedf53e4 fix(compiler-cli): avoid names used in the file for generated namespace imports in ngp
ngtsc's `ImportManager` names the `n`th generated namespace import `i<n>` and
passes it through the helper from `createGenerateUniqueIdentifierHelper`
(`translator/src/import_manager/check_unique_identifier_name.ts`), which moves it
to `i<n>_1`, `i<n>_2`, ... while the name is in the source file's `identifiers`
table or was already generated. TypeScript's parser fills that table with the
text of every identifier token, at any depth (`internIdentifier` in `parser.ts`).
So a nested arrow parameter `i0` moves the `@angular/core` import to `i0_1` in
both the JS and the `.d.ts`.

ngp always used `i0`, `i1`, ..., which gave different output and, for a
top-level `const i0`, a compile error because the generated references resolved
to the user's binding.

The analyzer now applies ngtsc's rule restricted to bindings
(`analyzer::imports::namespace_alias_conflicts`): the name of every symbol in
oxc's symbol table, at any depth and in any space, and of every reference that
resolves to no declaration (a global), keeping those shaped like a generated
alias. These are all the names a generated reference could resolve to instead
of the import, and reading them takes about 3% of the time a walk over every
AST node does. Generated imports only come with a compiled class, so a file
without one skips the check. The names are reported as
`AnalysisResult.namespaceAliasConflicts`, and both `ExpressionPrinter` and
`TcbImportManager` (via `generateTcbCode` when `requiresInline` is `true`, for
inline `.ngtypecheck.ts` files in `processor.ts` and `hybrid_compiler.ts`) apply
the same `allocateNamespaceAlias` helper against them so the `.ng.ts` (and from
it both JS and `.d.ts`) and inline TCBs avoid colliding with the file.

Names in the `identifiers` table that aren't bindings don't count: property and
member names, labels, JSX tag and attribute names, the foreign name in an import
or export specifier, index signature parameter names, string literals used as a
property name, element-access argument or module name, and identifiers in JSDoc.
None of them can capture a generated reference, so the output compiles, but for
them ngtsc picks a different name in both the JS and the `.d.ts`. They're listed
as a `TODO(parity)`.

ngp also reused a namespace import already in the file whose alias looked like a
generated one. ngtsc never reuses an existing import for generated code: both its
Ivy and declaration transforms use `presetImportManagerForceNamespaceImports`
(`disableOriginalSourceFileReuse: true`, `transform/src/transform.ts` and
`transform/src/declaration.ts`). That reuse is removed, so a user-written
`import * as i0 from '@angular/core'` now gets a separate `i0_1` import, as in
ngtsc.
2026-11-11 10:16:57 +01:00
Matthew Beck 7932b39528 test(compiler-cli): cover generated namespace import names that collide with the file
ngtsc names the namespace imports it generates `i0`, `i1`, ... and moves one to
`i0_1` when the source file already uses the name anywhere, including a nested
parameter. It also never reuses an import the file already has, even a namespace
import named like its own.

The `namespace_alias_collisions` golden case pins the generated names for a
top-level declaration, a nested arrow parameter, user-written namespace imports
named `i0` and `i1`, and a name used only as a property name. A golden's `.ng.ts`
is what both the JS and the `.d.ts` are compiled from, so it pins the names in
both.

ngp always emits `i0`/`i1` and reuses a user-written `i0`/`i1` namespace import,
so the golden holds the plain or reused names. For the top-level `const i0` the
output doesn't type-check, which `typecheck_goldens_spec.ts` lists as a known
failure.
2026-11-11 10:16:57 +01:00
Charles Lyding ca6e15c640 refactor(compiler-cli): introduce preprocessor analysis host trait and module ID interning
To let bundlers supply module resolutions, component resources, and file
contents asynchronously without exposing a filesystem to `ng-analyze`,
the query engine needs an abstract host boundary and a module identifier
representation that does not treat every ID as a filesystem path. Bundler
virtual module IDs (such as `\0`-prefixed Rollup IDs, Vite `/@id/...`
specifiers, or query-suffixed IDs) look like or contain path-like
segments that would be corrupted by structural path normalization or
platform case-folding.

Introduce the `host` module in `ng-analyze` defining `ModuleId`,
`IdKind` (`Path` vs `Virtual`), `ModuleFormat`, request/response records,
and the `AnalysisHost` trait for asynchronous `resolve`, `load`, and
`resolve_resource` operations. Provide `DefaultFsHost<Fs>` over
`oxc_resolver` and `ResourceResolverFs` as the synchronous filesystem
implementation that resolves futures immediately on first poll, maps
`rootDirs` paths to their backing files, canonicalizes resolved paths,
and delegates component resource loading to `ResourceResolver`.

Extend `FileIdInterner` to store `(ModuleId, IdKind)` alongside each
`FileId`. Apply structural normalization and case-insensitive key
folding exclusively to `IdKind::Path` entries while storing and matching
`IdKind::Virtual` entries verbatim, and allow authoritative host
resolutions to override a previously defaulted `IdKind` on the same
`FileId`, reporting the previous kind so the query engine can invalidate
results computed under it, while keeping existing path-based callers
unchanged.

`ModuleFormat::is_dts`, `ModuleFormat::is_compilation_root`, and
`FileIdInterner::get_module_if_interned` have no callers yet. Follow-up
changes use them when format detection moves to the host and the
invalidation APIs accept an `idKind`.
2026-11-10 11:09:16 -08:00
Angular Robot 24622b7a87 build: update cross-repo angular dependencies
See associated pull request for more information.
2026-11-10 10:56:36 -08:00
Andrew Scott c877d9baf1 refactor(compiler-cli): parse template diagNodes lazily and skip unused devmode TCB binding
parseComponentTemplate previously ran the template parser twice on every
component template: once with parseOptions for runtime code generation
and eagerly a second time with diagParseOptions for TCB generation,
diagnostics, and indexing. In devmode, emitDeclarationOnly, and
cross-file DependencyTemplates lookups (which only inspect
ngContentSelectors), diagNodes is never read, so the second parse was
wasted work.

This change makes diagNodes a lazy memoized getter on
ParsedComponentTemplate so the second parse only runs when diagNodes is
actually accessed. It also skips ensureBoundWithMetadata in
HybridCompiler.prepareChunk and prepareChunkSync for single-file
devmode chunks and emitDeclarationOnly builds (populating
preparedTcbData on demand in the indexer and language service when
needed), skips re-running adaptTcbInput in prepareTcbTargets Pass 2 for
targets that were already adapted with requiresInline in Pass 1, and
reuses cached source text from compiler.fileCache in ngp.ts.
2026-11-10 10:50:08 -08:00