From 188ff848d261bee62b828ed94d6772172853b6d5 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 22 May 2018 10:47:50 -0700 Subject: [PATCH] fix(ivy): `pureFunctionV` takes an array of values (#24039) PR Close #24039 --- .../compiler/src/render3/view/template.ts | 27 +++++++++++++++---- .../render3/r3_compiler_compliance_spec.ts | 2 +- .../hello_world_r2/bundle.golden_symbols.json | 3 +++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/compiler/src/render3/view/template.ts b/packages/compiler/src/render3/view/template.ts index c6dbadfe54..d50dbb1f2c 100644 --- a/packages/compiler/src/render3/view/template.ts +++ b/packages/compiler/src/render3/view/template.ts @@ -574,6 +574,15 @@ const pureFunctionIdentifiers = [ R3.pureFunction0, R3.pureFunction1, R3.pureFunction2, R3.pureFunction3, R3.pureFunction4, R3.pureFunction5, R3.pureFunction6, R3.pureFunction7, R3.pureFunction8 ]; + +function pureFunctionCallInfo(args: o.Expression[]) { + const identifier = pureFunctionIdentifiers[args.length]; + return { + identifier: identifier || R3.pureFunctionV, + isVarLength: !identifier, + }; +} + function getLiteralFactory( constantPool: ConstantPool, literal: o.LiteralArrayExpr | o.LiteralMapExpr, allocateSlots: (numSlots: number) => number): o.Expression { @@ -581,14 +590,22 @@ function getLiteralFactory( // Allocate 1 slot for the result plus 1 per argument const startSlot = allocateSlots(1 + literalFactoryArguments.length); literalFactoryArguments.length > 0 || error(`Expected arguments to a literal factory function`); - let pureFunctionIdent = - pureFunctionIdentifiers[literalFactoryArguments.length] || R3.pureFunctionV; + const {identifier, isVarLength} = pureFunctionCallInfo(literalFactoryArguments); // Literal factories are pure functions that only need to be re-invoked when the parameters // change. - return o.importExpr(pureFunctionIdent).callFn([ - o.literal(startSlot), literalFactory, ...literalFactoryArguments - ]); + const args = [ + o.literal(startSlot), + literalFactory, + ]; + + if (isVarLength) { + args.push(o.literalArr(literalFactoryArguments)); + } else { + args.push(...literalFactoryArguments); + } + + return o.importExpr(identifier).callFn(args); } /** diff --git a/packages/compiler/test/render3/r3_compiler_compliance_spec.ts b/packages/compiler/test/render3/r3_compiler_compliance_spec.ts index 3c8c9935e9..44af890457 100644 --- a/packages/compiler/test/render3/r3_compiler_compliance_spec.ts +++ b/packages/compiler/test/render3/r3_compiler_compliance_spec.ts @@ -548,7 +548,7 @@ describe('compiler compliance', () => { if (rf & 2) { $r3$.ɵp( 0, 'names', - $r3$.ɵb($r3$.ɵfV(10, $e0_ff$, ctx.n0, ctx.n1, ctx.n2, ctx.n3, ctx.n4, ctx.n5, ctx.n6, ctx.n7, ctx.n8))); + $r3$.ɵb($r3$.ɵfV(10, $e0_ff$, [ctx.n0, ctx.n1, ctx.n2, ctx.n3, ctx.n4, ctx.n5, ctx.n6, ctx.n7, ctx.n8]))); } }, directives: [MyComp] diff --git a/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json index c792f20640..c35362fae4 100644 --- a/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json @@ -3662,6 +3662,9 @@ { "name": "pureArrayDef" }, + { + "name": "pureFunctionCallInfo" + }, { "name": "pureFunctionIdentifiers" },