Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Decide: `@Injectable` imported under an alias — ngtsc emits no `ɵfac`, OXC does

クローズ
#507 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
angular, rust, typescript
領域
compilers

調査の方向性

Compare the alias case in the issue with ngtsc’s needsFactory logic in packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts. Review the OXC output and decide whether to preserve its working factory or match ngtsc; if keeping OXC’s behavior, record the difference in napi/angular-compiler/e2e/compare/fixtures/known-differences.ts. Done means the behavior decision is reflected in the fixture list.

索引モデルが issue の本文から書いたものです。

説明

question

With #504, OXC finds Angular class decorators by their @angular/core import, so an aliased @Injectable is now compiled. ngtsc 22.1.7 compiles it differently. It looks like an ngtsc bug. This issue records the difference and asks whether we keep OXC's output.

Repro

import {Injectable as X} from '@angular/core';
@X({providedIn: 'root'})
export class S {}

ngtsc 22.1.7

export class S {
    static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: S, factory: S.ɵfac, providedIn: 'root' });
}
static ɵprov: i0.ɵɵInjectableDeclaration<any>;

No ɵfac and no setClassMetadata. ɵprov.factory points at S.ɵfac, which doesn't exist, so injecting S fails at runtime.

Cause, in packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts:

needsFactory:
  meta.decorators === null ||
  decorators.every((current) => !isAngularCore(current) || current.name === 'Injectable'),

current.name is the name as written (X), so an aliased import gives needsFactory = false. setClassMetadata is only emitted inside if (analysis.needsFactory), so it is dropped too.

OXC (#504 tip)

export class S {
static ɵfac = /*@__PURE__*/ (() =>{
  let ɵS_BaseFactory;
  return function S_Factory(__ngFactoryType__) {
    return (ɵS_BaseFactory || (ɵS_BaseFactory = i0.ɵɵgetInheritedFactory(S)))((__ngFactoryType__ || S));
  };
})();
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({token:S,factory:S.ɵfac,providedIn:"root"});
}
// + ɵsetClassMetadata(S,[{type:X,args:[{providedIn:"root"}]}],null,null)
static ɵfac: i0.ɵɵFactoryDeclaration<S, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<S>;

On main the aliased decorator is not recognized at all, so the class is left as written (@X({providedIn: 'root'}) export class S {}).

Decision needed

  • Keep OXC's output (a working factory). This is a known difference from ngtsc. Add it to napi/angular-compiler/e2e/compare/fixtures/known-differences.ts.
  • Or copy ngtsc's output exactly. That gives a broken ɵprov.

Recommendation: keep it, record the difference, and maybe report it upstream.

Note: the ɵgetInheritedFactory form and InjectableDeclaration<S> vs <any> also show up for a plain @Injectable() class with no constructor, on main too. Not specific to the alias.

主要言語
Rust
スター
232
フォーク
21
平均マージ
1日 16時間
マージ済み PR(30日)
62

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

voidzero-dev/oxc-angular-compiler のほかの issue

voidzero-dev/oxc-angular-compiler の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。