Skip to content

Commit

Permalink
Ensure MarkupHooks have valid module attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed Sep 26, 2023
1 parent 54db640 commit 840f68c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/templates/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export type Attributes = Record<string, Attribute>;
type PathSegment = string | number;
export type Dependency = Array<PathSegment | Context>;

// namespace these are exported under; used when serializing views
const NAMESPACE = 'templates'

declare global {
interface Node {
$bindItemStart?: RangeBinding;
Expand Down Expand Up @@ -105,7 +108,7 @@ export const NAMESPACE_URIS = {
};

export class Template {
module = 'templates';
module = NAMESPACE;
type = 'Template';
content: Template[];
source: string;
Expand Down Expand Up @@ -1690,13 +1693,12 @@ function getDependencies(expression: HasDependencies, context: Context, options:
}

export abstract class MarkupHook<T> {
module = Template.prototype.module;
module = NAMESPACE;
name: string;
abstract emit(context: Context, target: T): void;
}

class Hook extends MarkupHook<any> {
module = Template.prototype.module;
name = 'hook';
emit(context: Context, node: Node & { $component: Controller }) {
node.$component = context.controller;
Expand Down
19 changes: 19 additions & 0 deletions test/all/templates/templates.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 840f68c

Please sign in to comment.