Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Tracking: evaluate decorator metadata values imported from other files

未关闭
#518 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
活跃
技术栈
angular, rust, typescript
领域
compilers

调研方向

Start in crates/oxc_angular_compiler/src/directive/decorator.rs around the reported error and read directive/evaluator.rs. Compare the resolver and dependency handling in component/cross_file_elision.rs with TransformOptions::resolved_imports and the Vite transform path. A complete direction should define how imported literal values are evaluated, dependent files are re-transformed, and unsupported cases retain a clear fallback.

由索引模型根据 Issue 内容生成。

描述

enhancement

OXC compiles one file at a time. ngtsc has the whole program, so its static evaluator follows an import into the other file and reads the value. OXC can't do that. Since #493 (fix/decorator-metadata-inputs-outputs) and #495 (feat/decorator-metadata-queries), OXC reports a clear error in these cases. Main silently emits wrong metadata.

Error: @Directive.inputs depends on 'INPUTS', which is imported from another module. OXC compiles one file at a time and cannot evaluate values from other files.

This issue tracks the gap and possible ways to close it.

Affected forms (other.ts exports a plain const)

Source ngtsc 22.1.7 OXC #504 tip OXC main
@Directive({inputs: INPUTS}), INPUTS = ['a'] inputs: { a: "a" } error input dropped (no inputs)
@Directive({inputs: [NAME]}), NAME = 'a' inputs: { a: "a" } error input dropped
@Directive({outputs: OUTPUTS}), OUTPUTS = ['o: oo'] outputs: { o: "oo" } error output dropped
@Input(OPTS) a, OPTS = {alias: 'b', required: true} inputs: { a: [0, "b", "a"] } ("required": true in .d.ts) error inputs:{a:"a"} (alias and required ignored)
@Input({alias: ALIAS}) a, ALIAS = 'b' inputs: { a: [0, "b", "a"] } error inputs:{a:"a"}
@Output(ONAME) o, ONAME = 'oo' outputs: { o: "oo" } error outputs:{o:"o"}
@ViewChild('a', {static: STATIC}), STATIC = true ɵɵviewQuery(_c0, 7) error ɵɵviewQuery(_c0,5) (not static)
@Input({transform: T}), T a function in other.ts .d.ts: ngAcceptInputType_a: string ngAcceptInputType_a: unknown unknown
@ViewChild(SEL), SEL = 'a' ɵɵviewQuery(_c0, 5), _c0 = ["a"] ɵɵviewQuery(SEL,5) same as tip

The last row works at runtime (ɵɵviewQuery accepts a string predicate), so only the shape differs.

These are not gaps, because ngtsc rejects them too and the tip matches it:

  • @ViewChild('a', QOPTS) → NG1001: @ViewChild options must be an object literal
  • queries: Q → NG1010: Decorator queries metadata must be an object literal
  • input(0, {alias: ALIAS}) → NG1010: Alias needs to be a string that is statically analyzable. (OXC misses this one; it's in the diagnostics issue)

Example:

// test.ts
import {Directive} from '@angular/core';
import {INPUTS} from './other';
@Directive({selector: '[d]', inputs: INPUTS})
export class D { a: any; }

// other.ts
export const INPUTS = ['a'];

Where

  • The error comes from crates/oxc_angular_compiler/src/directive/decorator.rs (~L706). The static evaluator is directive/evaluator.rs. Both are in the stack.

Possible approaches (not decided)

  1. Resolver hook from the Vite plugin. transformAngularFile takes a callback, or a precomputed map, that returns the value of an imported binding (specifier + exportName). The plugin resolves with Vite's resolver and reads the file. There is already a similar input, TransformOptions::resolved_imports (identifier → path), which only rewrites import paths today.
  2. Reuse component/cross_file_elision.rs. Behind the cross_file_elision feature (off by default, "intended for compare test purposes only") it already resolves imports with oxc_resolver (tsconfig paths included), parses the target with oxc_parser, and walks re-exports. It could be extended to evaluate exported const initializers and feed the result to the evaluator.
  3. Leave it as is. Keep the error and document the workaround: inline the value, or declare it in the same file.

For 1 and 2: the importing file has to be re-transformed when the other file changes. TransformResult::dependencies exists today for template and style files, and the Vite plugin links some of them to this.addWatchFile. A dependency on another file's value would need the same kind of wiring. Cycles, re-exports, export *, values that are not literals, and .d.ts-only packages need a defined fallback (keep today's error).

主要语言
Rust
星标
232
派生
21
平均合并
2 天 14 小时
30 天内合并 PR
30

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/oxc-angular-compiler 的其他 Issue

查看 voidzero-dev/oxc-angular-compiler 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。