Decide: two `@Component` on one class — ngtsc compiles the first with no error; OXC's HMR text scan pairs the second
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- angular, rust, typescript
- Domínio
- build-system, tooling
Direção de pesquisa
Start with the two-decorator reproduction and compare ngtsc and OXC output and runtime behavior. Read crates/oxc_angular_compiler/src/component/transform.rs, napi/angular-compiler/vite-plugin/utils/decorator-fields.ts, and napi/angular-compiler/vite-plugin/index.ts; done requires an agreed option and matching compiler metadata and HMR behavior.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
import {Component} from '@angular/core';
@Component({selector: 'a-cmp', template: 'first'})
@Component({selector: 'b-cmp', template: 'second'})
export class C {}
ngtsc 22.1.7 gives no diagnostic. It compiles the first @Component and leaves the second as a runtime decorator. At runtime that second decorator replaces ɵcmp with a JIT getter, so the module crashes on load without @angular/compiler. Same with OXC's output. So the input is broken under both compilers, and there is no ngtsc error for OXC to copy.
OXC still differs from ngtsc in two small ways. Opening this to decide whether either is worth fixing.
Compile output
OXC (#504 tip and main, same output):
@Component({selector: 'b-cmp', template: 'second'})
export class C {
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:C,selectors:[["a-cmp"]], ... i0.ɵɵtext(0,"first") ...});
}
... i0.ɵsetClassMetadata(C,[{type:Component,args:[{selector:"a-cmp",template:"first"}]}],null,null)
ngtsc 22.1.7:
let C = class C {
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: C, selectors: [["a-cmp"]], ... i0.ɵɵtext(0, "first") ... });
};
C = __decorate([
Component({ selector: 'b-cmp', template: 'second' })
], C);
... i0.ɵsetClassMetadata(C, [{
type: Component,
args: [{ selector: 'a-cmp', template: 'first' }]
}, {
type: Component,
args: [{ selector: 'b-cmp', template: 'second' }]
}], null, null)
Both compile the first decorator and keep the second. Difference 1: ngtsc's setClassMetadata lists both decorators, OXC's lists only the compiled one.
Runtime (node, @angular/core 22.1.7, no @angular/compiler), both outputs:
Error: The component 'C' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
HMR (Vite plugin)
Rust reports componentDecorators = {"c.ts@C": "Component"}, and templateUpdates["c.ts@C"] is the template of the first decorator (ɵɵtext(0,"first")).
stripComponentMetadata empties the template: / styles: of the decorator locateComponentDecorators pairs with C. Pass 2 of that scan looks for class X only between one decorator's ) and the next decorator's @, so the first @Component pairs with no class and the second one gets C. Difference 2: the plugin empties the decorator the compiler did not take:
pairs: [["C","({selector: 'b-cmp', template: 'second'})"]]
edit first (compiled) -> stripped forms differ => full reload
edit second (not compiled) -> stripped forms equal => HMR event, but the update holds the first template, so nothing changes
(Checked by running the real decorator-fields.ts functions and a copy of stripComponentMetadata with oxnode. Same pairing on main, where the scan only looks for the literal @Component(.)
Where
crates/oxc_angular_compiler/src/component/transform.rs:find_component_decoratortakes the first match (same as ngtsc);component_decoratorsreports only its callee text, not its position.napi/angular-compiler/vite-plugin/utils/decorator-fields.ts:locateComponentDecorators, pass 2 (bounded class-name scan).napi/angular-compiler/vite-plugin/index.ts:stripComponentMetadatakeys the decorators by class name, so two same-spelled decorators on one class can't be told apart.
On main?
Yes (both differences). componentDecorators itself is only on the #504 stack (d1fa6c4).
Options
- Leave as is: the input already crashes at runtime with ngtsc too.
- Report the compiled decorator's span (not only its spelling) in
componentDecorators, so the plugin empties exactly that one. - List every class decorator in
setClassMetadata, like ngtsc. - Add a warning for a second Angular class decorator of the same kind (ngtsc has none, so this would go beyond ngtsc).
- Linguagem predominante
- Rust
- Estrelas
- 240
- Forks
- 24
- Merge médio
- 1d 16h
- PRs com merge (30d)
- 72
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
-
Linker always uses the latest security schema: `img|src`/`video|src` sanitizers dropped for Angular < 22.2.2Talvez já em andamento @edbzn assumiu há 1 dia. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
voidzero-dev/oxc-angular-compiler#586 ·
Mantenedores costumam responder em até 1 dia
-
`$safeNavigationMigration(...)` in an event listener reads template locals from the wrong contextTalvez já em andamento @edbzn assumiu há 1 dia. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
voidzero-dev/oxc-angular-compiler#585 ·
Mantenedores costumam responder em até 1 dia
-
fix(directive): input names with lone surrogates are emitted in oxc's internal U+FFFD encodingAbertabug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 68/100
voidzero-dev/oxc-angular-compiler#505 ·
Mantenedores costumam responder em até 1 dia
-
bug rust
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 56/100
voidzero-dev/oxc-angular-compiler#313 ·
Mantenedores costumam responder em até 1 dia
-
Support useDefineForClassFields: false (Class Field Lowering)Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
voidzero-dev/oxc-angular-compiler#73 · 11 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de voidzero-dev/oxc-angular-compiler
Issues semelhantes
-
meta.json, text.txt and try JSON are written non-atomicallyTalvez já em andamento @qwertymuzaffar assumiu hoje. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
qwertymuzaffar/parrot#47 ·
Mantenedores costumam responder em até 1 dia
-
Alt select PhotocraftAbertapriority: medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
storytold/photocraft#8041 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
fmt -p: an unprefixed last line without a newline gets one addedTalvez já em andamento @fixfon assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
jhspetersson/fselect#187 ·
-
documentation good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
writerslogic/holographic-memory#96 ·
Mantenedores costumam responder em até 1 dia