146 Commits
Author SHA1 Message Date
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
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
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
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
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
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
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
Matthew Beck 670c17232b fix(compiler-cli): never drop hostDirectives entries in local compilation
In local and declaration-only compilation, ngtsc's `extractHostDirectives`
keeps every `hostDirectives` entry or reports it. ng-analyze dropped entries
silently: an undeclared identifier, a string, or an entry it couldn't
evaluate disappeared from the emitted metadata, and an entry that depended on
another file (an imported array, a spread, a conditional, or an `inputs`
mapping) dropped the whole `hostDirectives` field.

Extract `hostDirectives` the way ngtsc does under `CompilationMode.LOCAL`:

- Without `emitDeclarationOnly`, `hostDirectives` is evaluated across the
  compilation unit, so those cross-file entries resolve. Under
  `emitDeclarationOnly`, only ambient `.d.ts` globals fold.
- An entry that is still dynamic is emitted verbatim when its array element
  is an identifier or property access, and reports NG11003 otherwise. An
  entry flagged as an unsupported expression stays flagged unless it folds to
  a concrete value, since ngtsc re-anchors a dynamic value on the outermost
  expression it evaluated.
- A non-array value or a non-reference entry reports NG1010, and an inputs or
  outputs mapping that isn't an array yields no mapping rather than dropping
  the entry.
2026-11-09 19:56:19 +01:00
Andrew Scott f513487c41 refactor(compiler-cli): add perf tracing to the preprocessor and ng-analyze
Adds opt-in performance tracing to the preprocessor CLI and the Rust
ng-analyze sidecar, controlled by three new flags:
2026-11-09 19:54:32 +01:00
Charles Lyding dfb491ba19 refactor(compiler-cli): detect @angular/core compilations like ngtsc in the preprocessor
The preprocessor recognized `@angular/core` by walking up to the nearest
`package.json` named `@angular/core`, which ngtsc never does and which a
host without file system access cannot do. Follow ngtsc's rule instead:
the internal `angularCoreCompilation` option, falling back to the
tsconfig's `_isAngularCoreCompilation`, then to an explicit
`r3SymbolsFile`, and otherwise to whether the root `r3_symbols.ts`
exports `ITS_JUST_ANGULAR = true` (ngtsc's `isAngularCorePackage`).

The `ITS_JUST_ANGULAR` check reads `r3_symbols.ts` through the query
engine, so edits to it invalidate dependent analyses. A new
pseudo-dependency on the `r3_symbols.ts` root lookup re-runs only the
queries that read it when the roots add or remove that file, instead of
every query on each root change.

Also remove the unused `resolve_to_dts` helper.
2026-11-09 09:58:13 -08:00
Matthew Beck 5ac4cf7b54 fix(compiler-cli): resolve ambient global values declared in tsconfig .d.ts files
In ngtsc, an unbound identifier in Angular decorator metadata resolves
through TypeScript's global scope like any other value. An example is
Closure's `COMPILED`, declared by `declare var COMPILED: boolean` in a
`.d.ts` file listed in `tsconfig.json` `files`. ng-analyze only indexed the
`declare module` blocks in those files and treated these identifiers as
unknown. Full compilation fell back to emitting the unevaluated expression
(e.g. into `ɵɵsetNgModuleScope`), and fields that must be static reported
NG1010 (NG11001 in local compilation).

Index the ambient global values that the tsconfig's `.d.ts` files declare
(top-level declarations in script `.d.ts` files and `declare global`
blocks), and resolve unbound value identifiers against them:

- The index parses each `.d.ts` file into a recycled allocator, without
  semantic analysis or caching its parse, and treats a file as a module the
  way TypeScript does (`import x = require()` makes it a module;
  `export as namespace` alone doesn't).
- An unbound value identifier becomes an `AmbientGlobal` hole. Only the
  candidate `.d.ts` files are parsed, the name must be a value in the script
  scope or a `declare global` block, and the declaration is evaluated as
  ngtsc does: `declare var COMPILED: boolean` is a reference and
  `declare const ENV: 'prod'` is `'prod'`. References get the consumer's
  local name, so emitted code uses the bare global rather than importing
  the `.d.ts`.
- In local and declaration-only compilation, `host`, `@Input`/`@Output`
  metadata, and query predicates complete ambient globals while keeping
  cross-file import holes. Ambient globals that no `.d.ts` declares are
  demoted before validation, so they still report NG1010/NG11001.
- A declared variable whose type annotation is still pending falls back to
  a reference, as in ngtsc's `visitVariableDeclaration`.

The `ngmodule_imports_spread_dynamic_entry` golden now uses a call to a
declared function instead of an ambient boolean constant. The constant now
evaluates statically (as in ngtsc), and the golden exists to cover a spread
entry that can't be evaluated statically.
2026-11-06 07:33:00 +01:00
Matthew Beck 8f6fd2bdf3 fix(compiler-cli): hoist import x = … declarations like ngtsc's ImportManager
ngtsc's `ImportManager` rebuilds every file it adds imports to as the file's
existing import statements, then the generated imports, then the rest of the
file. Its `isImportStatement` counts `import X = …` (and `export import X = …`)
as an import statement, so ngtsc moves those to the top of the file along with
any `import` declarations written further down. ngp only hoisted `import`
declarations and left `import X = …` where it was. When code earlier in the
file reads the alias while the module loads, such as a `providers` entry that
ngtsc compiles into the component definition, ngtsc's output works and ngp's
throws.

Collect the top-level `import X = …` statements and hoist them together with
the late `import` declarations, in source order. Like ngtsc, only hoist in a
file that gets generated imports: one with a compiled class. ngtsc leaves a
file whose classes are all `jit: true` untouched, while ngp still adds an
`@angular/core` import there, so ngp no longer hoists late `import`
declarations in such a file either.

This changes runtime behavior in both directions, each time to match ngtsc.
Code that reads an `import X = …` alias before the line it's written on now
loads instead of throwing. An `import X = Local.Y` that follows
`namespace Local {}` now moves above the namespace and reads `undefined.Y` at
runtime, as it does with ngtsc; the `imports_equals_and_non_angular_hoisting`
golden records that.
2026-11-06 07:31:10 +01:00
Kristiyan Kostadinov dd3eb346c7 fix(compiler-cli): skip fingerprinting when incremental compilation is disabled
Fixes that we were fingerprinting files when incremental compilation is disabled which is unncessary work.
2026-11-06 07:28:33 +01:00
Kristiyan Kostadinov 6c21e65fe0 fix(compiler-cli): skip outputs for unchanged files in preprocessor
The preprocessor was writing out `.ng.ts`, `.ng.ts.map` and `.ngtypecheck.ts` files for files that weren't modified.
2026-11-05 20:40:30 +01:00
Kristiyan Kostadinov 73911c88ca fix(compiler-cli): fix json parsing error in sidecar
The JSON stream in the sidecar was breaking if a template uses `U+2028` or `U+2029` in the source code.
2026-11-05 16:15:09 +01:00
Kristiyan Kostadinov 7d2330e459 fix(compiler-cli): handle generic expressions in queries
Fixes that we were producing code that was triggering a compilation error when a query uses a generic expression (e.g. `read: TemplateRef<Foo<T>>`).
2026-11-05 16:15:09 +01:00
Kristiyan Kostadinov 009ec5ccbe fix(compiler-cli): handle optional signals in uninvoked signals check
The uninvoked signals check in the preprocessor wasn't accounting for signals declared as optional.
2026-11-05 16:15:09 +01:00
Matthew Beck a2617c5b96 fix(compiler-cli): mark ModuleWithProviders from foreign function calls as synthetic
Mark references resolved via try_foreign_function_call and
mark_value_synthetic on SyntheticValue::ModuleWithProviders as
synthetic = true, matching ngtsc's StaticInterpreter
resolveForeignFunctionCall / visitFfrExpression behavior so that
ClassData::to_wire sets remote_scopes_may_require_cycle_protection and
processor.ts wraps remotely-scoped ɵɵsetComponentScope arrays in
closures.
2026-11-05 13:17:25 +01:00
Matthew Beck 3725ddcd46 test(compiler-cli): add tests for synthetic ModuleWithProviders from foreign functions
Add evaluator, cross-file compiler, and end-to-end TypeScript remote
scoping tests covering ModuleWithProviders<T> values returned via
foreign function resolution.
2026-11-05 13:17:25 +01:00
Matthew Beck f5b0fa96a4 fix(compiler-cli): emit static ctorParameters for zero-arg constructor in jit: true
Emit static ctorParameters = () => [] when a jit: true class declares an
explicit zero-argument constructor (matching ngtsc's
downlevel_decorators_transform.ts), while continuing to omit
ctorParameters when no constructor is declared.
2026-11-05 10:02:42 +01:00
Matthew Beck 6e3c007064 test(compiler-cli): add test for jit: true class with empty constructor
Add a test covering jit: true classes with explicit zero-argument
constructors alongside a jit: true component with an implicit constructor.
2026-11-05 10:02:42 +01:00
Matthew Beck 02a8a664ae fix(compiler-cli): suppress wire codegen when NgModule analysis fails
Track fatal NgModule scope analysis failures via NgModuleData::analysis_failed
and filter failed NgModule classes out of FileData::to_wire in full compilation
mode, avoiding cascading TS6133/TS2339 errors on emitted .ng.ts files while
preserving NG6xxx diagnostics and strictInjectionParameters NG2003 validation
for co-located @Injectable() decorators.
2026-11-05 09:54:11 +01:00
Matthew Beck 034d8d111f test(compiler-cli): add tests for failed NgModule analysis suppression and diagnostics
Add Rust and TypeScript preprocessor tests covering wire suppression,
strictInjectionParameters NG2003 preservation on co-located @Injectable,
and noUnusedLocals decorator retention when @NgModule analysis fails.
2026-11-05 09:54:11 +01:00
Kristiyan Kostadinov 78b6c53d48 fix(compiler-cli): implement uninvoked signal check in preprocessor
Ports over the uninvoked signal check from ngtsc to the preprocessor.

**Disclaimer:** we don't have access to a type checker in the preprocessor which means that the new check won't be as accurate as what we have in ngtsc. This is a trade-off we're making in the name of feature parity and of performance.
2026-11-04 22:08:23 +01:00
Andrew Scott 4f4fd8e43e refactor(compiler-cli): support in-process execution and persistent analyzer in preprocessor
Expose `createHybridCompiler` factory function to construct a `HybridCompiler`
configured with compiler options read from `IAnalyzer.getCompilerOptions()`.
Add `keepAnalyzerAlive` option to `RunOptions` in `run()` to allow persistent
worker hosts to keep the analysis sidecar open across multiple compilation requests.
2026-11-04 22:05:49 +01:00
Kristiyan Kostadinov 57905ca4e6 refactor(compiler-cli): set up diagnostic codes in preprocessor
Moves the diagnostic codes source of truth from ngtsc into the Rust side of the preprocessor. We generate a TS file from them for the cases where the codes need to be used in TS.
2026-11-04 09:05:13 +01:00