code: void updateGlobalVarReferences(Map<Var, ReferenceCollection>
        refMapPatch, Node root) {
      if (refMap == null || !root.isScript()) {
        resetGlobalVarReferences(refMapPatch);
        return;
      }
  
      InputId inputId = root.getInputId();
      checkNotNull(inputId);
      // Note there are two assumptions here (i) the order of compiler inputs
      // has not changed and (ii) all references are in the order they appear
      // in AST (this is enforced in ReferenceCollectionCallback).
      removeScriptReferences(inputId);
      for (Entry<Var, ReferenceCollection> entry : refMapPatch.entrySet()) {
        Var var = entry.getKey();
        if (var.isGlobal()) {
          replaceReferences(var.getName(), inputId, entry.getValue());
        }
      }
    }
docs: Updates the internal reference map based on the provided parameters. If
  {@code scriptRoot} is not SCRIPT, it basically replaces the internal map
  with the new one, otherwise it replaces all the information associated to
  the given script.
  
  @param refMapPatch The reference map result of a
  {@link ReferenceCollectingCallback} pass which might be collected from
  the whole AST or just a sub-tree associated to a SCRIPT node.
  @param root AST sub-tree root on which reference collection was done.