File tree Expand file tree Collapse file tree
packages/@glimmer/runtime/lib/modifiers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import {
1414 CheckString ,
1515 CheckUndefined ,
1616} from '@glimmer/debug' ;
17- import { buildUntouchableThis , localAssert } from '@glimmer/debug-util' ;
17+ import { buildUntouchableThis } from '@glimmer/debug-util' ;
1818import { registerDestructor } from '@glimmer/destroyable' ;
1919import { setInternalModifierManager } from '@glimmer/manager' ;
2020import { valueForRef } from '@glimmer/reference' ;
@@ -57,13 +57,16 @@ export class OnModifierState {
5757 updateListener ( ) : void {
5858 let { element, args, listener } = this ;
5959
60- localAssert (
61- args . positional [ 0 ] ,
62- 'You must pass a valid DOM event name as the first argument to the `on` modifier'
63- ) ;
60+ let arg0 = args . positional [ 0 ] ;
61+
62+ if ( DEBUG && ! arg0 ) {
63+ throw new Error (
64+ 'You must pass a valid DOM event name as the first argument to the `on` modifier'
65+ ) ;
66+ }
6467
6568 let eventName = check (
66- valueForRef ( args . positional [ 0 ] ) ,
69+ arg0 ? valueForRef ( arg0 ) : undefined ,
6770 CheckString ,
6871 ( ) => 'You must pass a valid DOM event name as the first argument to the `on` modifier'
6972 ) ;
Original file line number Diff line number Diff line change @@ -285,7 +285,7 @@ function basicTest(scenarios: Scenarios, appName: string) {
285285 resetOnerror();
286286 });
287287
288- test('throws helpful error when callback is undefined ', async function (assert) {
288+ test('throws helpful error when callback is missing ', async function (assert) {
289289 assert.expect(1);
290290 const noop = undefined;
291291 setupOnerror((error) => {
@@ -297,16 +297,16 @@ function basicTest(scenarios: Scenarios, appName: string) {
297297 await render(<template><div {{on "click" noop}}>Click</div></template>);
298298 });
299299
300- test('throws helpful error when callback is null ', async function (assert) {
300+ test('throws helpful error when event name is missing ', async function (assert) {
301301 assert.expect(1);
302- const noop = null ;
302+ const noop = () => {} ;
303303 setupOnerror((error) => {
304304 assert.true(
305- /You must pass a function as the second argument to the \`on\` modifier/.test(error.message),
305+ /You must pass a valid DOM event name as the first argument to the \`on\` modifier/.test(error.message),
306306 'Expected helpful error message, got: ' + error.message
307307 );
308308 });
309- await render(<template><div {{on "click" noop }}>Click</div></template>);
309+ await render(<template><div {{on}}>Click</div></template>);
310310 });
311311 });
312312 ` ,
You can’t perform that action at this time.
0 commit comments