<commit_before>var GlobBuilder = (function() {

  function Glob(text) {

    var glob = text.split('.');

    // Returns true if glob matches current $state name.
    this.matches = function(state) {
      var segments = state.name.split('.');

      // match greedy starts
      if (glob[0] === '**') {
         segments = segments.slice(segments.indexOf(glob[1]));
         segments.unshift('**');
      }
      // match greedy ends
      if (glob[glob.length - 1] === '**') {
         segments.splice(segments.indexOf(glob[glob.length - 2]) + 1, Number.MAX_VALUE);
         segments.push('**');
      }
      if (glob.length != segments.length) return false;

      // match single stars
      for (var i = 0, l = glob.length; i < l; i++) {
        if (glob[i] === '*') segments[i] = '*';
      }

      return segments.join('') === glob.join('');
    };
  }

  return {
    // Checks text to see if it looks like a glob.
    is: function(text) {
      return text.indexOf('*') > -1;
    },

    // Factories a glob matcher from a string
    fromString: function(text) {
      if (!this.is(text)) return null;
      return new Glob(text);
    }
  };
})();


function StateQueueManager(states, builder, $urlRouterProvider) {
  var queue = [], abstractKey = 'abstract';

  extend(this, {
    register: function(config, pre) {
      // Wrap a new object around the state so we can store our private details easily.
      state = inherit(config, {
        name: builder.name(config),
        self: config,
        resolve: config.resolve || {},
        toString: function() { return this.name; }
      });

      if (!isString(state.name)) throw new Error("State must have a valid name");
      // if (registered.hasOwnProperty(name)) throw new Error("State '" + name + "'' is already defined");
      if (pre)
        queue.unshift(state);
      else
        queue.push(state);
      return state;
    },

    flush: function() {
      var result, state, orphans = [];

      while (queue.length > 0) {
        state = queue.shift();
        result = builder.build(state);

        if (result) {
          states[state.name] = state;
          this.attachRoute(state);
          continue;
        }
        if (orphans.indexOf(state) >= 0) {
          throw new Error("Cannot register orphaned state '" + state.name + "'");
        }
        orphans.push(state);
        queue.push(state);
      }
      return states;
    },

    attachRoute: function(state) {
      if (state[abstractKey] || !state.url) return;

      $urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
        if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
          $state.transitionTo(state, $match, { location: false });
        }
      }]);
    }
  });
}

// Builds state properties from definition passed to StateQueueManager.register()
function StateBuilder(root, matcher, $urlMatcherFactoryProvider) {

  var self = this, delegates = {}, builders = {

    parent: function(state) {
      return matcher.find(self.parentName(state));
    },

    data: function(state) {
      if (state.parent && state.parent.data) {<commit_msg>fix($state): fix StateQueueManager orphan detection<commit_after>var GlobBuilder = (function() {

  function Glob(text) {

    var glob = text.split('.');

    // Returns true if glob matches current $state name.
    this.matches = function(state) {
      var segments = state.name.split('.');

      // match greedy starts
      if (glob[0] === '**') {
         segments = segments.slice(segments.indexOf(glob[1]));
         segments.unshift('**');
      }
      // match greedy ends
      if (glob[glob.length - 1] === '**') {
         segments.splice(segments.indexOf(glob[glob.length - 2]) + 1, Number.MAX_VALUE);
         segments.push('**');
      }
      if (glob.length != segments.length) return false;

      // match single stars
      for (var i = 0, l = glob.length; i < l; i++) {
        if (glob[i] === '*') segments[i] = '*';
      }

      return segments.join('') === glob.join('');
    };
  }

  return {
    // Checks text to see if it looks like a glob.
    is: function(text) {
      return text.indexOf('*') > -1;
    },

    // Factories a glob matcher from a string
    fromString: function(text) {
      if (!this.is(text)) return null;
      return new Glob(text);
    }
  };
})();


function StateQueueManager(states, builder, $urlRouterProvider) {
  var queue = [], abstractKey = 'abstract';

  extend(this, {
    register: function(config, pre) {
      // Wrap a new object around the state so we can store our private details easily.
      state = inherit(config, {
        name: builder.name(config),
        self: config,
        resolve: config.resolve || {},
        toString: function() { return this.name; }
      });

      if (!isString(state.name)) throw new Error("State must have a valid name");
      // if (registered.hasOwnProperty(name)) throw new Error("State '" + name + "'' is already defined");
      if (pre)
        queue.unshift(state);
      else
        queue.push(state);
      return state;
    },

    flush: function() {
      var result, state, orphans = [], orphanIdx, previousQueueLength = {};

      while (queue.length > 0) {
        state = queue.shift();
        result = builder.build(state);
        orphanIdx = orphans.indexOf(state);

        if (result) {
          states[state.name] = state;
          this.attachRoute(state);
          if (orphanIdx >= 0) orphans.splice(orphanIdx, 1);
          continue;
        }

        var prev = previousQueueLength[state.name];
        previousQueueLength[state.name] = queue.length;
        if (orphanIdx >= 0 && prev === queue.length) {
          // Wait until two consecutive iterations where no additional states were dequeued successfully.
          throw new Error("Cannot register orphaned state '" + state.name + "'");
        } else if (orphanIdx < 0) {
          orphans.push(state);
        }

        queue.push(state);
      }
      return states;
    },

    attachRoute: function(state) {
      if (state[abstractKey] || !state.url) return;

      $urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
        if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
          $state.transitionTo(state, $match, { location: false });
        }
      }]);
    }
  });
}

// Builds state properties from definition passed to StateQueueManager.register()
function StateBuilder(root, matcher, $urlMatcherFactoryProvider) {

  var self = this, delegates = {}, builders = {

    parent: function(state) {
      return matcher.find(self.parentName(state));
    },

    data: function(state) {
      if (state.parent && state.parent.data) {
{'fraction_non_alphanumeric': 0.1507854940537366, 'fraction_numerical': 0.003083247687564234, 'mean_word_length': 2.3840039741679084, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, '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': '4173036', 'n_tokens_mistral': 2044, 'n_tokens_neox': 1979, 'n_words': 516}