From 840f68cb4972aa1d6d423c9e2a57a3d05db0f765 Mon Sep 17 00:00:00 2001 From: Craig Beck Date: Tue, 26 Sep 2023 12:29:05 -0700 Subject: [PATCH] Ensure MarkupHooks have valid module attribute --- src/templates/templates.ts | 8 +++++--- test/all/templates/templates.mocha.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/templates/templates.ts b/src/templates/templates.ts index 93ae86dd..fbe0d853 100644 --- a/src/templates/templates.ts +++ b/src/templates/templates.ts @@ -14,6 +14,9 @@ export type Attributes = Record; type PathSegment = string | number; export type Dependency = Array; +// namespace these are exported under; used when serializing views +const NAMESPACE = 'templates' + declare global { interface Node { $bindItemStart?: RangeBinding; @@ -105,7 +108,7 @@ export const NAMESPACE_URIS = { }; export class Template { - module = 'templates'; + module = NAMESPACE; type = 'Template'; content: Template[]; source: string; @@ -1690,13 +1693,12 @@ function getDependencies(expression: HasDependencies, context: Context, options: } export abstract class MarkupHook { - module = Template.prototype.module; + module = NAMESPACE; name: string; abstract emit(context: Context, target: T): void; } class Hook extends MarkupHook { - module = Template.prototype.module; name = 'hook'; emit(context: Context, node: Node & { $component: Controller }) { node.$component = context.controller; diff --git a/test/all/templates/templates.mocha.js b/test/all/templates/templates.mocha.js index 195a6412..98145b76 100644 --- a/test/all/templates/templates.mocha.js +++ b/test/all/templates/templates.mocha.js @@ -39,3 +39,22 @@ describe('Views', function() { }); }); + +describe('Hooks', function() { + it('derives valid module attribute from base class', function() { + class TestHook extends templates.MarkupHook { + constructor() { + super(); + this.name = 'TestHook'; + } + } + var testHook = new TestHook(); + expect(testHook.name).to.equal('TestHook'); + expect(testHook.module).to.equal('templates'); + }); + it('has valid module name', function() { + var hook = new templates.ComponentOn('foo'); + expect(hook.name).to.equal('foo'); + expect(hook.module).to.equal('templates'); + }); +});