fix(core): require factory to be provided for shakeable InjectionToken (#22207)
InjectionToken can be created with an ngInjectableDef, and previously this allowed the full expressiveness of @Injectable. However, this requires a runtime reflection system in order to generate factories from expressed provider declarations. Instead, this change requires scoped InjectionTokens to provide the factory directly (likely using inject() for the arguments), bypassing the need for a reflection system. Fixes #22205 PR Close #22207
This commit is contained in:

committed by
Victor Berchet

parent
5dd2b5135d
commit
f755db78dc
@ -48,12 +48,14 @@ export class InjectableCompiler {
|
||||
} else if (v.ngMetadataName === 'Self') {
|
||||
flags |= InjectFlags.Self;
|
||||
} else if (v.ngMetadataName === 'Inject') {
|
||||
throw new Error('@Inject() is not implemented');
|
||||
token = v.token;
|
||||
} else {
|
||||
token = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags !== InjectFlags.Default || defaultValue !== undefined) {
|
||||
args = [ctx.importExpr(token), o.literal(defaultValue), o.literal(flags)];
|
||||
} else {
|
||||
args = [ctx.importExpr(token)];
|
||||
|
Reference in New Issue
Block a user