Skip to content

Commit b7462c6

Browse files
fix(vite-plugin-angular): reject @service on Angular below 22
Addresses CodeRabbit review feedback. When a `@Service` class was compiled against Angular <22, the version gate did a bare `break`, leaving `targetType` at its `FactoryTarget.Injectable` default — the unconditional factory block then emitted an `Injectable`-target `ɵfac` with no `ɵprov`, a silently wrong half-compiled class. `@Service` does not exist before Angular 22, so this is a broken configuration. Set `classCompileError` instead, surfacing a clear `@Service requires Angular 22 or later` error before factory emission rather than degrading silently. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 328d800 commit b7462c6

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • packages/vite-plugin-angular/src/lib/compiler

packages/vite-plugin-angular/src/lib/compiler/compile.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,15 @@ export function compile(
974974

975975
case 'Service': {
976976
// `@Service` (and the `compileService` compiler API) landed in
977-
// Angular 22. Skip on older peers where the API is absent.
978-
if (!angularVersionAtLeast(22)) break;
977+
// Angular 22. On older peers the decorator does not exist; fail
978+
// loudly rather than falling through and emitting a default
979+
// `Injectable`-target factory with no `ɵprov`.
980+
if (!angularVersionAtLeast(22)) {
981+
classCompileError = new Error(
982+
`[fast-compile] @Service on ${className} requires Angular 22 or later`,
983+
);
984+
break;
985+
}
979986
targetType = (FactoryTarget as any).Service;
980987
const serviceMeta: any = {
981988
name: className,

0 commit comments

Comments
 (0)