diff --git a/packages/compiler-cli/src/ngtsc/translator/src/translator.ts b/packages/compiler-cli/src/ngtsc/translator/src/translator.ts index e9d2780c7f..0005d506c8 100644 --- a/packages/compiler-cli/src/ngtsc/translator/src/translator.ts +++ b/packages/compiler-cli/src/ngtsc/translator/src/translator.ts @@ -185,9 +185,13 @@ class ExpressionTranslatorVisitor implements ExpressionVisitor, StatementVisitor } visitInvokeFunctionExpr(ast: InvokeFunctionExpr, context: Context): ts.CallExpression { - return ts.createCall( + const expr = ts.createCall( ast.fn.visitExpression(this, context), undefined, ast.args.map(arg => arg.visitExpression(this, context))); + if (ast.pure) { + ts.addSyntheticLeadingComment(expr, ts.SyntaxKind.MultiLineCommentTrivia, '@__PURE__', false); + } + return expr; } visitInstantiateExpr(ast: InstantiateExpr, context: Context): ts.NewExpression { diff --git a/packages/compiler/src/output/output_ast.ts b/packages/compiler/src/output/output_ast.ts index 7ab2775400..7b456e89d6 100644 --- a/packages/compiler/src/output/output_ast.ts +++ b/packages/compiler/src/output/output_ast.ts @@ -424,13 +424,13 @@ export class InvokeMethodExpr extends Expression { export class InvokeFunctionExpr extends Expression { constructor( public fn: Expression, public args: Expression[], type?: Type|null, - sourceSpan?: ParseSourceSpan|null) { + sourceSpan?: ParseSourceSpan|null, public pure = false) { super(type, sourceSpan); } isEquivalent(e: Expression): boolean { return e instanceof InvokeFunctionExpr && this.fn.isEquivalent(e.fn) && - areAllEquivalent(this.args, e.args); + areAllEquivalent(this.args, e.args) && this.pure === e.pure; } isConstant() { return false; }