Skip to content

Commit 3a3ebbd

Browse files
authored
test(e2e): record the aliased-@Injectable emit difference (#560)
`import { Injectable as X }` + `@X(...)` compiles to a working `ɵfac` and setClassMetadata under Oxc; ngtsc's `needsFactory` check compares the written decorator name, so it emits only `ɵprov` pointing at a factory it never generated — an upstream bug (issue #507). Oxc keeps its output; this adds a fixture covering the case and documents the difference in known-differences.ts.
1 parent f7c2a73 commit 3a3ebbd

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Fixtures for Angular decorators imported under an alias.
3+
*
4+
* `import { Injectable as X }` + `@X(...)` is an Angular decorator to Oxc,
5+
* which resolves the import binding. ngtsc finds the decorator too, but its
6+
* `needsFactory` check (`injectable.ts`) compares the WRITTEN name
7+
* (`current.name === 'Injectable'`), so an aliased import compiles to a
8+
* broken `ɵprov` referencing a `ɵfac` it never emitted — an upstream bug.
9+
* See https://github.com/voidzero-dev/oxc-angular-compiler/issues/507.
10+
*/
11+
import type { Fixture } from '../types.js'
12+
13+
export const fixtures: Fixture[] = [
14+
{
15+
type: 'full-transform',
16+
name: 'aliased-injectable',
17+
category: 'edge-cases',
18+
description:
19+
'@Injectable imported under an alias — Oxc emits a working ɵfac and setClassMetadata; ngtsc emits only ɵprov pointing at a factory it never generated (upstream bug)',
20+
className: 'AliasedService',
21+
sourceCode: `
22+
import { Injectable as X } from '@angular/core';
23+
24+
@X({ providedIn: 'root' })
25+
export class AliasedService {}
26+
`.trim(),
27+
expectedFeatures: ['ɵɵdefineInjectable'],
28+
},
29+
]

‎napi/angular-compiler/e2e/compare/fixtures/known-differences.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const INJECTABLE_FACTORY_WRAPPER =
3333
'an @Injectable useFactory is wrapped in a function expression where Angular emits an arrow function'
3434
const SET_CLASS_METADATA_IMPORT =
3535
'Oxc keeps the @Inject import because its setClassMetadata references it; ngtsc emits the same reference but TypeScript elision still drops the import (upstream emit bug)'
36+
const ALIASED_INJECTABLE =
37+
'an aliased @Injectable compiles to a broken ɵprov under ngtsc — its needsFactory check compares the written decorator name, so the factory (and setClassMetadata) are never emitted; Oxc emits a working ɵfac (issue #507, kept deliberately)'
3638

3739
export const KNOWN_DIFFERENCES: Record<string, KnownDifference> = {
3840
'animations/animation-metadata-with-change-detection': {
@@ -107,6 +109,10 @@ export const KNOWN_DIFFERENCES: Record<string, KnownDifference> = {
107109
fields: ['DeferHydrateViewportComponent.ɵcmp'],
108110
reasons: [INCREMENTAL_HYDRATION],
109111
},
112+
'edge-cases/aliased-injectable': {
113+
fields: ['AliasedService.ɵfac'],
114+
reasons: [ALIASED_INJECTABLE],
115+
},
110116
'edge-cases/multiple-custom-decorators': {
111117
fields: ['MultiDecoratorComponent.ɵcmp', 'MultiDecoratorComponent.ɵfac'],
112118
reasons: [CUSTOM_DECORATOR],

0 commit comments

Comments
 (0)