Tracking: evaluate decorator metadata values imported from other files
维护者通常 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 内容生成。
描述
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 literalqueries: Q→NG1010: Decorator queries metadata must be an object literalinput(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 isdirective/evaluator.rs. Both are in the stack.
Possible approaches (not decided)
- Resolver hook from the Vite plugin.
transformAngularFiletakes 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. - Reuse
component/cross_file_elision.rs. Behind thecross_file_elisionfeature (off by default, "intended for compare test purposes only") it already resolves imports withoxc_resolver(tsconfig paths included), parses the target withoxc_parser, and walks re-exports. It could be extended to evaluate exportedconstinitializers and feed the result to the evaluator. - 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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
voidzero-dev/oxc-angular-compiler 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
voidzero-dev/oxc-angular-compiler#511 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 78/100
voidzero-dev/oxc-angular-compiler#522 ·
维护者通常 1 天内回复
-
question
难度 5/5 一周以上 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#521 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 76/100
voidzero-dev/oxc-angular-compiler#520 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 76/100
voidzero-dev/oxc-angular-compiler#519 ·
维护者通常 1 天内回复
查看 voidzero-dev/oxc-angular-compiler 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
check: a failed re-read of the model file before binding is labelled E_THETA_LEVEL_BINDING on [parameters]可能已有人在做 @TeunP 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 80/100
Devolutions/picky-rs#546 · 1 条评论 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复