Skip to content

Commit

Permalink
just use a Set
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-greene committed May 18, 2021
1 parent 06adc59 commit efbb726
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/resolve-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function resolveExternal (parser, options) {
* @param {string} path - The full path of `obj`, possibly with a JSON Pointer in the hash
* @param {$Refs} $refs
* @param {$RefParserOptions} options
* @param {WeakMap} seen - Internal.
* @param {Set} seen - Internal.
*
* @returns {Promise[]}
* Returns an array of promises. There will be one promise for each JSON reference in `obj`.
Expand All @@ -53,11 +53,11 @@ function resolveExternal (parser, options) {
* then the corresponding promise will internally reference an array of promises.
*/
function crawl (obj, path, $refs, options, seen) {
seen = seen || new WeakMap();
seen = seen || new Set();
let promises = [];

if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !seen.has(obj)) {
seen.set(obj, 1); // Track previously seen objects to avoid infinite recursion
seen.add(obj); // Track previously seen objects to avoid infinite recursion
if ($Ref.isExternal$Ref(obj)) {
promises.push(resolve$Ref(obj, path, $refs, options));
}
Expand Down

0 comments on commit efbb726

Please sign in to comment.