packages/relay-compiler/util/dedupeJSONStringify.js
function collectDuplicates(value) {
    if (value == null || typeof value !== 'object') {
      return;
    }
    const metadata = metadataForVal.get(value);
    // Only consider duplicates with hashes longer than 2 (excludes [] and {}).
    if (metadata && metadata.value !== value && metadata.hash.length > 2) {
      metadata.isDuplicate = true;
      return;
    }
    if (Array.isArray(value)) {
      for (let i = 0; i < value.length; i++) {
        collectDuplicates(value[i]);
      }
    } else {
      for (const k in value) {
        if (value.hasOwnProperty(k) && value[k] !== undefined) {
          collectDuplicates(value[k]);
        }
      }
    }
  }
function collectDuplicates(value) {
    if (value == null || typeof value !== 'object') {
      return;
    }
    const metadata = metadataForVal.get(value);
    // Only consider duplicates with hashes longer than 2 (excludes [] and {}).
    if (metadata && metadata.value !== value && metadata.hash.length > 2) {
      metadata.isDuplicate = true;
      return;
    }
    if (Array.isArray(value)) {
      for (let i = 0; i < value.length; i++) {
        collectDuplicates(value[i]);
      }
    } else {
      for (const k in value) {
        if (value.hasOwnProperty(k) && value[k] !== undefined) {
          collectDuplicates(value[k]);
        }
      }
    }
  }
function collectDuplicates ( value ) { if ( value == null || typeof value !== 'object' ) { return ; } const metadata = metadataForVal . get ( value ) ; // Only consider duplicates with hashes longer than 2 (excludes [] and {}). if ( metadata && metadata . value !== value && metadata . hash . length > 2 ) { metadata . isDuplicate = true ; return ; } if ( Array . isArray ( value ) ) { for ( let i = 0 ; i < value . length ; i ++ ) { collectDuplicates ( value [ i ] ) ; } } else { for ( const k in value ) { if ( value . hasOwnProperty ( k ) && value [ k ] !== undefined ) { collectDuplicates ( value [ k ] ) ; } } } }
Using top-down recursion, linearly scan the JSON tree to determine which values should be deduplicated.
Using top - down recursion linearly scan the JSON tree to determine which values should be deduplicated .