fix(ng_module): `ɵfac` ignores `@Inject(TOKEN)` on `@NgModule` constructor parameters
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 76/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- rust, typescript
- Domínio
- compilers
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Rust
- Estrelas
- 232
- Forks
- 21
- Merge médio
- 2d 14h
- PRs com merge (30d)
- 30
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de voidzero-dev/oxc-angular-compiler
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
voidzero-dev/oxc-angular-compiler#511 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 78/100
voidzero-dev/oxc-angular-compiler#522 ·
Mantenedores costumam responder em até 1 dia
-
question
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
voidzero-dev/oxc-angular-compiler#521 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 76/100
voidzero-dev/oxc-angular-compiler#520 ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
voidzero-dev/oxc-angular-compiler#518 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de voidzero-dev/oxc-angular-compiler
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
pyca/verified-garbage#1023 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 74/100
-
review-drift
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
oxidecomputer/hansei#14 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
rubys/roundhouse#444 ·
Mantenedores costumam responder em até 1 dia
-
Published hardy-bpa-server image is built without the file-cla featureTalvez já em andamento @EmbryoSpace assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
ricktaylor/hardy#755 ·
Mantenedores costumam responder em até 1 dia