Skip to content

Commit fd55d36

Browse files
patricklxkategengler
authored andcommitted
improve fn & on undefined callback message
(cherry picked from commit f6f9f52)
1 parent 67782d4 commit fd55d36

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/@ember/-internals/glimmer/lib/helpers/fn.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ function fn({ positional }: CapturedArguments) {
8585
if (DEBUG && typeof callbackRef[INVOKE] !== 'function') {
8686
let callback = callbackRef.value();
8787

88+
const debug = (<any>callbackRef).debug && (<any>callbackRef).debug();
8889
assert(
89-
`You must pass a function as the \`fn\` helpers first argument, you passed ${callback}`,
90+
`You must pass a function as the \`fn\` helpers first argument, you passed ${debug} to \`fn\` but it was ${callback}`,
9091
typeof callback === 'function'
9192
);
9293
}

packages/@ember/-internals/glimmer/lib/modifiers/on.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ export class OnModifierState {
100100
this.eventName = eventName;
101101
this.shouldUpdate = true;
102102
}
103+
if (DEBUG) {
104+
const debug = args.positional.at(1) && (<any>args.positional.at(1)).debug();
105+
const value = args.positional.at(1) && args.positional.at(1).value();
106+
assert(
107+
`You must pass a function as the second argument to the \`on\` modifier, you passed ${debug} to \`on\` but it was ${value}`,
108+
value !== undefined && typeof value === 'function'
109+
);
110+
}
103111

104-
assert(
105-
'You must pass a function as the second argument to the `on` modifier',
106-
args.positional.at(1) !== undefined && typeof args.positional.at(1).value() === 'function'
107-
);
108112
let userProvidedCallback = args.positional.at(1).value() as EventListener;
109113
if (userProvidedCallback !== this.userProvidedCallback) {
110114
this.userProvidedCallback = userProvidedCallback;

packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ moduleFor(
127127
arg1: 'foo',
128128
arg2: 'bar',
129129
});
130-
}, /You must pass a function as the `fn` helpers first argument, you passed null/);
130+
}, /You must pass a function as the `fn` helpers first argument, you passed this.myFunc to `fn` but it was null/);
131131
}
132132

133133
'@test asserts if the provided function accesses `this` without being bound prior to passing to fn'(

0 commit comments

Comments
 (0)