Skip to content

Commit cb374f5

Browse files
committed
fix(utils): 修正 multimap 的可选参数判定
详细的提交内容: - 将 `MultiMap.has(key, value?)` 的参数判定从 `arguments.length` 改为显式的缺省值哨兵 `_MISSING` - 解决当调用方显式传入 `undefined` 时,`has(key, undefined)` 与 `has(key)` 无法正确区分的问题 - 保持仅判断 key 是否存在的行为不变,同时让 value 存在性检查更稳定、可预测 - 影响范围:`src/utils/multi-map.ts` 中所有依赖 `has` 方法的调用方 - 其他说明:该修改属于内部实现优化,不影响对外 API 形式
1 parent c7b334f commit cb374f5

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/utils/multi-map.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Provides usual operations: add, remove, get, has, keys, values, entries,
33
// clear, deleteKey and size accessors.
44

5+
const _MISSING = Symbol("missing");
6+
57
class MultiMap<K, V> {
68
private map: Map<K, Set<V>> = new Map();
79

@@ -20,11 +22,11 @@ class MultiMap<K, V> {
2022
return this.map.has(key);
2123
}
2224

23-
has(key: K, value?: V): boolean {
25+
has(key: K, value: V | typeof _MISSING = _MISSING): boolean {
2426
const set = this.map.get(key);
2527
if (!set) return false;
26-
if (arguments.length === 1) return true;
27-
return set.has(value as V);
28+
if (value === _MISSING) return true;
29+
return set.has(value);
2830
}
2931

3032
add(key: K, value: V): void {

0 commit comments

Comments
 (0)