fix(ng_module): `ɵfac` ignores `@Inject(TOKEN)` on `@NgModule` constructor parameters
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 76/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- rust, typescript
- 領域
- compilers
研究方向
Start in crates/oxc_angular_compiler/src/ng_module/decorator.rs at extract_param_dependency, then compare directive/decorator.rs and pipe/decorator.rs. Check how the @Inject argument is extracted and how the other four extract_param_dependency copies differ. Done means @NgModule factories use the @Inject token, fall back to the type without @Inject, and cover both token and class-type reproductions.
由索引模型根據 Issue 內容生成。
描述
The @NgModule factory reads @Optional, @Self, @SkipSelf, @Host and @Attribute on constructor parameters, but not @Inject. The token comes from the type annotation instead:
- type with no token (
unknown, an interface, a primitive) →ɵɵinvalidFactoryDep(i), and the module throws NG0202 when it is created; - class type → the class is injected instead of the
@Injecttoken, with no error.
Same result for an aliased import (import {Inject as Inj}). @Injectable, @Pipe and the other handlers read @Inject fine.
Repro
import {Inject, InjectionToken, NgModule} from '@angular/core';
export const TOKEN = new InjectionToken<unknown>('TOKEN');
@NgModule({})
export class M {
constructor(@Inject(TOKEN) x: unknown) {}
}
import {Inject, Injectable, NgModule} from '@angular/core';
@Injectable({providedIn: 'root'}) export class Real {}
@Injectable({providedIn: 'root'}) export class Other {}
@NgModule({})
export class M {
constructor(@Inject(Other) x: Real) {}
}
OXC (#504 tip and main, same output)
static ɵfac = function M_Factory(__ngFactoryType__) {
return new (__ngFactoryType__ || M)(i0.ɵɵinvalidFactoryDep(0));
};
// at runtime: NG0202: This constructor is not compatible with Angular Dependency Injection
// because its dependency at index 0 of the parameter list is invalid.
return new (__ngFactoryType__ || M)(i0.ɵɵinject(Real)); // should be Other
ngtsc 22.1.7
return new (__ngFactoryType__ || M)(i0.ɵɵinject(TOKEN));
return new (__ngFactoryType__ || M)(i0.ɵɵinject(Other));
Where
crates/oxc_angular_compiler/src/ng_module/decorator.rs, extract_param_dependency (tip ~L467, main ~L444): the decorator match has no "Inject" arm (it falls into _ => {}), and the token always comes from extract_param_token (the type annotation). Compare directive/decorator.rs (tip ~L357) or pipe/decorator.rs (tip ~L307), which read the @Inject argument first.
On main?
Yes.
Direction
Read the @Inject(...) argument as the token, like the pipe extractor does, and fall back to the type only when there is no @Inject. The five extract_param_dependency copies (component, directive, pipe, injectable, ng_module) could share one helper so they can't drift again.
- 主要語言
- Rust
- 星號
- 232
- 分支
- 21
- 平均合併
- 1 天 23 小時
- 30 天內合併 PR
- 53
環境準備
這個專案沒有提供開發容器、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 天內回覆
-
fix(emit): arrow functions in metadata lose default parameter values and `async`可能已有人在做 @Brooooooklyn 今天認領。 未關閉bug
難度 4/5 3-5 天 新手友好度 58/100
voidzero-dev/oxc-angular-compiler#512 ·
維護者通常 1 天內回覆
-
bug
難度 3/5 1-2 天 新手友好度 78/100
voidzero-dev/oxc-angular-compiler#510 ·
維護者通常 1 天內回覆
-
fix(aot): a user binding named `i0` collides with the injected `import * as i0 from '@angular/core'`未關閉bug
難度 4/5 3-5 天 新手友好度 68/100
voidzero-dev/oxc-angular-compiler#509 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 52/100
voidzero-dev/oxc-angular-compiler#508 ·
維護者通常 1 天內回覆
查看 voidzero-dev/oxc-angular-compiler 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 4 天內回覆
-
Update dusk-bls12_381 to 0.16可能已有人在做 @HDauven 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 72/100
googlefonts/fontquant#43 ·
-
bot:ai-assisted status:untriaged
難度 2/5 1-3 小時 新手友好度 68/100
midnightntwrk/midnight-zk#561 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 74/100
rubys/roundhouse#571 ·
維護者通常 1 天內回覆