"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SerializerStatistics = exports.ReactStatistics = exports.TimingStatistics = exports.BodyReference = undefined;
exports.AreSameResidualBinding = AreSameResidualBinding;

var _environment = require("../environment.js");

var _index = require("../values/index.js");

var _abstract = require("../methods/abstract.js");

var _realm = require("../realm.js");

var _invariant = require("../invariant.js");

var _invariant2 = _interopRequireDefault(_invariant);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// TODO: add type for additional functions.


// Each of these will correspond to a different preludeGenerator and thus will
// have different values available for initialization. FunctionValues should
// only be additional functions.
function AreSameResidualBinding(realm, x, y) {
  if (x.serializedValue === y.serializedValue) return true;
  if (x.value && x.value === y.value) return true;
  if (x.value instanceof _index.ConcreteValue && y.value instanceof _index.ConcreteValue) {
    return (0, _abstract.SameValue)(realm, x.value, y.value);
  }
  return false;
} /**
   * Copyright (c) 2017-present, Facebook, Inc.
   * All rights reserved.
   *
   * This source code is licensed under the BSD-style license found in the
   * LICENSE file in the root directory of this source tree. An additional grant
   * of patent rights can be found in the PATENTS file in the same directory.
   */

class BodyReference {
  constructor(body, index) {
    (0, _invariant2.default)(index >= 0);
    this.body = body;
    this.index = index;
  }
  isNotEarlierThan(other) {
    return this.body === other.body && this.index >= other.index;
  }
}

exports.BodyReference = BodyReference;
class TimingStatistics {
  constructor() {
    this.totalTime = 0;
    this.globalCodeTime = 0;
    this.initializeMoreModulesTime = 0;
    this.deepTraversalTime = 0;
    this.referenceCountsTime = 0;
    this.serializePassTime = 0;
  }
}

exports.TimingStatistics = TimingStatistics;
class ReactStatistics {
  constructor() {
    this.optimizedTrees = 0;
    this.inlinedComponents = 0;
    this.evaluatedRootNodes = [];
    this.componentsEvaluated = 0;
    this.optimizedNestedClosures = 0;
  }
}

exports.ReactStatistics = ReactStatistics;
class SerializerStatistics {
  constructor() {
    this.functions = 0;
    this.delayedValues = 0;
    this.initializedModules = 0;
    this.acceleratedModules = 0;
    this.delayedModules = 0;
    this.totalModules = 0;
    this.resetBeforePass();
  }
  resetBeforePass() {
    this.objects = 0;
    this.objectProperties = 0;
    this.functionClones = 0;
    this.lazyObjects = 0;
    this.referentialized = 0;
    this.valueIds = 0;
    this.valuesInlined = 0;
    this.generators = 0;
    this.requireCalls = 0;
    this.requireCallsReplaced = 0;
  }


  log() {
    console.log(`=== serialization statistics`);
    console.log(`${this.objects} objects with ${this.objectProperties} properties`);
    console.log(`${this.functions} functions plus ${this.functionClones} clones due to captured variables; ${this.referentialized} captured mutable variables`);
    console.log(`${this.lazyObjects} objects are lazy.`);
    console.log(`${this.valueIds} eager and ${this.delayedValues} delayed value ids generated, and ${this.valuesInlined} values inlined.`);
    console.log(`${this.initializedModules} out of ${this.totalModules} modules initialized, with ${this.acceleratedModules} accelerated and ${this.delayedModules} delayed.`);
    console.log(`${this.requireCallsReplaced} of ${this.requireCalls} require calls inlined.`);
    console.log(`${this.generators} generators`);
  }
}

exports.SerializerStatistics = SerializerStatistics;
//# sourceMappingURL=types.js.map