Skip to content

Commit 0e49193

Browse files
committed
fix(core registry): Do nothing with Patterns without a trigger.
Patterns without a trigger broke the registry scan method. Now they don't.
1 parent 514e7ff commit 0e49193

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/core/registry.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,22 @@ const registry = {
174174
}
175175
}
176176

177+
// Clean up selectors:
178+
// - Remove whitespace,
179+
// - Remove trailing commas,
180+
// - Join to selecto string.
181+
const selector_string = selectors.map(
182+
(selector) => selector.trim().replace(/,$/, "")
183+
).join(",");
184+
185+
// Exit, if no selector.
186+
if (!selector_string) {
187+
return;
188+
}
189+
177190
let matches = dom.querySelectorAllAndMe(
178191
content,
179-
selectors.map((it) => it.trim().replace(/,$/, "")).join(",")
192+
selector_string
180193
);
181194
matches = matches.filter((el) => {
182195
// Filter out patterns:

src/core/registry.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,16 @@ describe("pat-registry: The registry for patterns", function () {
104104

105105
done();
106106
});
107+
108+
it("Does nothing with Patterns without a trigger.", function () {
109+
registry.register(
110+
{
111+
name: "pattern-without-trigger"
112+
}
113+
)
114+
115+
const el = document.createElement("div");
116+
expect(() => { registry.scan(el) }).not.toThrow(DOMException);
117+
});
118+
107119
});

0 commit comments

Comments
 (0)