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
- 平均合并
- 2 天 14 小时
- 30 天内合并 PR
- 30
环境准备
这个项目没有提供开发容器、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 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 78/100
voidzero-dev/oxc-angular-compiler#522 ·
维护者通常 1 天内回复
-
question
难度 5/5 一周以上 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#521 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 76/100
voidzero-dev/oxc-angular-compiler#520 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#518 ·
维护者通常 1 天内回复
查看 voidzero-dev/oxc-angular-compiler 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
zcashlabs/thus-spoke-zakura#153 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
topgrade-rs/topgrade#2395 ·
维护者通常 1 天内回复
-
app bug windows-os
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
matrix-org/matrix-rust-sdk#7217 ·
维护者通常 1 天内回复
-
editor good first issue
难度 2/5 1-3 小时 新手友好度 65/100
funnyboy-roks/inq#54 ·