fix(compiler): add PURE annotation to getInheritedFactory calls (#38291)
Currently the `getInheritedFactory` function is implemented to allow closure to remove the call if the base factory is unused. However, this method does not work with terser. By adding the PURE annotation, terser will also be able to remove the call when unused. PR Close #38291
This commit is contained in:

committed by
Alex Rickabaugh

parent
1de4fe5dbf
commit
03d8e317c4
@ -176,8 +176,9 @@ export abstract class Expression {
|
||||
return new InvokeMethodExpr(this, name, params, null, sourceSpan);
|
||||
}
|
||||
|
||||
callFn(params: Expression[], sourceSpan?: ParseSourceSpan|null): InvokeFunctionExpr {
|
||||
return new InvokeFunctionExpr(this, params, null, sourceSpan);
|
||||
callFn(params: Expression[], sourceSpan?: ParseSourceSpan|null, pure?: boolean):
|
||||
InvokeFunctionExpr {
|
||||
return new InvokeFunctionExpr(this, params, null, sourceSpan, pure);
|
||||
}
|
||||
|
||||
instantiate(params: Expression[], type?: Type|null, sourceSpan?: ParseSourceSpan|null):
|
||||
|
@ -212,7 +212,9 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3FactoryFn {
|
||||
const baseFactory = o.variable(`ɵ${meta.name}_BaseFactory`);
|
||||
const getInheritedFactory = o.importExpr(R3.getInheritedFactory);
|
||||
const baseFactoryStmt =
|
||||
baseFactory.set(getInheritedFactory.callFn([meta.internalType]))
|
||||
baseFactory
|
||||
.set(getInheritedFactory.callFn(
|
||||
[meta.internalType], /* sourceSpan */ undefined, /* pure */ true))
|
||||
.toDeclStmt(o.INFERRED_TYPE, [o.StmtModifier.Exported, o.StmtModifier.Final]);
|
||||
statements.push(baseFactoryStmt);
|
||||
|
||||
|
Reference in New Issue
Block a user