Decide: two `@Component` on one class — ngtsc compiles the first with no error; OXC's HMR text scan pairs the second
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
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- angular, rust, typescript
- Bereich
- build-system, tooling
Rechercherichtung
Start with the two-decorator reproduction and compare ngtsc and OXC output and runtime behavior. Read crates/oxc_angular_compiler/src/component/transform.rs, napi/angular-compiler/vite-plugin/utils/decorator-fields.ts, and napi/angular-compiler/vite-plugin/index.ts; done requires an agreed option and matching compiler metadata and HMR behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
import {Component} from '@angular/core';
@Component({selector: 'a-cmp', template: 'first'})
@Component({selector: 'b-cmp', template: 'second'})
export class C {}
ngtsc 22.1.7 gives no diagnostic. It compiles the first @Component and leaves the second as a runtime decorator. At runtime that second decorator replaces ɵcmp with a JIT getter, so the module crashes on load without @angular/compiler. Same with OXC's output. So the input is broken under both compilers, and there is no ngtsc error for OXC to copy.
OXC still differs from ngtsc in two small ways. Opening this to decide whether either is worth fixing.
Compile output
OXC (#504 tip and main, same output):
@Component({selector: 'b-cmp', template: 'second'})
export class C {
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:C,selectors:[["a-cmp"]], ... i0.ɵɵtext(0,"first") ...});
}
... i0.ɵsetClassMetadata(C,[{type:Component,args:[{selector:"a-cmp",template:"first"}]}],null,null)
ngtsc 22.1.7:
let C = class C {
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: C, selectors: [["a-cmp"]], ... i0.ɵɵtext(0, "first") ... });
};
C = __decorate([
Component({ selector: 'b-cmp', template: 'second' })
], C);
... i0.ɵsetClassMetadata(C, [{
type: Component,
args: [{ selector: 'a-cmp', template: 'first' }]
}, {
type: Component,
args: [{ selector: 'b-cmp', template: 'second' }]
}], null, null)
Both compile the first decorator and keep the second. Difference 1: ngtsc's setClassMetadata lists both decorators, OXC's lists only the compiled one.
Runtime (node, @angular/core 22.1.7, no @angular/compiler), both outputs:
Error: The component 'C' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
HMR (Vite plugin)
Rust reports componentDecorators = {"c.ts@C": "Component"}, and templateUpdates["c.ts@C"] is the template of the first decorator (ɵɵtext(0,"first")).
stripComponentMetadata empties the template: / styles: of the decorator locateComponentDecorators pairs with C. Pass 2 of that scan looks for class X only between one decorator's ) and the next decorator's @, so the first @Component pairs with no class and the second one gets C. Difference 2: the plugin empties the decorator the compiler did not take:
pairs: [["C","({selector: 'b-cmp', template: 'second'})"]]
edit first (compiled) -> stripped forms differ => full reload
edit second (not compiled) -> stripped forms equal => HMR event, but the update holds the first template, so nothing changes
(Checked by running the real decorator-fields.ts functions and a copy of stripComponentMetadata with oxnode. Same pairing on main, where the scan only looks for the literal @Component(.)
Where
crates/oxc_angular_compiler/src/component/transform.rs:find_component_decoratortakes the first match (same as ngtsc);component_decoratorsreports only its callee text, not its position.napi/angular-compiler/vite-plugin/utils/decorator-fields.ts:locateComponentDecorators, pass 2 (bounded class-name scan).napi/angular-compiler/vite-plugin/index.ts:stripComponentMetadatakeys the decorators by class name, so two same-spelled decorators on one class can't be told apart.
On main?
Yes (both differences). componentDecorators itself is only on the #504 stack (d1fa6c4).
Options
- Leave as is: the input already crashes at runtime with ngtsc too.
- Report the compiled decorator's span (not only its spelling) in
componentDecorators, so the plugin empties exactly that one. - List every class decorator in
setClassMetadata, like ngtsc. - Add a warning for a second Angular class decorator of the same kind (ngtsc has none, so this would go beyond ngtsc).
- Vorherrschende Sprache
- Rust
- Sterne
- 240
- Forks
- 24
- Ø Merge
- 1 T. 16 Std.
- Gemergte PRs (30 T.)
- 72
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
-
fix(directive): input names with lone surrogates are emitted in oxc's internal U+FFFD encodingOffenbug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 68/100
voidzero-dev/oxc-angular-compiler#505 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug rust
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 56/100
voidzero-dev/oxc-angular-compiler#313 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Support useDefineForClassFields: false (Class Field Lowering)Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
voidzero-dev/oxc-angular-compiler#73 · 11 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Angular 21.2.0 + @oxc-angular/vite 0.0.7 SSR runtime parity regressions (RouterLinkActive, Forms DI, Apollo DI) require app-level shimsEvtl. wieder frei @Brooooooklyn hat das vor 228 Tagen übernommen, und es ist kein Pull Request offen. Offen
voidzero-dev/oxc-angular-compiler#61 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Angular 21.2.0 + @oxc-angular/vite 0.0.7 SSR: AngularNodeAppEngine is unusable (missing app-engine manifest)Evtl. wieder frei @Brooooooklyn hat das vor 228 Tagen übernommen, und es ist kein Pull Request offen. Offen
voidzero-dev/oxc-angular-compiler#60 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in voidzero-dev/oxc-angular-compiler
Ähnliche Issues
-
area:desktop priority:p2 type:bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
fritzprix/libr-agent#2165 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
area:ecosystem bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Chelis-Lang/chelis#3942 ·
Maintainer antworten meist innerhalb von 1 Tag