refactor(ivy): do not generate providedIn: null (#34116)
We should only generate the `providedIn` property in injectable defs if it has a non-null value. `null` does not communicate any information to the runtime that isn't communicated already by the absence of the property. This should give us some modest code size savings. PR Close #34116
This commit is contained in:

committed by
Miško Hevery

parent
56f4e56094
commit
67eac733d2
@ -105,10 +105,16 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||
}
|
||||
|
||||
const token = meta.internalType;
|
||||
const providedIn = meta.providedIn;
|
||||
|
||||
const expression = o.importExpr(Identifiers.ɵɵdefineInjectable).callFn([mapToMapExpression(
|
||||
{token, factory: result.factory, providedIn})]);
|
||||
const injectableProps: {[key: string]: o.Expression} = {token, factory: result.factory};
|
||||
|
||||
// Only generate providedIn property if it has a non-null value
|
||||
if ((meta.providedIn as o.LiteralExpr).value !== null) {
|
||||
injectableProps.providedIn = meta.providedIn;
|
||||
}
|
||||
|
||||
const expression =
|
||||
o.importExpr(Identifiers.ɵɵdefineInjectable).callFn([mapToMapExpression(injectableProps)]);
|
||||
const type = new o.ExpressionType(o.importExpr(
|
||||
Identifiers.InjectableDef, [typeWithParameters(meta.type, meta.typeArgumentCount)]));
|
||||
|
||||
|
Reference in New Issue
Block a user