Skip to content

Commit ad6a164

Browse files
committed
Refactor to use Map
1 parent 4a93553 commit ad6a164

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/index.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import {visit} from 'unist-util-visit'
1616

17-
const own = {}.hasOwnProperty
18-
1917
/**
2018
* Find definitions in `tree`.
2119
*
@@ -28,17 +26,17 @@ const own = {}.hasOwnProperty
2826
* Getter.
2927
*/
3028
export function definitions(tree) {
31-
/** @type {Record<string, Definition>} */
32-
const cache = Object.create(null)
29+
/** @type {Map<string, Definition>} */
30+
const cache = new Map()
3331

3432
if (!tree || !tree.type) {
3533
throw new Error('mdast-util-definitions expected node')
3634
}
3735

3836
visit(tree, 'definition', function (definition) {
3937
const id = clean(definition.identifier)
40-
if (id && !own.call(cache, id)) {
41-
cache[id] = definition
38+
if (id && !cache.get(id)) {
39+
cache.set(id, definition)
4240
}
4341
})
4442

@@ -47,8 +45,7 @@ export function definitions(tree) {
4745
/** @type {GetDefinition} */
4846
function definition(identifier) {
4947
const id = clean(identifier)
50-
// To do: next major: return `undefined` when not found.
51-
return id && own.call(cache, id) ? cache[id] : undefined
48+
return cache.get(id)
5249
}
5350
}
5451

0 commit comments

Comments
 (0)