Skip to content

Commit 4bcd303

Browse files
NullVoxPopuliclaude
andcommitted
Clean up: fix stale comment, stronger test assertions, import order
- on.ts comment: "this.*" → "path read" since binding applies to all paths now - fn-test.ts: assert seenThis has expected property (arg1 === 'foo') instead of just non-null, matching reviewer feedback - expressions.ts: alphabetize imports Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 87d8b52 commit 4bcd303

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/@glimmer-workspace/integration-tests/test/helpers/fn-test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,25 @@ class FnTest extends RenderTest {
181181
'this context is available within the callback'(assert: Assert) {
182182
let seenThis: unknown;
183183

184-
this.render(`<Stash @stashedFn={{fn this.myFunc this.arg1}}/>`, {
184+
let context = {
185185
myFunc() {
186186
assert.step('calling stashed function');
187187
seenThis = this;
188188
},
189189

190190
arg1: 'foo',
191-
});
191+
};
192+
193+
this.render(`<Stash @stashedFn={{fn this.myFunc this.arg1}}/>`, context);
192194

193195
this.stashedFn?.();
194196
assert.verifySteps(['calling stashed function']);
195-
assert.ok(seenThis !== null && seenThis !== undefined, 'this is bound to the context');
197+
assert.ok(seenThis !== null && seenThis !== undefined, 'this is not null/undefined');
198+
assert.strictEqual(
199+
(seenThis as Record<string, unknown>)['arg1'],
200+
'foo',
201+
'this is bound to the object myFunc is defined on'
202+
);
196203
}
197204

198205
@test

packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import type { Reference } from '@glimmer/reference';
4545
import {
4646
childRefFor,
4747
createComputeRef,
48-
setBindingParentRef,
4948
FALSE_REFERENCE,
49+
setBindingParentRef,
5050
TRUE_REFERENCE,
5151
UNDEFINED_REFERENCE,
5252
valueForRef,

packages/@glimmer/runtime/lib/modifiers/on.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ export class OnModifierState {
183183
if (shouldUpdate) {
184184
let callback = userProvidedCallback;
185185

186-
// If the callback ref was created by VM_GET_PROPERTY_BOUND_OP (i.e. a
187-
// `this.*` path read), bind the callback to the parent object so that
188-
// class methods preserve their `this` context.
186+
// If the callback ref was created by VM_GET_PROPERTY_BOUND_OP (a path
187+
// read like `this.foo`, `o.method`, etc.), bind the callback to the
188+
// parent object so that methods preserve their `this` context.
189189
let bindingParentRef = arg1 ? getBindingParentRef(arg1) : undefined;
190190
if (bindingParentRef) {
191191
let parentValue = valueForRef(bindingParentRef);

0 commit comments

Comments
 (0)