Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

fix(ng_module): `ɵfac` ignores `@Inject(TOKEN)` on `@NgModule` constructor parameters

未关闭
#519 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 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 内容生成。

描述

bug

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 @Inject token, 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/oxc-angular-compiler 的其他 Issue

查看 voidzero-dev/oxc-angular-compiler 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。