<commit_before>
import invariant from 'invariant';
const {PUSH, POP, REPLACE, REPLACE_AT_INDEX} = require('../constants/navigation');

module.exports = function navigate(state, {type, payload}) {
  if (!state) {
    return {};
  }

  let stack = state.stack;
  let index = state.index;

  switch (type) {
    case PUSH:
      if (index !== 0) {
        stack = stack.skip(index);
      }

      return Object.assign({}, state, {
        stack: stack.push(payload),
        index: 0,
      });

    case POP:
      if (stack.count() === 1) {
        return state;
      }

      return Object.assign({}, state, {
        index: index + 1,
      });

    case REPLACE:
      if (!stack.count()) {
        return state;
      }

      return Object.assign({}, state, {
        stack: stack.splice(index, 1, payload),
      });

    case REPLACE_AT_INDEX:
      invariant(
        payload.index < stack.count() - 1 && payload.index > 0,
        'Index out of bounds when trying to replaceAtIndex: ' +
        'your navigation stack contains ${stack.count()} elements, ' +
        'but you\'re trying to replace an element with index ${payload.index}',
      );

      return Object.assign({}, state, {
        stack: stack.splice(payload.index, 1, payload.route),
      });

    default:
      return state;
  }
};<commit_msg>removing interpolation<commit_after>
import invariant from 'invariant';
const {PUSH, POP, REPLACE, REPLACE_AT_INDEX} = require('../constants/navigation');

module.exports = function navigate(state, {type, payload}) {
  if (!state) {
    return {};
  }

  let stack = state.stack;
  let index = state.index;

  switch (type) {
    case PUSH:
      if (index !== 0) {
        stack = stack.skip(index);
      }

      return Object.assign({}, state, {
        stack: stack.push(payload),
        index: 0,
      });

    case POP:
      if (stack.count() === 1) {
        return state;
      }

      return Object.assign({}, state, {
        index: index + 1,
      });

    case REPLACE:
      if (!stack.count()) {
        return state;
      }

      return Object.assign({}, state, {
        stack: stack.splice(index, 1, payload),
      });

    case REPLACE_AT_INDEX:
      invariant(
        payload.index < stack.count() - 1 && payload.index > 0,
        'Index out of bounds when trying to replaceAtIndex: ' +
        'your navigation stack contains ' + stack.count() + ' elements, ' +
        'but you\'re trying to replace an element with index ' + payload.index,
      );

      return Object.assign({}, state, {
        stack: stack.splice(payload.index, 1, payload.route),
      });

    default:
      return state;
  }
};
{'fraction_non_alphanumeric': 0.1433408577878104, 'fraction_numerical': 0.006019563581640331, 'mean_word_length': 2.157957244655582, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1409893', 'n_tokens_mistral': 834, 'n_tokens_neox': 792, 'n_words': 219}