From 4047c0a8707c17006f812700041c8d2215e76bb1 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 23 Apr 2019 18:33:38 -0400 Subject: [PATCH 1/2] [FEATURE] Ensure `fn` can be nested. --- .../-internals/glimmer/lib/helpers/fn.ts | 5 +-- .../tests/integration/helpers/fn-test.js | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/@ember/-internals/glimmer/lib/helpers/fn.ts b/packages/@ember/-internals/glimmer/lib/helpers/fn.ts index 3a0474514b9..aae4a13e818 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/fn.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/fn.ts @@ -4,6 +4,7 @@ import { DEBUG } from '@glimmer/env'; import { Arguments, VM } from '@glimmer/runtime'; import { ICapturedArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; import { InternalHelperReference } from '../utils/references'; +import { Opaque } from '@glimmer/util'; let context: any = null; if (DEBUG && HAS_NATIVE_PROXY) { @@ -45,10 +46,10 @@ function fnHelper({ positional }: ICapturedArguments) { typeof positional.at(0).value() === 'function' ); - return () => { + return (...invocationArgs: Opaque[]) => { let [fn, ...args] = positional.value(); - return fn!['apply'](context, args); + return fn!['call'](context, ...args, ...invocationArgs); }; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js index 03b81dfee1d..3c38cea437b 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js @@ -158,6 +158,38 @@ if (EMBER_GLIMMER_FN_HELPER) { assert.equal(this.stashedFn(), 'arg1: foo, arg2: bar'); } + + '@test partially applies each layer when nested [GH#17959]'() { + this.render(`{{invoke (fn (fn (fn this.myFunc this.arg1) this.arg2) this.arg3)}}`, { + myFunc(arg1, arg2, arg3) { + return `arg1: ${arg1}, arg2: ${arg2}, arg3: ${arg3}`; + }, + + arg1: 'foo', + arg2: 'bar', + arg3: 'qux', + }); + + this.assertText('arg1: foo, arg2: bar, arg3: qux'); + this.assertStableRerender(); + + runTask(() => set(this.context, 'arg1', 'qux')); + this.assertText('arg1: qux, arg2: bar, arg3: qux'); + + runTask(() => set(this.context, 'arg2', 'derp')); + this.assertText('arg1: qux, arg2: derp, arg3: qux'); + + runTask(() => set(this.context, 'arg3', 'huzzah')); + this.assertText('arg1: qux, arg2: derp, arg3: huzzah'); + + runTask(() => { + set(this.context, 'arg1', 'foo'); + set(this.context, 'arg2', 'bar'); + set(this.context, 'arg3', 'qux'); + }); + + this.assertText('arg1: foo, arg2: bar, arg3: qux'); + } } ); } From 33fdfdc02c8adf9eaace5ac223b2ed2d072984bb Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Wed, 24 Apr 2019 10:09:12 +0100 Subject: [PATCH 2/2] Fix import ordering lint --- packages/@ember/-internals/glimmer/lib/helpers/fn.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ember/-internals/glimmer/lib/helpers/fn.ts b/packages/@ember/-internals/glimmer/lib/helpers/fn.ts index aae4a13e818..9843f77604c 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/fn.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/fn.ts @@ -3,8 +3,8 @@ import { assert } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; import { Arguments, VM } from '@glimmer/runtime'; import { ICapturedArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; -import { InternalHelperReference } from '../utils/references'; import { Opaque } from '@glimmer/util'; +import { InternalHelperReference } from '../utils/references'; let context: any = null; if (DEBUG && HAS_NATIVE_PROXY) {