Tracking: evaluate decorator metadata values imported from other files
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Feature
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- angular, rust, typescript
- Bereich
- compilers
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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).
- Vorherrschende Sprache
- Rust
- Sterne
- 232
- Forks
- 21
- Ø Merge
- 2 T. 14 Std.
- Gemergte PRs (30 T.)
- 30
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus voidzero-dev/oxc-angular-compiler
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
voidzero-dev/oxc-angular-compiler#511 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 78/100
voidzero-dev/oxc-angular-compiler#522 ·
Maintainer antworten meist innerhalb von 1 Tag
-
question
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
voidzero-dev/oxc-angular-compiler#521 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
voidzero-dev/oxc-angular-compiler#520 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
voidzero-dev/oxc-angular-compiler#519 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in voidzero-dev/oxc-angular-compiler
Ähnliche Issues
-
[Misdetection] `text/tab-separated-values` file misdetected as `text/tsv`Evtl. vergeben @bact hat das heute übernommen. Offenmisdetection needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
C-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 2 Tagen
-
vxc prints a debug line '[flat-codegen] emitted module via the flat path' on every compileEvtl. vergeben @YodHeVauHe hat das heute übernommen. Offendevex good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Unused dependenciesOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag