Skip to content

Commit

Permalink
fix(core registry): Do nothing with Patterns without a trigger.
Browse files Browse the repository at this point in the history
Patterns without a trigger broke the registry scan method. Now they don't.
  • Loading branch information
thet committed Jan 28, 2025
1 parent 514e7ff commit 0e49193
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/core/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,22 @@ const registry = {
}
}

// Clean up selectors:
// - Remove whitespace,
// - Remove trailing commas,
// - Join to selecto string.
const selector_string = selectors.map(
(selector) => selector.trim().replace(/,$/, "")
).join(",");

// Exit, if no selector.
if (!selector_string) {
return;
}

let matches = dom.querySelectorAllAndMe(
content,
selectors.map((it) => it.trim().replace(/,$/, "")).join(",")
selector_string
);
matches = matches.filter((el) => {
// Filter out patterns:
Expand Down
12 changes: 12 additions & 0 deletions src/core/registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,16 @@ describe("pat-registry: The registry for patterns", function () {

done();
});

it("Does nothing with Patterns without a trigger.", function () {
registry.register(
{
name: "pattern-without-trigger"
}
)

const el = document.createElement("div");
expect(() => { registry.scan(el) }).not.toThrow(DOMException);
});

});

0 comments on commit 0e49193

Please sign in to comment.