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
平均合併
1 天 23 小時
30 天內合併 PR
53

環境準備

這個專案沒有提供開發容器、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 摘要。