From f6f9f5210754155c8d081a65d78f37a561d928f7 Mon Sep 17 00:00:00 2001 From: patricklx Date: Wed, 4 Sep 2019 09:11:11 +0200 Subject: [PATCH] improve fn & on undefined callback message --- packages/@ember/-internals/glimmer/lib/helpers/fn.ts | 3 ++- .../@ember/-internals/glimmer/lib/modifiers/on.ts | 12 ++++++++---- .../glimmer/tests/integration/helpers/fn-test.js | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/@ember/-internals/glimmer/lib/helpers/fn.ts b/packages/@ember/-internals/glimmer/lib/helpers/fn.ts index 443258afca6..21b71a0c6f5 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/fn.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/fn.ts @@ -86,8 +86,9 @@ function fnHelper({ positional }: ICapturedArguments) { if (DEBUG && typeof callbackRef[INVOKE] !== 'function') { let callback = callbackRef.value(); + const debug = (callbackRef).debug && (callbackRef).debug(); assert( - `You must pass a function as the \`fn\` helpers first argument, you passed ${callback}`, + `You must pass a function as the \`fn\` helpers first argument, you passed ${debug} to \`fn\` but it was ${callback}`, typeof callback === 'function' ); } diff --git a/packages/@ember/-internals/glimmer/lib/modifiers/on.ts b/packages/@ember/-internals/glimmer/lib/modifiers/on.ts index d74bc39ae38..3364c76fbdd 100644 --- a/packages/@ember/-internals/glimmer/lib/modifiers/on.ts +++ b/packages/@ember/-internals/glimmer/lib/modifiers/on.ts @@ -101,11 +101,15 @@ export class OnModifierState { this.eventName = eventName; this.shouldUpdate = true; } + if (DEBUG) { + const debug = args.positional.at(1) && (args.positional.at(1)).debug(); + const value = args.positional.at(1) && args.positional.at(1).value(); + assert( + `You must pass a function as the second argument to the \`on\` modifier, you passed ${debug} to \`on\` but it was ${value}`, + value !== undefined && typeof value === 'function' + ); + } - assert( - 'You must pass a function as the second argument to the `on` modifier', - args.positional.at(1) !== undefined && typeof args.positional.at(1).value() === 'function' - ); let userProvidedCallback = args.positional.at(1).value() as EventListener; if (userProvidedCallback !== this.userProvidedCallback) { this.userProvidedCallback = userProvidedCallback; 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 24a3e7581ff..2a12e852a85 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js @@ -127,7 +127,7 @@ moduleFor( arg1: 'foo', arg2: 'bar', }); - }, /You must pass a function as the `fn` helpers first argument, you passed null/); + }, /You must pass a function as the `fn` helpers first argument, you passed this.myFunc to `fn` but it was null/); } '@test asserts if the provided function accesses `this` without being bound prior to passing to fn'(