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:
Charles Lyding
2020-07-29 15:31:27 -04:00
committed by Alex Rickabaugh
parent 4c7f233fa8
commit 6f6102d8ad
4 changed files with 12 additions and 7 deletions

View File

@ -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):

View File

@ -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);