Skip to content

Commit

Permalink
Merge pull request #18353 from patricklx/patch-1
Browse files Browse the repository at this point in the history
[BUGFIX beta] improve `fn` & `on` undefined callback message
  • Loading branch information
rwjblue authored Apr 13, 2020
2 parents 4945a71 + f6f9f52 commit f36a2cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/@ember/-internals/glimmer/lib/helpers/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ function fn({ positional }: CapturedArguments) {
if (DEBUG && typeof callbackRef[INVOKE] !== 'function') {
let callback = callbackRef.value();

const debug = (<any>callbackRef).debug && (<any>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'
);
}
Expand Down
12 changes: 8 additions & 4 deletions packages/@ember/-internals/glimmer/lib/modifiers/on.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ export class OnModifierState {
this.eventName = eventName;
this.shouldUpdate = true;
}
if (DEBUG) {
const debug = args.positional.at(1) && (<any>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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'(
Expand Down

0 comments on commit f36a2cc

Please sign in to comment.