Comparing version
@@ -81,3 +81,3 @@ 'use strict'; | ||
// Optional: support for some standard constructors (extend as desired) | ||
if (obj instanceof Map) | ||
/*if (obj instanceof Map) | ||
Array.from(obj, ([key, val]) => result.set(circularClone(key, hash), | ||
@@ -87,2 +87,3 @@ circularClone(val, hash)) ); | ||
Array.from(obj, (key) => result.add(circularClone(key, hash)) ); | ||
*/ | ||
// Register in hash | ||
@@ -89,0 +90,0 @@ hash.set(obj, result); |
@@ -42,2 +42,3 @@ 'use strict'; | ||
let obj = (options.depth > 1 ? o : clone(o)); | ||
let container = { data: obj }; | ||
let defs = (options.depth > 1 ? definitions : clone(definitions)); | ||
@@ -54,3 +55,3 @@ // options.master is the top level object, regardless of depth | ||
iterations++; | ||
recurse(obj,options.state,function(obj,key,state){ | ||
recurse(container,options.state,function(obj,key,state){ | ||
if ((key === '$ref') && (typeof obj[key] === 'string')) { | ||
@@ -78,3 +79,3 @@ let $ref = obj[key]; // immutable | ||
let entry = options.cache[$ref]; | ||
if (entry.resolved && entry.path !== '#') { | ||
if (entry.resolved) { | ||
// we have already seen and resolved this reference | ||
@@ -84,3 +85,2 @@ logger.warn('Patching %s for %s',$ref,entry.path); | ||
if ((options.$ref) && (typeof state.parent[state.pkey] === 'object')) state.parent[state.pkey][options.$ref] = $ref; | ||
if (options.bail && iterations > 2) changes--; | ||
} | ||
@@ -100,3 +100,2 @@ else if ($ref === entry.path) { | ||
if ((options.$ref) && (typeof state.parent[state.pkey] === 'object')) state.parent[options.$ref] = $ref; | ||
if (options.bail && iterations > 2) changes--; | ||
} | ||
@@ -107,3 +106,3 @@ } | ||
} | ||
return obj; | ||
return container.data; | ||
} | ||
@@ -110,0 +109,0 @@ |
@@ -37,3 +37,3 @@ 'use strict'; | ||
if (typeof obj === 'undefined') return false; | ||
if (!prop || (prop === '#')) return obj; // doesn't return newValue | ||
if (!prop || (prop === '#')) return (typeof newValue !== 'undefined' ? newValue : obj); | ||
@@ -40,0 +40,0 @@ if (prop.indexOf('#')>=0) { |
{ | ||
"name": "reftools", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Utility functions to deal with references in objects", | ||
"main": "lib/recurse.js", | ||
"scripts": { | ||
"test": "npx mocha" | ||
"test": "node node_modules/mocha/bin/mocha $nflags" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
35440
0.3%17
6.25%