feat(class_metadata): emit JIT/TestBed metadata for signal members and all decorated class kinds#303
Merged
Brooooooklyn merged 8 commits intoMay 28, 2026
Conversation
…stBed Signal-based members (`input()`/`input.required()`/`output()`/`model()`/ `viewChild()`/`viewChildren()`/`contentChild()`/`contentChildren()`) live only in the AOT `ɵcmp`, which `TestBed.overrideComponent` discards before recompiling via JIT. The JIT recompile reconstructs inputs/outputs/queries from decorator and prop metadata reflected off the class, so signal members were silently dropped on recompile — `setInput`/router-binding then failed with NG0315/NG0303/NG0950. Synthesize the equivalent `@Input`/`@Output`/query prop decorators into `setClassMetadata`, mirroring `@angular/compiler-cli`'s `initializer_api_transforms` (applied by the Angular CLI in test builds). The decorator type is referenced via the `@angular/core` namespace import (`i0.Input`), exactly as ngc emits it; output verified byte-for-byte against ngc 21.2 across all initializer-API member kinds.
… from setClassMetadata
A `@Component` config field whose value is a template literal with an
unresolvable `${…}` interpolation (e.g. ``selector: `${UNRESOLVED}-tag` ``) was
copied verbatim into `ɵsetClassMetadata`, leaking the raw `${…}` text. The AOT
`ɵcmp` path already drops such fields (voidzero-dev#300); apply the same fold-or-drop on the
`setClassMetadata` decorator-args path.
Expose `resolve_template_literal` as `pub(crate)` and thread the file-scope string
consts into `build_decorator_metadata_array`. Resolvable interpolations
(`${KNOWN_CONST}`) still fold and are left untouched; only unresolvable fields are
dropped (post-conversion, so key/quoting/ordering fidelity is preserved). Fixes the
pre-existing `component_template_literal_unresolved_identifier_drops_field` test,
which default-on `emit_class_metadata` (voidzero-dev#299) had turned red.
…ed initializer APIs Match ngc's `tryParseInitializerApi`, which unwraps `as`/parenthesized expressions and resolves namespaced calls: - `x = input(0) as any` / `x = (input(0))` — unwrap `TSAsExpression`/ `ParenthesizedExpression` before matching the initializer call (applies to input/output/model/query detectors, so both the AOT ɵcmp and setClassMetadata paths recognize them). - `core.input.required()` / `core.model.required()` — recognize the namespaced `<ns>.<fn>.required()` form, not just `<fn>.required()`. Output verified byte-for-byte against @angular/compiler-cli 21.2.14.
Directives previously emitted no `setClassMetadata`, so `TestBed.overrideDirective` could not reflect their decorators and signal inputs/outputs/queries were lost on recompile. Emit it for the `@Directive` AOT branch, mirroring the `@Component` path: the `@Directive` decorator metadata, `ctorParameters` (reflected from the class), and prop decorators (real `@Input`/`@Output`/query decorators plus synthesized initializer-API ones). Matches ngc, which emits directive class metadata. Constructor-token types are reflected from the AST (not namespace-prefixed) since directive metadata carries a different dependency representation than `build_ctor_params_metadata` consumes — the common no-constructor directive emits `null` ctorParameters, exactly like ngc. Updates two host-directive snapshots that now include the directive `setClassMetadata`.
…nd NgModules
Extends directive metadata support to the remaining decorated class kinds so
TestBed.overridePipe/overrideModule and reflection work, matching ngc which emits
setClassMetadata for every decorated class. Each emits the decorator metadata,
ctorParameters (reflected from the class — imported token types are namespace-
prefixed via the import map, e.g. `() => [{ type: i0.Injector }]`), and prop
decorators.
Extracts the shared `build_set_class_metadata_decls` helper (used by the
@Directive/@Pipe/@Injectable/@NgModule branches), replacing the inline directive
block. Output verified byte-for-byte against @angular/compiler-cli 21.2.14 for
each kind, including constructor-DI cases.
…adata Add regression guards for the classic (non-signal) decorators in setClassMetadata, on both @component and @directive: plain/aliased/config @input, plain/aliased @output, @ViewChild/@ViewChildren, @ContentChild/@ContentChildren (with read/ descendants), @HostBinding, and @HostListener (with args) — plus a mixed classic+signal class. Expected shapes verified byte-for-byte against @angular/compiler-cli 21.2.14.
…ecorators A signal query with no locator (`viewChild()`) is invalid (ngc errors); skip synthesis instead of emitting a malformed decorator that treats the options object as the predicate. No behavior change for valid queries. Also drops a stale duplicate comment.
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Brooooooklyn
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes
ɵsetClassMetadatacomplete enough forTestBed.overrideComponent/overrideDirectiveto recompile correctly matching@angular/compiler-cli.input()/input.required()/output()/model()/viewChild()/viewChildren()/contentChild()/contentChildren()) live only in the AOTɵcmp, whichoverrideComponentdiscards before recompiling via JIT. JIT reconstructs inputs/outputs/queries from decorator/prop metadata, so signal members were dropped on recompile (NG0315/NG0303/NG0950). We now emit the equivalent@Input/@Output/query prop decorators intoɵsetClassMetadata, mirroringcompiler-cli'sinitializer_api_transforms(referenced via the@angular/corenamespace, e.g.i0.Input).ɵsetClassMetadatafor@Directive/@Pipe/@Injectable/@NgModule(previously@Component-only), so TestBed overrides and reflection work for every decorated class kind.as-cast / parenthesized (x = input(0) as T,(input(0))) and namespaced-required (core.input.required()).${…}interpolation (e.g.selector: \${UNRESOLVED}-tag`) instead of copying the raw text intoɵsetClassMetadata— applying the same fold-or-drop the AOTɵcmp` path already does.Why
Using OXC as a component-test compiler
TestBed.overrideComponentrebuildsɵcmpfrom decorator/prop metadata reflected off the class. Angular's CLI applies a transform that synthesizes these decorators for signal members; OXC didn't, so they vanished on recompile. This change brings OXC in line with that transform.Parity
Output verified byte-for-byte against
@angular/compiler-cli21.2.14 across the full matrix —input/required/aliased,output,model/aliased,viewChild/viewChildren/contentChild(+options)/contentChildren, classic@Input/@Output/@ViewChild/@ContentChild/@HostBinding/@HostListener, and constructor-DI namespacing — on Component, Directive, Pipe, Injectable, and NgModule.