Decide: two `@Component` on one class — ngtsc compiles the first with no error; OXC's HMR text scan pairs the second
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- angular, rust, typescript
- Lĩnh vực
- build-system, tooling
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Rust
- Star
- 232
- Fork
- 21
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 53
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của voidzero-dev/oxc-angular-compiler
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
voidzero-dev/oxc-angular-compiler#511 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(emit): arrow functions in metadata lose default parameter values and `async`Có thể đã có người làm @Brooooooklyn đã nhận hôm nay. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
voidzero-dev/oxc-angular-compiler#512 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 78/100
voidzero-dev/oxc-angular-compiler#510 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(aot): a user binding named `i0` collides with the injected `import * as i0 from '@angular/core'`Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
voidzero-dev/oxc-angular-compiler#509 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
voidzero-dev/oxc-angular-compiler#508 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của voidzero-dev/oxc-angular-compiler
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Update dusk-bls12_381 to 0.16Có thể đã có người làm @HDauven đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
`TcpListenerService` shares one `Extensions` store across all accepted connectionsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
googlefonts/fontquant#43 ·