<commit_before>import { pick, clone, extend, isEqual, isString, find } from './dash'
import dsl from './dsl'
import Path from './path'
import invariant from './invariant'
import BrowserLocation from './locations/browser'
import MemoryLocation from './locations/memory'
import transition from './transition'
import { intercept } from './links'
import createLogger from './logger'
import qs from './qs'

function Cherrytree () {
  this.initialize.apply(this, arguments)
}

/**
 * The actual constructor
 * @param {Object} options
 */
Cherrytree.prototype.initialize = function (options) {
  this.nextId = 1
  this.state = {}
  this.middleware = []
  this.options = extend({
    location: 'browser',
    interceptLinks: true,
    logError: true,
    Promise: Promise,
    qs: qs
  }, options)
  this.log = createLogger(this.options.log)
  this.logError = createLogger(this.options.logError, { error: true })

  invariant(typeof this.options.Promise === 'function',
    'Cherrytree requires an ES6 Promise implementation, ' +
    'either as an explicit option or a global Promise')
}

/**
 * Add a middleware
 * @param  {Function} middleware
 * @return {Object}   router
 * @api public
 */
Cherrytree.prototype.use = function (middleware) {
  this.middleware.push(middleware)
  return this
}

/**
 * Add the route map
 * @param  {Function} routes
 * @return {Object}   router
 * @api public
 */
Cherrytree.prototype.map = function (routes) {
  // create the route tree
  this.routes = dsl(routes)

  // create the matcher list, which is like a flattened
  // list of routes = a list of all branches of the route tree
  let matchers = this.matchers = []
  // keep track of whether duplicate paths have been created,
  // in which case we'll warn the dev
  let dupes = {}

  eachBranch({routes: this.routes}, [], function (routes) {
    // concatenate the paths of the list of routes
    let path = routes.reduce(function (memo, r) {
      // reset if there's a leading slash, otherwise concat
      // and keep resetting the trailing slash
      return (r.path[0] === '/' ? r.path : memo + '/' + r.path).replace(/\/$/, '')
    }, '')
    // ensure we have a leading slash
    if (path === '') {
      path = '/'
    }
    // register routes
    matchers.push({
      routes: routes,
      name: routes[routes.length - 1].name,
      path: path
    })

    // dupe detection
    let lastRoute = routes[routes.length - 1]
    if (dupes[path]) {
      throw new Error('Routes ' + dupes[path] + ' and ' + lastRoute.name +
      ' have the same url path \'' + path + '\'')
    }
    dupes[path] = lastRoute.name
  })

  function eachBranch (node, memo, fn) {
    node.routes.forEach(function (route) {
      if (!abstract(route)) {
        fn(memo.concat(route))
      }
      if (route.routes && route.routes.length > 0) {
        eachBranch(route, memo.concat(route), fn)
      }
    })
  }

  function abstract (route) {
    return route.options && route.options.abstract
  }

  return this
}
<commit_msg>Remove redundant code from Cherrytree.prototype.map<commit_after>import { pick, clone, extend, isEqual, isString, find } from './dash'
import dsl from './dsl'
import Path from './path'
import invariant from './invariant'
import BrowserLocation from './locations/browser'
import MemoryLocation from './locations/memory'
import transition from './transition'
import { intercept } from './links'
import createLogger from './logger'
import qs from './qs'

function Cherrytree () {
  this.initialize.apply(this, arguments)
}

/**
 * The actual constructor
 * @param {Object} options
 */
Cherrytree.prototype.initialize = function (options) {
  this.nextId = 1
  this.state = {}
  this.middleware = []
  this.options = extend({
    location: 'browser',
    interceptLinks: true,
    logError: true,
    Promise: Promise,
    qs: qs
  }, options)
  this.log = createLogger(this.options.log)
  this.logError = createLogger(this.options.logError, { error: true })

  invariant(typeof this.options.Promise === 'function',
    'Cherrytree requires an ES6 Promise implementation, ' +
    'either as an explicit option or a global Promise')
}

/**
 * Add a middleware
 * @param  {Function} middleware
 * @return {Object}   router
 * @api public
 */
Cherrytree.prototype.use = function (middleware) {
  this.middleware.push(middleware)
  return this
}

/**
 * Add the route map
 * @param  {Function} routes
 * @return {Object}   router
 * @api public
 */
Cherrytree.prototype.map = function (routes) {
  // create the route tree
  this.routes = dsl(routes)

  // create the matcher list, which is like a flattened
  // list of routes = a list of all branches of the route tree
  let matchers = this.matchers = []
  // keep track of whether duplicate paths have been created,
  // in which case we'll warn the dev
  let dupes = {}

  eachBranch({routes: this.routes}, [], function (routes) {
    // concatenate the paths of the list of routes
    let path = routes.reduce(function (memo, r) {
      // reset if there's a leading slash, otherwise concat
      // and keep resetting the trailing slash
      return (r.path[0] === '/' ? r.path : memo + '/' + r.path).replace(/\/$/, '')
    }, '')
    // ensure we have a leading slash
    if (path === '') {
      path = '/'
    }

    let lastRoute = routes[routes.length - 1]

    // register routes
    matchers.push({
      routes: routes,
      name: lastRoute.name,
      path: path
    })

    // dupe detection
    if (dupes[path]) {
      throw new Error('Routes ' + dupes[path] + ' and ' + lastRoute.name +
      ' have the same url path \'' + path + '\'')
    }
    dupes[path] = lastRoute.name
  })

  function eachBranch (node, memo, fn) {
    node.routes.forEach(function (route) {
      if (!route.options.abstract) {
        fn(memo.concat(route))
      }
      if (route.routes.length) {
        eachBranch(route, memo.concat(route), fn)
      }
    })
  }

  return this
}

{'fraction_non_alphanumeric': 0.13426786015875697, 'fraction_numerical': 0.0016889039013680122, 'mean_word_length': 2.8579804560260587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5150393', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1789, 'n_words': 557}