text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            * 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.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            */
  
  exports.evaluate = evaluate;
  exports.evaluateWithAbstractConditional = evaluateWithAbstractConditional;
  
  var _completions = require("../completions.js");
  
  var _realm = require("../realm.js");
  
  var _index = require("../values/index.js");
  
  var _environment = require("../environment.js");
  
  var _index2 = require("../methods/index.js");
  
  var _invariant = require("../invariant.js");
  
  var _invariant2 = _interopRequireDefault(_invariant);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function evaluate(ast, strictCode, env, realm) {
    // 1. Let exprRef be the result of evaluating Expression
    var exprRef = env.evaluate(ast.test, strictCode);
    // 2. Let exprValue be ToBoolean(? GetValue(exprRef))
    var exprValue = (0, _index2.GetValue)(realm, exprRef);
  
    if (exprValue instanceof _index.ConcreteValue) {
      var stmtCompletion = void 0;
      if ((0, _index2.ToBoolean)(realm, exprValue)) {
        // 3.a. Let stmtCompletion be the result of evaluating the first Statement
        stmtCompletion = env.evaluateCompletion(ast.consequent, strictCode);
      } else {
        if (ast.alternate)
          // 4.a. Let stmtCompletion be the result of evaluating the second Statement
          stmtCompletion = env.evaluateCompletion(ast.alternate, strictCode);else
          // 3 (of the if only statement). Return NormalCompletion(undefined)
          stmtCompletion = realm.intrinsics.undefined;
      }
      // 5. Return Completion(UpdateEmpty(stmtCompletion, undefined)
      if (stmtCompletion instanceof _environment.Reference) return stmtCompletion;
      stmtCompletion = (0, _index2.UpdateEmpty)(realm, stmtCompletion, realm.intrinsics.undefined);
      if (stmtCompletion instanceof _completions.AbruptCompletion) {
        throw stmtCompletion;
      }
      return stmtCompletion;
    }
    (0, _invariant2.default)(exprValue instanceof _index.AbstractValue);
  
    if (!exprValue.mightNotBeObject()) {
      return env.evaluate(ast.consequent, strictCode);
    } else {
      return evaluateWithAbstractConditional(exprValue, ast.consequent, ast.alternate, strictCode, env, realm);
    }
  }
  
  function evaluateWithAbstractConditional(condValue, consequent, alternate, strictCode, env, realm) {
    // Evaluate consequent and alternate in sandboxes and get their effects.
    var _realm$partially_eval = realm.partially_evaluate_node(consequent, strictCode, env),
        _realm$partially_eval2 = _slicedToArray(_realm$partially_eval, 5),
        compl1 = _realm$partially_eval2[0],
        gen1 = _realm$partially_eval2[1],
        bindings1 = _realm$partially_eval2[2],
        properties1 = _realm$partially_eval2[3],
        createdObj1 = _realm$partially_eval2[4];
  
    var _ref = alternate ? realm.partially_evaluate_node(alternate, strictCode, env) : (0, _realm.construct_empty_effects)(realm),
        _ref2 = _slicedToArray(_ref, 5),
        compl2 = _ref2[0],
        gen2 = _ref2[1],
        bindings2 = _ref2[2],
        properties2 = _ref2[3],
        createdObj2 = _ref2[4];
  
    // Join the effects, creating an abstract view of what happened, regardless
    // of the actual value of condValue.
  
  
    var joinedEffects = (0, _index2.joinEffects)(realm, condValue, [compl1, gen1, bindings1, properties1, createdObj1], [compl2, gen2, bindings2, properties2, createdObj2]);
    var completion = joinedEffects[0];
    if (completion instanceof _completions.NormalCompletion) {
      // in this case one of the branches may complete abruptly, which means that
      // not all control flow branches join into one flow at this point.
      // Consequently we have to continue tracking changes until the point where
      // all the branches come together into one.
      realm.capture_effects();
    }
    // Note that the effects of (non joining) abrupt branches are not included
    // in joinedEffects, but are tracked separately inside completion.
    realm.apply_effects(joinedEffects);
  
    // return or throw completion
    if (completion instanceof _completions.AbruptCompletion) throw completion;
    (0, _invariant2.default)(completion instanceof _completions.NormalCompletion || completion instanceof _index.Value || completion instanceof _environment.Reference);
    return completion;
  }
  //# sourceMappingURL=IfStatement.js.map