14 Commits
Author SHA1 Message Date
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 338d0a286d refactor(compiler-cli): decouple preprocessor HybridCompiler from tsconfigPath
`HybridCompiler` wrote `<tsconfig>.ngdiag.json` itself from `prepareChunk` and `prepareChunkSync`,
which tied it to a `tsconfigPath` and to the Node filesystem, or to a `virtualFiles` overlay
standing in for it. Now that the analyzer no longer requires a tsconfig, hosts that embed the
compiler without one have nowhere to write such a file, and whether and where diagnostics are
persisted is a decision for the build driver rather than for the compiler.

`tsconfigPath` and `virtualFiles` are therefore removed from `HybridCompilerOptions`, together
with `writeDiagnosticsFile` and `writeDiagnosticsFileSync`, and `hybrid_compiler.ts` no longer
imports `node:fs`. In their place, `HybridCompiler.getDiagnostics()` returns the collected
per-file diagnostics in the deterministic order the `.ngdiag.json` already used and leaves out
diagnostics anchored on `.d.ts` files unless `includeDeclarationFiles` is set, making it the
single place that filters and orders them; `serializeDiagnostics` now only formats that output.
The `.ngdiag.json` write moves into `run` in `ngp.ts`, gated on a new optional
`RunOptions.tsconfigPath`. The write that preceded the processing of each chunk is dropped as
redundant, while `run` still writes after every chunk and once more at the end so that option
diagnostics reach the file even when the analyzer produces no chunks.

Without a tsconfig there is also nothing to resolve relative paths against, so `rootDir` and
`rootDirs` on `HybridCompilerOptions` must now be absolute; relative `rootDirs` used to be
resolved against `rootDir` or `dirname(tsconfigPath)`. This matters because
`getProjectRelativePath`, which produces the `ɵsetClassDebugInfo` paths and HMR IDs, uses
`path.posix.relative` and would silently resolve a relative root against the process cwd. Both
options are normalized to forward slashes; `rootDir` previously was not, which would have broken
that computation for backslash paths on Windows. `main.ts` resolves relative `rootDirs` against
the tsconfig directory, matching TypeScript and the analyzer, and the test helpers do the same.
2026-10-27 16:52:26 -07:00
Kristiyan Kostadinov def073ed0a fix(compiler-cli): don't report diagnostics against .d.ts files in preprocessor
Fixes that referencing a non-class from a declaration file in an `NgModule` (e.g. passing `NgModule` itself into `imports`) produced a diagnostic pointing to the `.d.ts` file. There were two problems:
1. The evaluator was resolving a type reference to anything it could find, whereas ngtsc only resolves it if the target is a class. As a result, `declare const NgModule: NgModuleDecorator` was resolving to the interface instead of the variable.
2. ngtsc keeps diagnostics on `.d.ts` files, but they're never reported if the build only asks for the diagnostics of the compilation unit's source files, which is what the `.ngdiag.json` consumers do. We now omit them when serializing, but still keep them around so that `getDiagnostics`-style consumers can see them.
2026-10-26 21:14:57 +01:00
Kristiyan Kostadinov da45c9a0a3 fix(compiler-cli): align option diagnostics behavior with ngtsc
An earlier change ported over the compiler option diagnostics from ngtsc, but it mixed them in with the other diagnostics. This ended up breaking internally in two ways:
1. Internally we don't report the compiler option diagnostics, because they're tracked separately.
2. ngtsc has some logic that skips extended template checks, template semantic checks and source file validations if there are any config diagnostics.
2026-10-23 21:14:32 +02:00
Kristiyan Kostadinov a51e7292b7 fix(compiler-cli): implement internal compiler flag
Implements the `_useHostForImportGeneration` compiler flag that we use internally.
2026-10-21 19:53:30 +02:00
Matthew Beck 0fc2bfee4c fix(compiler-cli): plumb i18nPreserveWhitespaceForLegacyExtraction into hybrid compiler
Forward angularCompilerOptions.i18nPreserveWhitespaceForLegacyExtraction into
templateParseOptions.preserveSignificantWhitespace (defaulting to true) across
the CLI entry point, test utilities, and NGP test driver so legacy i18n
whitespace collapsing matches ngtsc.
2026-10-21 08:22:52 +02:00
Kristiyan Kostadinov c56b9e70c4 fix(compiler-cli): implement NgModule scope diagnostics in preprocessor
Ports the `NgModule` scope diagnostics from ngtsc to the preprocessor.
2026-10-20 22:04:22 +02:00
Kristiyan Kostadinov 7728f2765b refactor(compiler): resolve warning with internal tooling
Fixes that the top-level variables we generate from the constant pool cause a warning to be logged internally.
2026-10-14 13:04:08 -07:00
Andrew Scott a56f2031d1 test(compiler-cli): port preprocessor CLI, sidecar isolation, and golden typecheck tests
- Port `ngp.test.ts` to `test/ngp_spec.ts` to test the `main.ts` CLI entrypoint under Bazel.
- Fix the inverted `fs.access(ngAnalyzeDir)` fallback in `main.ts`: when `alxhub/ng-hybrid-preprocessor` commit `c707e178` converted `if (!fs.existsSync(ngAnalyzeDir))` to async `fs.access(ngAnalyzeDir)`, it placed `ngAnalyzeDir = path.resolve(__dirname, '../../ng-analyze')` inside the `try` block instead of the `catch` block, overwriting a valid `./ng-analyze` directory with `../../ng-analyze` whenever `./ng-analyze` existed.
- Port `scripts/check-sidecar-isolation.mjs` to `test/sidecar_isolation_spec.ts` to guard against static imports of `analyzer_loader`, `analyzer_napi`, `analyzer_wasm`, or `wasm_host_fs` from sidecar-mode entrypoints.
- Port `scripts/typecheck-goldens.ts` to `test/typecheck_goldens_spec.ts` with a dedicated sharded `//packages/compiler-cli/preprocessor/test:typecheck_goldens_test` Bazel target to verify emitted TypeScript across all golden test cases.
2026-10-14 17:33:24 +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
Kristiyan Kostadinov b4c41d8ff2 build: preprocessor golden script running against wrong node_modules
Fixes an issue where the script for approving goldens in the preprocessor was running against the wrong `node_modules`, causing random failures.
2026-10-12 20:37:43 +02:00
Kristiyan Kostadinov 520fe13f85 fix(compiler-cli): resolve template stylesheets through the analyzer in the preprocessor
`<link rel="stylesheet">` URLs in a component template were resolved relative to the component file in TypeScript and read directly from disk, bypassing the analyzer's resource resolution. Stylesheets that only exist under a secondary `rootDirs` entry were therefore reported as a false NG2008, even though the same URL works in the decorator's `styleUrls`.

The NG2008 was also anchored on the `templateUrl` string-literal span, so a `templateUrl` written as a template literal produced a diagnostic without a location, which crashed `tsc` when it tried to format it.

Template-linked stylesheets now go through a new `Analyzer.readResource` API backed by the same `ResourceResolver` as `templateUrl`/`styleUrls`, and NG2008 is anchored on the full `templateUrl` expression like in ngtsc.
2026-10-12 20:37:43 +02:00
Matthew Beck 96ccdc02fe fix(compiler-cli): sync hybrid preprocessor evaluator and cache invalidation fixes
Port three commits that landed in ng-hybrid-preprocessor after the initial
monorepo integration snapshot (1f279a05):

1. Scope evaluator cycle guards to the current resolution path (ng-hybrid-preprocessor#607):
   Cross-file evaluation previously used a flat `visited: HashSet<String>`
   that never removed keys upon returning from a resolution step. Consequently,
   any static method call or static member reached along multiple sibling,
   non-cyclic paths (such as `X.forRoot()` imported both directly and through
   a spread constant) resolved only on the first occurrence and turned every
   subsequent occurrence into `Dynamic(ImportCycle)`. Since a single dynamic
   entry invalidates an `@NgModule.imports` array, modules with diamond
   `ModuleWithProviders` imports silently lost their compilation scope.

   Replace the flat set with a path-scoped stack (`ResolutionState.in_progress`)
   and Tarjan-style low-link memoization (`ResolutionState.completed`) so
   sibling occurrences resolve independently without exponential re-evaluation
   on deep diamond chains, while genuine cycles (`A.m() -> B.n() -> A.m()`)
   are still cut as `ImportCycle`.

2. Drop every stale `HybridCompiler.fileCache` entry on file updates (ng-hybrid-preprocessor#614):
   `HybridCompiler.fileCache` is keyed by `AnalysisResult.filePath` (the
   query engine's interned `FileId` path, which is case-folded on
   case-insensitive platforms), whereas `update_file_content_core` and
   `invalidate_files_core` previously returned only `fs.canonicalize()`
   spellings of the directly edited files. This left stale TCB and bound-target
   entries in `fileCache` both when paths contained uppercase segments on
   macOS/Windows and when an edit invalidated a transitive dependent outside
   the `tsconfig.json` entrypoints (such as a file opened on demand by the
   language service).

   Route invalidations through `Analyzer::evict_file` to collect every
   transitively evicted per-file `QueryKey` (including `QueryKey::ProgramFiles`)
   and emit its `engine.lookup_path` wire spelling, and avoid caching empty
   `FileAnalysis` entries under raw caller paths when `getMetadataForFile`
   returns `null`.

3. Audit comments, normalize Angular permalinks, and refine TODOs (ng-hybrid-preprocessor#702):
   Tighten docstrings and inline comments across the Rust analyzer, TypeScript
   preprocessor, language service, and test suites; normalize upstream ngtsc
   reference permalinks; document non-obvious evaluator and compiler pipeline
   invariants; and standardize `TODO(...)` tags.
2026-10-09 22:37:45 +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