Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa
#507 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
angular, rust, typescript
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
232
Fork
21
Merge medio
1g 16h
PR unite (30g)
62

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di voidzero-dev/oxc-angular-compiler

Tutte le issue di voidzero-dev/oxc-angular-compiler

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.