From 544d2223d6101c7b3aa7ada3f581b815e12dd507 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 25 Jun 2024 14:11:12 +0200 Subject: [PATCH 01/12] fix arrow modifiers debug name currently arrow functions or functions without name as displayed with their whole implementation --- packages/@glimmer/manager/lib/public/modifier.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index ad598d31c..201138dd4 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -119,9 +119,9 @@ export class CustomModifierManager getDebugName(definition: object) { if (typeof definition === 'function') { - return definition.name || definition.toString(); + return definition.name || ''; } else { - return ''; + return definition.toString() || ''; } } From 56d14542ff3c93297c0e46248f1243442deeff33 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 25 Jun 2024 14:30:09 +0200 Subject: [PATCH 02/12] allow if custom toString --- packages/@glimmer/manager/lib/public/modifier.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index 201138dd4..b0196ba3c 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -119,6 +119,9 @@ export class CustomModifierManager getDebugName(definition: object) { if (typeof definition === 'function') { + if (definition.toString !== Function.toString) { + return definition.toString(); + } return definition.name || ''; } else { return definition.toString() || ''; From c66cae854276ccd694b7fc861e7eda7fcb8285d3 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Wed, 26 Jun 2024 17:10:46 +0200 Subject: [PATCH 03/12] delegate call to delegate --- packages/@glimmer/manager/lib/public/modifier.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index b0196ba3c..4a5fae7f8 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -117,7 +117,11 @@ export class CustomModifierManager return state; } - getDebugName(definition: object) { + getDebugName(owner: O, definition: object) { + let delegate = this.getDelegateFor(owner); + if (typeof delegate.getDebugName === 'function') { + return delegate.getDebugName(definition); + } if (typeof definition === 'function') { if (definition.toString !== Function.toString) { return definition.toString(); @@ -128,8 +132,12 @@ export class CustomModifierManager } } - getDebugInstance({ modifier }: CustomModifierState) { - return modifier; + getDebugInstance(owner: O, state: CustomModifierState) { + let delegate = this.getDelegateFor(owner); + if (typeof delegate.getDebugInstance === 'function') { + return delegate.getDebugInstance(state); + } + return state.modifier; } getTag({ tag }: CustomModifierState) { From 3c7f0de9e58af0ff33921c436e1aa33c1d1b2dc8 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Wed, 26 Jun 2024 17:12:25 +0200 Subject: [PATCH 04/12] pass owner --- packages/@glimmer/runtime/lib/compiled/opcodes/component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts index 655c4e52f..b091e556d 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts @@ -504,8 +504,8 @@ export class ComponentElementOperations implements ElementOperations { } let { element, constructing } = vm.elements(); - let name = manager.getDebugName(definition.state); - let instance = manager.getDebugInstance(state); + let name = manager.getDebugName(vm.owner(), definition.state); + let instance = manager.getDebugInstance(vm.owner(), state); assert(constructing, `Expected a constructing element in addModifier`); From b32c9470fd08ba2e7a8913e0ae26e4d77719ea16 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Wed, 26 Jun 2024 17:18:33 +0200 Subject: [PATCH 05/12] use name --- packages/@glimmer/manager/lib/public/modifier.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index 4a5fae7f8..a56d4bde6 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -122,14 +122,7 @@ export class CustomModifierManager if (typeof delegate.getDebugName === 'function') { return delegate.getDebugName(definition); } - if (typeof definition === 'function') { - if (definition.toString !== Function.toString) { - return definition.toString(); - } - return definition.name || ''; - } else { - return definition.toString() || ''; - } + return definition.name || ''; } getDebugInstance(owner: O, state: CustomModifierState) { From 2d678375d0212bbf6289047b272d0c398d70c631 Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Wed, 26 Jun 2024 17:41:55 +0200 Subject: [PATCH 06/12] fix types --- .../integration-tests/test/debug-render-tree-test.ts | 4 ++++ .../interfaces/lib/managers/internal/modifier.d.ts | 2 +- .../@glimmer/interfaces/lib/managers/modifier.d.ts | 2 ++ packages/@glimmer/manager/lib/public/modifier.ts | 10 +++++----- .../@glimmer/runtime/lib/compiled/opcodes/component.ts | 4 ++-- packages/@glimmer/runtime/lib/environment.ts | 4 ++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts b/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts index 6c8dbf24a..fa0a9761e 100644 --- a/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts @@ -340,6 +340,10 @@ class DebugRenderTreeTest extends RenderTest { didInsertElement() {} didUpdate() {} willDestroyElement() {} + + getDebugName() { + return 'did-insert' + } } this.registerModifier('did-insert', DidInsertModifier); diff --git a/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts b/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts index b717072d2..7aea472c9 100644 --- a/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts +++ b/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts @@ -22,7 +22,7 @@ export interface InternalModifierManager< // the modifier's update hooks need to be called (if at all). getTag(modifier: TModifierInstanceState): UpdatableTag | null; - getDebugName(Modifier: TModifierDefinitionState): string; + getDebugName(Modifier: TModifierDefinitionState, definition: object): string; getDebugInstance(Modifier: TModifierInstanceState): unknown; // At initial render, the modifier gets a chance to install itself on the diff --git a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts index 1c078905d..fc014ada5 100644 --- a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts +++ b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts @@ -19,4 +19,6 @@ export interface ModifierManager { installModifier(instance: ModifierStateBucket, element: Element, args: Arguments): void; updateModifier(instance: ModifierStateBucket, args: Arguments): void; destroyModifier(instance: ModifierStateBucket, args: Arguments): void; + getDebugName?(instance: object): string; + getDebugInstance?(instance: object): any; } diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index a56d4bde6..537d92dd8 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -117,16 +117,16 @@ export class CustomModifierManager return state; } - getDebugName(owner: O, definition: object) { - let delegate = this.getDelegateFor(owner); + getDebugName(state: CustomModifierState, definition: object) { + let delegate = state.delegate; if (typeof delegate.getDebugName === 'function') { return delegate.getDebugName(definition); } - return definition.name || ''; + return (definition as any).name || ''; } - getDebugInstance(owner: O, state: CustomModifierState) { - let delegate = this.getDelegateFor(owner); + getDebugInstance(state: CustomModifierState) { + let delegate = state.delegate; if (typeof delegate.getDebugInstance === 'function') { return delegate.getDebugInstance(state); } diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts index b091e556d..332cdd56a 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts @@ -504,8 +504,8 @@ export class ComponentElementOperations implements ElementOperations { } let { element, constructing } = vm.elements(); - let name = manager.getDebugName(vm.owner(), definition.state); - let instance = manager.getDebugInstance(vm.owner(), state); + let name = manager.getDebugName(state, definition.state); + let instance = manager.getDebugInstance(state); assert(constructing, `Expected a constructing element in addModifier`); diff --git a/packages/@glimmer/runtime/lib/environment.ts b/packages/@glimmer/runtime/lib/environment.ts index 46a1b5a18..d132c21b5 100644 --- a/packages/@glimmer/runtime/lib/environment.ts +++ b/packages/@glimmer/runtime/lib/environment.ts @@ -65,7 +65,7 @@ class TransactionImpl implements Transaction { () => manager.install(state), import.meta.env.DEV && `- While rendering:\n (instance of a \`${ - definition.resolvedName || manager.getDebugName(definition.state) + definition.resolvedName || manager.getDebugName(state as any, definition.state) }\` modifier)` ); updateTag(modifierTag, tag); @@ -82,7 +82,7 @@ class TransactionImpl implements Transaction { () => manager.update(state), import.meta.env.DEV && `- While rendering:\n (instance of a \`${ - definition.resolvedName || manager.getDebugName(definition.state) + definition.resolvedName || manager.getDebugName(state as any, definition.state) }\` modifier)` ); updateTag(modifierTag, tag); From 8105426d3084be03f4f83033fd8e19cbc941d47d Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Wed, 26 Jun 2024 17:46:37 +0200 Subject: [PATCH 07/12] fix test --- packages/@glimmer-workspace/integration-tests/lib/modifiers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts b/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts index eb0e26717..d255d6fe9 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts @@ -44,7 +44,7 @@ export class TestModifierManager return tag; } - getDebugName({ Klass }: TestModifierDefinitionState) { + getDebugName(state: TestModifierDefinitionState, { Klass }: TestModifierDefinitionState) { return Klass?.name || ''; } From 2262c85d49387802b58bd3d9c3dd9deaae672890 Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Wed, 26 Jun 2024 17:52:07 +0200 Subject: [PATCH 08/12] fix lint --- .../integration-tests/test/debug-render-tree-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts b/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts index fa0a9761e..11c3b65ec 100644 --- a/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts @@ -342,7 +342,7 @@ class DebugRenderTreeTest extends RenderTest { willDestroyElement() {} getDebugName() { - return 'did-insert' + return 'did-insert'; } } From 566e047ae3a65d2b2aca8ba76a8aa983eaddaf6b Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Wed, 26 Jun 2024 17:53:28 +0200 Subject: [PATCH 09/12] revert --- .../integration-tests/test/debug-render-tree-test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts b/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts index 11c3b65ec..6c8dbf24a 100644 --- a/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts @@ -340,10 +340,6 @@ class DebugRenderTreeTest extends RenderTest { didInsertElement() {} didUpdate() {} willDestroyElement() {} - - getDebugName() { - return 'did-insert'; - } } this.registerModifier('did-insert', DidInsertModifier); From 25d103d5de8abe490894f1042d264135280b0847 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Wed, 26 Jun 2024 18:20:04 +0200 Subject: [PATCH 10/12] return delegate if no modifier --- packages/@glimmer/manager/lib/public/modifier.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index 537d92dd8..6d864b744 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -130,7 +130,7 @@ export class CustomModifierManager if (typeof delegate.getDebugInstance === 'function') { return delegate.getDebugInstance(state); } - return state.modifier; + return state.modifier || delegate; } getTag({ tag }: CustomModifierState) { From 01399ddb47a9c4eb751e94d3cbcc4b227b608126 Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Thu, 11 Jul 2024 23:21:54 +0200 Subject: [PATCH 11/12] cleanup code --- .../integration-tests/lib/modifiers.ts | 4 +- .../lib/test-helpers/define.ts | 2 +- .../lib/managers/internal/modifier.d.ts | 4 +- .../interfaces/lib/managers/modifier.d.ts | 4 +- .../@glimmer/manager/lib/public/modifier.ts | 47 +++++++++---------- .../runtime/lib/compiled/opcodes/component.ts | 4 +- packages/@glimmer/runtime/lib/environment.ts | 4 +- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts b/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts index d255d6fe9..a749439c6 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts @@ -44,8 +44,8 @@ export class TestModifierManager return tag; } - getDebugName(state: TestModifierDefinitionState, { Klass }: TestModifierDefinitionState) { - return Klass?.name || ''; + getDebugName(definition?: object) { + return (definition as any).instance.constructor.name || ''; } getDebugInstance({ instance }: TestModifier) { diff --git a/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts b/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts index 74e7ac7ee..28633885d 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts @@ -82,7 +82,7 @@ class FunctionalModifierManager implements ModifierManager } } - getDebugName(fn: Function) { + getDebugName(fn: SimpleModifierFn) { return fn.name || '(anonymous function)'; } } diff --git a/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts b/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts index 7aea472c9..d49064171 100644 --- a/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts +++ b/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts @@ -22,8 +22,8 @@ export interface InternalModifierManager< // the modifier's update hooks need to be called (if at all). getTag(modifier: TModifierInstanceState): UpdatableTag | null; - getDebugName(Modifier: TModifierDefinitionState, definition: object): string; - getDebugInstance(Modifier: TModifierInstanceState): unknown; + getDebugName(modifier: TModifierInstanceState): string; + getDebugInstance(modifier: TModifierInstanceState): unknown; // At initial render, the modifier gets a chance to install itself on the // element it is managing. It can also return a bucket of state that diff --git a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts index fc014ada5..bf5e7f10a 100644 --- a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts +++ b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts @@ -19,6 +19,6 @@ export interface ModifierManager { installModifier(instance: ModifierStateBucket, element: Element, args: Arguments): void; updateModifier(instance: ModifierStateBucket, args: Arguments): void; destroyModifier(instance: ModifierStateBucket, args: Arguments): void; - getDebugName?(instance: object): string; - getDebugInstance?(instance: object): any; + getDebugName?(definition?: object): string; + getDebugInstance?(instance: ModifierStateBucket): any; } diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index 6d864b744..460bbbdc7 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -32,13 +32,13 @@ export function modifierCapabilities { +export interface CustomModifierState { tag: UpdatableTag; element: SimpleElement; - modifier: ModifierInstance; - delegate: ModifierManager; + modifier: ModifierStateBucket; + delegate: ModifierManager; args: Arguments; - debugName?: string; + definition?: object; } /** @@ -65,12 +65,12 @@ export interface CustomModifierState { * `updateModifier()` - invoked when the arguments passed to a modifier change * `destroyModifier()` - invoked when the modifier is about to be destroyed */ -export class CustomModifierManager - implements InternalModifierManager> +export class CustomModifierManager + implements InternalModifierManager> { - private componentManagerDelegates = new WeakMap>(); + private componentManagerDelegates = new WeakMap>(); - constructor(private factory: ManagerFactory>) {} + constructor(private factory: ManagerFactory>) {} private getDelegateFor(owner: O) { let { componentManagerDelegates } = this; @@ -99,45 +99,44 @@ export class CustomModifierManager let delegate = this.getDelegateFor(owner); let args = argsProxyFor(capturedArgs, 'modifier'); - let instance: ModifierInstance = delegate.createModifier(definition, args); + let modifier: ModifierStateBucket = delegate.createModifier(definition, args); let tag = createUpdatableTag(); - let state: CustomModifierState; + let state: CustomModifierState; state = { tag, element, delegate, args, - modifier: instance, + definition, + modifier, }; - registerDestructor(state, () => delegate.destroyModifier(instance, args)); + registerDestructor(state, () => delegate.destroyModifier(modifier, args)); return state; } - getDebugName(state: CustomModifierState, definition: object) { - let delegate = state.delegate; - if (typeof delegate.getDebugName === 'function') { + getDebugName({ delegate, definition }: CustomModifierState) { + if (typeof delegate?.getDebugName === 'function') { return delegate.getDebugName(definition); } return (definition as any).name || ''; } - getDebugInstance(state: CustomModifierState) { - let delegate = state.delegate; - if (typeof delegate.getDebugInstance === 'function') { - return delegate.getDebugInstance(state); + getDebugInstance({ delegate, modifier }: CustomModifierState) { + if (typeof delegate?.getDebugInstance === 'function') { + return delegate.getDebugInstance(modifier); } - return state.modifier || delegate; + return modifier || delegate; } - getTag({ tag }: CustomModifierState) { + getTag({ tag }: CustomModifierState) { return tag; } - install({ element, args, modifier, delegate }: CustomModifierState) { + install({ element, args, modifier, delegate }: CustomModifierState) { let { capabilities } = delegate; if (capabilities.disableAutoTracking === true) { @@ -147,7 +146,7 @@ export class CustomModifierManager } } - update({ args, modifier, delegate }: CustomModifierState) { + update({ args, modifier, delegate }: CustomModifierState) { let { capabilities } = delegate; if (capabilities.disableAutoTracking === true) { @@ -157,7 +156,7 @@ export class CustomModifierManager } } - getDestroyable(state: CustomModifierState) { + getDestroyable(state: CustomModifierState) { return state; } } diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts index 332cdd56a..a38816d8d 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts @@ -494,7 +494,7 @@ export class ComponentElementOperations implements ElementOperations { this.modifiers.push(modifier); if (vm.env.debugRenderTree !== undefined) { - const { manager, definition, state } = modifier; + const { manager, state } = modifier; // TODO: we need a stable object for the debugRenderTree as the key, add support for // the case where the state is a primitive, or if in practice we always have/require @@ -504,7 +504,7 @@ export class ComponentElementOperations implements ElementOperations { } let { element, constructing } = vm.elements(); - let name = manager.getDebugName(state, definition.state); + let name = manager.getDebugName(state); let instance = manager.getDebugInstance(state); assert(constructing, `Expected a constructing element in addModifier`); diff --git a/packages/@glimmer/runtime/lib/environment.ts b/packages/@glimmer/runtime/lib/environment.ts index d132c21b5..52ab7d11b 100644 --- a/packages/@glimmer/runtime/lib/environment.ts +++ b/packages/@glimmer/runtime/lib/environment.ts @@ -65,7 +65,7 @@ class TransactionImpl implements Transaction { () => manager.install(state), import.meta.env.DEV && `- While rendering:\n (instance of a \`${ - definition.resolvedName || manager.getDebugName(state as any, definition.state) + definition.resolvedName || manager.getDebugName(state) }\` modifier)` ); updateTag(modifierTag, tag); @@ -82,7 +82,7 @@ class TransactionImpl implements Transaction { () => manager.update(state), import.meta.env.DEV && `- While rendering:\n (instance of a \`${ - definition.resolvedName || manager.getDebugName(state as any, definition.state) + definition.resolvedName || manager.getDebugName(state) }\` modifier)` ); updateTag(modifierTag, tag); From d02dedfeafdf78f2ed90ec170ba53871dcda5bb0 Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Fri, 18 Oct 2024 17:34:15 +0200 Subject: [PATCH 12/12] fix --- .../@glimmer-workspace/integration-tests/lib/modifiers.ts | 4 ++-- .../@glimmer/interfaces/lib/managers/internal/modifier.d.ts | 4 ++-- packages/@glimmer/interfaces/lib/managers/modifier.d.ts | 2 +- packages/@glimmer/manager/lib/public/modifier.ts | 5 ++--- packages/@glimmer/runtime/lib/compiled/opcodes/component.ts | 4 ++-- packages/@glimmer/runtime/lib/environment.ts | 4 ++-- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts b/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts index a749439c6..eb0e26717 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/modifiers.ts @@ -44,8 +44,8 @@ export class TestModifierManager return tag; } - getDebugName(definition?: object) { - return (definition as any).instance.constructor.name || ''; + getDebugName({ Klass }: TestModifierDefinitionState) { + return Klass?.name || ''; } getDebugInstance({ instance }: TestModifier) { diff --git a/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts b/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts index d49064171..b717072d2 100644 --- a/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts +++ b/packages/@glimmer/interfaces/lib/managers/internal/modifier.d.ts @@ -22,8 +22,8 @@ export interface InternalModifierManager< // the modifier's update hooks need to be called (if at all). getTag(modifier: TModifierInstanceState): UpdatableTag | null; - getDebugName(modifier: TModifierInstanceState): string; - getDebugInstance(modifier: TModifierInstanceState): unknown; + getDebugName(Modifier: TModifierDefinitionState): string; + getDebugInstance(Modifier: TModifierInstanceState): unknown; // At initial render, the modifier gets a chance to install itself on the // element it is managing. It can also return a bucket of state that diff --git a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts index bf5e7f10a..f6e0ae7c3 100644 --- a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts +++ b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts @@ -19,6 +19,6 @@ export interface ModifierManager { installModifier(instance: ModifierStateBucket, element: Element, args: Arguments): void; updateModifier(instance: ModifierStateBucket, args: Arguments): void; destroyModifier(instance: ModifierStateBucket, args: Arguments): void; - getDebugName?(definition?: object): string; + getDebugName?(factory?: unknown): string; getDebugInstance?(instance: ModifierStateBucket): any; } diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index 460bbbdc7..33c35aa3d 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -38,7 +38,6 @@ export interface CustomModifierState { modifier: ModifierStateBucket; delegate: ModifierManager; args: Arguments; - definition?: object; } /** @@ -109,7 +108,6 @@ export class CustomModifierManager element, delegate, args, - definition, modifier, }; @@ -118,7 +116,8 @@ export class CustomModifierManager return state; } - getDebugName({ delegate, definition }: CustomModifierState) { + getDebugName(definition: object) { + const delegate = this.factory.prototype; if (typeof delegate?.getDebugName === 'function') { return delegate.getDebugName(definition); } diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts index a38816d8d..655c4e52f 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts @@ -494,7 +494,7 @@ export class ComponentElementOperations implements ElementOperations { this.modifiers.push(modifier); if (vm.env.debugRenderTree !== undefined) { - const { manager, state } = modifier; + const { manager, definition, state } = modifier; // TODO: we need a stable object for the debugRenderTree as the key, add support for // the case where the state is a primitive, or if in practice we always have/require @@ -504,7 +504,7 @@ export class ComponentElementOperations implements ElementOperations { } let { element, constructing } = vm.elements(); - let name = manager.getDebugName(state); + let name = manager.getDebugName(definition.state); let instance = manager.getDebugInstance(state); assert(constructing, `Expected a constructing element in addModifier`); diff --git a/packages/@glimmer/runtime/lib/environment.ts b/packages/@glimmer/runtime/lib/environment.ts index 52ab7d11b..46a1b5a18 100644 --- a/packages/@glimmer/runtime/lib/environment.ts +++ b/packages/@glimmer/runtime/lib/environment.ts @@ -65,7 +65,7 @@ class TransactionImpl implements Transaction { () => manager.install(state), import.meta.env.DEV && `- While rendering:\n (instance of a \`${ - definition.resolvedName || manager.getDebugName(state) + definition.resolvedName || manager.getDebugName(definition.state) }\` modifier)` ); updateTag(modifierTag, tag); @@ -82,7 +82,7 @@ class TransactionImpl implements Transaction { () => manager.update(state), import.meta.env.DEV && `- While rendering:\n (instance of a \`${ - definition.resolvedName || manager.getDebugName(state) + definition.resolvedName || manager.getDebugName(definition.state) }\` modifier)` ); updateTag(modifierTag, tag);