Skip to content

feat(compiler): evaluate decorator metadata imported from other files - #553

Merged
Brooooooklyn merged 1 commit into
mainfrom
feat/issue-518-cross-file-metadata
Oct 7, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
feat/issue-518-cross-file-metadata

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Fixes #518.

What

Decorator metadata that references values exported from other files errored with "depends on 'X', which is imported from another module" — e.g.

// meta.ts
export const INPUTS = ['x', 'y: why'];

// app.ts
import { INPUTS } from './meta';
@Directive({ selector: 'a', inputs: INPUTS })
class A {}

ngtsc evaluates these through its program-wide checker. This adds an opt-in resolve_imported_values / napi resolveImportedValues option (gated on the existing cross_file_elision feature, which the vite plugin and compare builds already compile) that resolves exported const values Rust-side.

How

  • directive/evaluator.rs: an owned StaticValue (scalars, arrays, objects — no references) plus an ImportValueResolver trait. The evaluator consults it for named imports and ns.X member access; None keeps today's opaque-reference diagnostic.
  • component/cross_file_elision.rs: CrossFileAnalyzer is now Rc<Inner> so analyze_file can hand out Rc<dyn ImportValueResolver> (CrossFileResolver). resolve_export_value skips node_modules, follows export {}/export * chains (depth-capped, cycle-safe — circular export * visited-set added; the hop specifier is now carried as the resolved absolute path so nested-dir barrels resolve correctly), and evaluates const initializers with a resolver-backed StringConsts so [...OTHER_IMPORTED, 'b'] chains across files.
  • Every file read lands in TransformResult.dependencies; the vite plugin now consumes result.dependencies (previously dropped) and registers them with the watcher — an elided import { INPUTS } has no JS edge, so metadata edits would otherwise go stale.
  • Vite plugin and the e2e compare compiler enable the option.

Unresolvable values (packages, export declare, functions, dynamic initializers, objects containing them) keep the existing diagnostic verbatim.

Verification

  • cargo test --workspace --all-features: all green (1177 lib tests; 49 cross_file_elision unit tests incl. 11 new; 9 new tempdir end-to-end tests covering inputs arrays, @Input option objects, namespace imports, re-export/star chains, dependency reporting, and every fallback path).
  • ngtsc fixture compare (resolveImportedValues: true): 100% pass in every category vs Angular 22.2.1.
  • CI cargo test now runs --all-features — feature-gated tests previously never ran.

Known limitation (matches today's error path): imported values containing non-literal members (e.g. {transform: booleanAttribute}) stay opaque and keep the diagnostic.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Comment thread crates/oxc_angular_compiler/src/component/cross_file_elision.rs Outdated
@Brooooooklyn
Brooooooklyn force-pushed the feat/issue-518-cross-file-metadata branch from b941407 to 669b769 Compare October 6, 2026 18:26
Comment thread crates/oxc_angular_compiler/src/component/transform.rs
Comment thread crates/oxc_angular_compiler/src/component/cross_file_elision.rs Outdated
@Brooooooklyn
Brooooooklyn force-pushed the feat/issue-518-cross-file-metadata branch from 669b769 to b42f67a Compare October 6, 2026 18:43
Fixes #518.

Decorator metadata referencing exported consts in other files errored with
"depends on 'X', which is imported from another module" even though ngtsc
resolves these through its program-wide checker:

    // meta.ts: export const INPUTS = ['x'];
    import { INPUTS } from './meta';
    @directive({ inputs: INPUTS }) class A {}

A new `resolve_imported_values` transform option (napi `resolveImportedValues`,
on in the vite plugin and the compare harness) extends the existing
cross-file analysis: `CrossFileAnalyzer` now evaluates exported `const`
initializers through a resolver-aware `StringConsts`, following `export {}`,
`export *`, and cross-file const chains, bounded and cycle-safe. Files read
for resolution land in `TransformResult.dependencies` and are registered with
Vite's watcher so metadata edits re-transform dependents in dev.

Anything unresolvable — packages, `export declare`, functions, dynamic
initializers — keeps the existing diagnostic unchanged.

The vite plugin's transform call now passes `resolveImportedValues` plus
`baseDir`/`tsconfigPath`, and consumes `result.dependencies` (previously
dropped) so files read for value resolution are watched.

Also: `cargo test` in CI now runs `--all-features` — feature-gated tests
(cross_file_elision's whole suite) never ran before.
@Brooooooklyn
Brooooooklyn force-pushed the feat/issue-518-cross-file-metadata branch from b42f67a to 4c4f0c4 Compare October 7, 2026 03:44
@Brooooooklyn
Brooooooklyn merged commit ef1987c into main Oct 7, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the feat/issue-518-cross-file-metadata branch October 7, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking: evaluate decorator metadata values imported from other files

1 participant