Decide: two `@Component` on one class — ngtsc compiles the first with no error; OXC's HMR text scan pairs the second
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- angular, rust, typescript
- 領域
- build-system, tooling
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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).
- 主要語言
- Rust
- 星號
- 244
- 分支
- 26
- 平均合併
- 1 天 16 分鐘
- 30 天內合併 PR
- 87
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
voidzero-dev/oxc-angular-compiler 的其他 Issue
-
vite: async/await is not lowered for zone.js, so fakeAsync/tick cannot control awaits可能已有人在做 @edbzn 今天認領。 未關閉
難度 4/5 3-5 天 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#641 ·
維護者通常 1 天內回覆
-
Constructor param typed `ns.Foo` (namespace-qualified) compiles to ɵɵinvalidFactoryDep可能已有人在做 @edbzn 今天認領。 未關閉
難度 3/5 1-2 天 新手友好度 25/100
voidzero-dev/oxc-angular-compiler#633 ·
維護者通常 1 天內回覆
-
@defer doesn't lazy-load an imports entry written as forwardRef(() => X)可能已有人在做 @edbzn 今天認領。 未關閉
難度 4/5 3-5 天 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#632 ·
維護者通常 1 天內回覆
-
Project-wide preserveWhitespaces option is ignored可能已有人在做 @edbzn 今天認領。 未關閉
難度 3/5 1-2 天 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#631 ·
維護者通常 1 天內回覆
-
Constructor overloads: factory and metadata read the first overload, not the implementation可能已有人在做 @edbzn 今天認領。 未關閉
難度 4/5 3-5 天 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#630 ·
維護者通常 1 天內回覆
查看 voidzero-dev/oxc-angular-compiler 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 73/100
維護者通常 1 天內回覆
-
C-bug needs-triage O-UEFI T-libs
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
bug priority: P3 ready-for-agent
難度 2/5 1-3 小時 新手友好度 82/100
shep-pm/shep-kelpie#1332 ·
維護者通常 1 天內回覆
-
enhancement
難度 2/5 1-3 小時 新手友好度 65/100
ramensoftware/windhawk#1156 · 2 則留言 ·
-
area/cli complexity:trivial good first issue Stellar Wave test
難度 2/5 1-3 小時 新手友好度 68/100
Externalize-Labs/externalize#23 ·
維護者通常 1 天內回覆