11 Commits
Author SHA1 Message Date
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
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
Kristiyan Kostadinov 4501ff813f refactor(compiler-cli): initial implementation of incremental compilation in preprocessor
Adds an initial implementation for incremental compilation in the preprocessor. Some numbers from a benchmark running against a synthetic app made up of  20 features x 20 components + 30 shared directives/pipes/services (~500 TS files, ~400 templates):

| scenario | main | branch | delta | files processed (main -> branch) | files written (main -> branch) |
|---|---|---|---|---|---|
| cold build (fresh analyzer) | 3388 ms | **3366 ms** | −0.7% | 513 -> 513 | 513 -> 513 |
| rebuild: template edit (leaf component) | 3143 ms | **41 ms** | −98.7% | 513 -> 1 | 513 -> 1 |
| rebuild: component method body | 3144 ms | **40 ms** | −98.7% | 513 -> 1 | 513 -> 2 |
| rebuild: service method body (widely imported) | 3150 ms | **34 ms** | −98.9% | 513 -> 1 | 513 -> 8 |
| rebuild: directive public API (new input) | 3167 ms | **169 ms** | −94.6% | 513 -> 10 | 513 -> 8 |
| rebuild: NgModule scope (drop an export) | 3210 ms | **49 ms** | −98.5% | 513 -> 1 | 513 -> 2 |

**Note:** the real-world numbers will depend on build tooling integration so take these numbers with a grain of salt.
2026-10-29 17:47:21 +01:00
Charles Lyding 0210eb4fa2 refactor(compiler-cli): make tsconfig optional for the preprocessor analyzer
Integrations such as bundlers and the Angular CLI may have no tsconfig at all, or already own
the parsed configuration. The analyzer can now be constructed from options alone.

`AnalyzerOptions.tsconfigPath` is now optional, and three options replace what could
previously only come from the tsconfig:

- `entryPoints`: the roots of the program closure. When set, they replace the tsconfig's root
  files, and the roots are no longer re-read from the tsconfig after file updates (the same
  holds after `setEntryPoints`). Bundlers pass their own entry files; the analyzer follows
  imports from there. The `.d.ts` files a tsconfig lists are still searched for ambient
  modules either way.
- `r3SymbolsFile`: the `r3_symbols.ts` file used when compiling `@angular/core` itself, which
  was only found by scanning the root files for that name. The scan remains the fallback.
- `implicitStandalone`: whether declarations without an explicit `standalone` flag are
  standalone, which was only derived from `angularCompilerOptions._angularCoreVersion`. The
  tsconfig value remains the fallback, and the default is `true`.

`setEntryPoints` is now exposed on every backend (N-API, WASM and the sidecar) and on
`IAnalyzer`, so integrations that discover entry files incrementally can replace the roots
after construction. Like `updateFileContent`, it returns every path whose cached analysis is
now stale.

`createAnalyzer` and `createAnalyzerWithInfo` also accept a single options object in which
`tsconfigPath` is optional, alongside the existing tsconfig-path form, which is unchanged.

Without a tsconfig, every unset option takes its documented default (matching the defaults of
an empty tsconfig), path-valued options must be absolute since there is no directory to
resolve them against, and the module resolver runs without tsconfig `paths` mappings.
Behavior is unchanged when a tsconfig is given and the new options are unset.
2026-10-27 06:58:15 -07:00
Charles Lyding 44220dd7b9 refactor(compiler-cli): add explicit preprocessor analyzer options alongside tsconfig
The preprocessor analyzer could only be configured by reading a tsconfig, which prevents
integrations (bundlers, the Angular CLI) that have no tsconfig or already own the parsed
configuration from driving it directly. This is the first step toward making the analyzer
tsconfig-agnostic.

Every setting that was previously only read from the tsconfig is now also an explicit
`AnalyzerOptions` field: `strictStandalone`, `strictInjectionParameters`,
`compileNonExportedClasses` and `generateExtraImportsInLocalMode`. Settings that only
configure the built-in file-system module resolution move into a separate `defaultHost`
(`rootDirs`, `preserveSymlinks`, `nodeModulesPathOverride`), since they will belong to the
default host rather than the analyzer core once resolution is delegated to a host.
`importPrefixRoots` replaces the ambiguously named `rootDirs` option, which only ever
configured the `PrefixImportStrategy` roots. The previous `rootDirs` and top-level
`nodeModulesPathOverride` fields remain as deprecated aliases.

All new fields are optional and fall back to the tsconfig; an explicitly set option always
wins. Construction is split into `EffectiveConfig::resolve`, the single place where options
are merged over tsconfig values, and `Analyzer::construct`, which preserves the previous
construction order. Behavior is unchanged when no new options are set.

`LoadAnalyzerOptions` now extends the engine's `AnalyzerOptions` and the loader forwards
engine options as-is instead of copying a fixed subset of fields, so new engine options are
usable through `createAnalyzer()` without loader changes. `SidecarAnalyzer.initialize`
forwards any additional engine options the same way.
2026-10-23 09:03:46 -07:00
Matthieu Riegler 970bbc7cd0 refactor(compiler-cli): implement extended template diagnostics in preprocessor
Implements AST-only and scope-aware extended template diagnostics,
template variable write checks, and unused standalone import checks
in the NGP preprocessor.
2026-10-23 07:33:41 +02:00
Kristiyan Kostadinov 2766c7057c fix(compiler-cli): implement compiler option validations
Ports over the compiler options validations from ngtsc.
2026-10-22 23:00:49 +02:00
Andrew Scott fd1de1b0bb refactor(compiler-cli): remove dead code and wire Bazel WASM/sidecar paths in preprocessor
- Add Bazel (`dist/bin/packages/compiler-cli/preprocessor/ng-analyze/ng_analyze_wasm/ng_analyze_wasm.js`) and bundled (`../ng-analyze/ng_analyze_wasm/ng_analyze_wasm.js`) WASM binding candidates to `wasmCandidates()` in `analyzer_loader.ts` so `createAnalyzer(..., {backend: 'wasm'})` and `main.ts --wasm` locate the Bazel-built WASM binary without requiring an explicit `wasmBinding` path.
- Wire `options.sidecar` in `test/utils.ts` (`runPipeline`) to spawn `SidecarAnalyzer` (`ng_analyze_bin`) so `t4_tri_modal_parity_audit` in `test/resource_resolution_spec.ts` compares WASM vs. Sidecar output rather than comparing WASM against itself.
- Deduplicate `refName` and `refToExpression` in `processor.ts` by importing them from `compiler-utils.ts`.
- Remove unused `_workspaceName` and `_rootDirs` parameters from `prepareTcbTargets` in `tcb.ts` and its call sites.
- Remove unused imports, interfaces (`ImportViaMetadata`), fields (`FileAnalysis.typeOnlyExports`), variables (`IGNORE_MARKER_REGEX`, `currentTcbUri`, `GOLDEN_ROOT`), and helper functions (`collectGoldenCases()`, `flatten()`).
- Fix outdated comments, typos, and Vitest/standalone repo references.
2026-10-14 17:33:24 +02:00
Andrew Scott 4b6788f1fe feat(compiler-cli): support synchronous WASM execution in preprocessor (#71313)
Add synchronous execution paths to WasmAnalyzer, HybridCompiler, and processor so synchronous compiler test harnesses can invoke the WASM analyzer and preprocessor without async bridging.

PR Close #71313
2026-10-13 05:33:37 +02:00
4e4ad75144 refactor(compiler-cli): integrate hybrid preprocessor into compiler-cli
Integrate the hybrid Angular preprocessor (NGP) under packages/compiler-cli/preprocessor,
along with its language service integration, VS Code extension, and Rust/Wasm Bazel toolchain.

Key components included:
- Rust-based AST analyzer and Wasm compilation target (packages/compiler-cli/preprocessor/ng-analyze)
- Preprocessor engine and Jasmine test suites (packages/compiler-cli/preprocessor)
- Language service extension and specs (packages/compiler-cli/preprocessor/language-service)
- Experimental VS Code extension (ngp-vscode-ng-language-service)
- Rust toolchain and crate dependencies in Bazel (MODULE.bazel, Cargo.toml)

Monorepo integration & compatibility adjustments:
- Rust toolchain & hermetic Bazel testing: Made N-API optional (default = [] in Cargo.toml) and
  added non-NAPI fallback methods on Analyzer and TestAnalyzer (analyzer.rs, test_analyzer.rs,
  lib.rs) for native Bazel rust_test and Wasm compilation; replaced static Cargo.toml lookups in
  fs.rs tests with hermetic tempfile fixtures for Bazel sandbox execution; updated driver test
  fixture for Option<String> local_name.
- Angular monorepo TypeScript & linting compliance: Added tslint:disable:no-console pragmas to CLI
  entrypoints (main.ts, ngp.ts); added explicit override modifiers (output_ast_printer.ts); aligned
  TypeScript ESM imports (tcb_ls_util.ts); and consolidated compiler imports and type references
  (processor.ts, hybrid_compiler.ts).

Co-authored-by: Matthew Beck <[email protected]>
Co-authored-by: Alex Rickabaugh <[email protected]>
Co-authored-by: Kristiyan Kostadinov <[email protected]>
Co-authored-by: JoostK <[email protected]>
Co-authored-by: Matthieu Riegler <[email protected]>
2026-10-08 14:23:48 -07:00