14
14
15
15
import { visit } from 'unist-util-visit'
16
16
17
- const own = { } . hasOwnProperty
18
-
19
17
/**
20
18
* Find definitions in `tree`.
21
19
*
@@ -28,17 +26,17 @@ const own = {}.hasOwnProperty
28
26
* Getter.
29
27
*/
30
28
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 ( )
33
31
34
32
if ( ! tree || ! tree . type ) {
35
33
throw new Error ( 'mdast-util-definitions expected node' )
36
34
}
37
35
38
36
visit ( tree , 'definition' , function ( definition ) {
39
37
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 )
42
40
}
43
41
} )
44
42
@@ -47,8 +45,7 @@ export function definitions(tree) {
47
45
/** @type {GetDefinition } */
48
46
function definition ( identifier ) {
49
47
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 )
52
49
}
53
50
}
54
51
0 commit comments