Skip to content

Commit f54ebea

Browse files
authored
fix: ignore invalid before values (#198)
1 parent 934bc55 commit f54ebea

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/Hook.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ class Hook {
152152
} else if (Array.isArray(item.before)) {
153153
before = new Set(item.before);
154154
}
155+
if (before) {
156+
for (const name of before) {
157+
if (!this.taps.some((tap) => tap.name === name)) {
158+
before.delete(name);
159+
}
160+
}
161+
}
155162
let stage = 0;
156163
if (typeof item.stage === "number") {
157164
stage = item.stage;

lib/__tests__/Hook.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,48 @@ describe("Hook", () => {
107107
new Error("Missing name for tap")
108108
);
109109
});
110+
111+
it("should ignore invalid before values", () => {
112+
const hook = new SyncHook();
113+
114+
const calls = [];
115+
116+
hook.tap("A", () => calls.push("A"));
117+
118+
hook.tap(
119+
{
120+
name: "B",
121+
before: "C"
122+
},
123+
() => calls.push("B")
124+
);
125+
126+
hook.tap(
127+
{
128+
name: "C",
129+
before: [" "]
130+
},
131+
() => calls.push("C")
132+
);
133+
134+
hook.tap(
135+
{
136+
name: "D",
137+
before: {}
138+
},
139+
() => calls.push("D")
140+
);
141+
142+
hook.tap(
143+
{
144+
name: "E",
145+
before: null
146+
},
147+
() => calls.push("E")
148+
);
149+
150+
calls.length = 0;
151+
hook.call();
152+
expect(calls).toEqual(["A", "B", "C", "D", "E"]);
153+
});
110154
});

0 commit comments

Comments
 (0)