text: var constants = require("./constants");
  var isArray = Array.isArray;
  
  function resolve(object, path, len) {
      var current = object;
      for (var i=0; i<len; i++) {
          current = current[path[i]];
      }
  
      return current;
  }
  
  function resolveType(info) {
      if (info.type === 'Date') {
          return new Date(info.value);
      } else if (info.type === 'NOOP') {
          return constants.NOOP;
      } else {
          throw new Error('Bad type');
      }
  }
  
  module.exports = function finalize(outer) {
      if (!outer) {
          return outer;
      }
  
      var assignments = outer.$$;
      if (assignments) {
          var object = outer.o;
          var len;
  
          if (assignments && (len=assignments.length)) {
              for (var i=0; i<len; i++) {
                  var assignment = assignments[i];
  
                  var rhs = assignment.r;
                  var rhsValue;
  
                  if (isArray(rhs)) {
                      rhsValue = resolve(object, rhs, rhs.length);
                  } else {
                      rhsValue = resolveType(rhs);
                  }
  
                  var lhs = assignment.l;
                  var lhsLast = lhs.length-1;
  
                  if (lhsLast === -1) {
                      object = outer.o = rhsValue;
                      break;
                  } else {
                      var lhsParent = resolve(object, lhs, lhsLast);
                      lhsParent[lhs[lhsLast]] = rhsValue;
                  }
              }
          }
  
          assignments.length = 0; // Assignments have been applied, do not reapply
  
          return object == null ? null : object;
      } else {
          return outer;
      }
  
  };