<commit_before>import { stringify, parse as parseQuery } from 'query-string'
import React, { PropTypes } from 'react'
import MatchCountProvider from './MatchCountProvider'
import { createLocation } from './LocationUtils'
import {
  action as actionType,
  location as locationType,
  router as routerType
} from './PropTypes'

const isPartialDescriptor = (loc) => !!loc.path


class StaticRouter extends React.Component {

  static propTypes = {
    action: actionType.isRequired,
    blockTransitions: PropTypes.func.isRequired,
    children: PropTypes.oneOfType([ PropTypes.node, PropTypes.func ]),
    createHref: PropTypes.func.isRequired,
    location: locationType.isRequired,
    onPush: PropTypes.func.isRequired,
    onReplace: PropTypes.func.isRequired,
    stringifyQuery: PropTypes.func.isRequired,
    parseQuery: PropTypes.func.isRequired
  }

  static defaultProps = {
    createHref: (loc) => {
      return loc
    },
    stringifyQuery: (query) => stringify(query).replace(/%20/g, '+'),
    parseQuery
  }

  static childContextTypes = {
    router: routerType.isRequired,
    location: locationType.isRequired
  }

  getChildContext() {
    return {
      location: this.getLocation(),
      router: {
        createHref: (to) => this.props.createHref(to),
        transitionTo: (loc) => this.props.onPush(loc),
        replaceWith: (loc) => this.props.onReplace(loc),
        blockTransitions: (getPromptMessage) => this.blockTransitions(getPromptMessage)
      }
    }
  }

  createLocationFromPathname() {
    const { location:pathname, parseQuery } = this.props
    return {
      ...createLocation({ input: pathname, parseQuery }),
      state: null
    }
  }

  createLocationFromLocationWithPath() {
    const { location:loc, parseQuery } = this.props
    return {
      ...createLocation({ input: loc.path, parseQuery }),
      state: loc.state || null
    }
  }

  getLocation() {
    // TODO: maybe memoize this on willReceiveProps to get extreme w/ perf
    const { location } = this.props
    return typeof location === 'string' ? (
      this.createLocationFromPathname(location)
    ) : isPartialDescriptor(location) ? (
      this.createLocationFromLocationWithPath(location.path),
    ) : location
  }<commit_msg>fix trailing comma from debugging<commit_after>import { stringify, parse as parseQuery } from 'query-string'
import React, { PropTypes } from 'react'
import MatchCountProvider from './MatchCountProvider'
import { createLocation } from './LocationUtils'
import {
  action as actionType,
  location as locationType,
  router as routerType
} from './PropTypes'

const isPartialDescriptor = (loc) => !!loc.path


class StaticRouter extends React.Component {

  static propTypes = {
    action: actionType.isRequired,
    blockTransitions: PropTypes.func.isRequired,
    children: PropTypes.oneOfType([ PropTypes.node, PropTypes.func ]),
    createHref: PropTypes.func.isRequired,
    location: locationType.isRequired,
    onPush: PropTypes.func.isRequired,
    onReplace: PropTypes.func.isRequired,
    stringifyQuery: PropTypes.func.isRequired,
    parseQuery: PropTypes.func.isRequired
  }

  static defaultProps = {
    createHref: (loc) => {
      return loc
    },
    stringifyQuery: (query) => stringify(query).replace(/%20/g, '+'),
    parseQuery
  }

  static childContextTypes = {
    router: routerType.isRequired,
    location: locationType.isRequired
  }

  getChildContext() {
    return {
      location: this.getLocation(),
      router: {
        createHref: (to) => this.props.createHref(to),
        transitionTo: (loc) => this.props.onPush(loc),
        replaceWith: (loc) => this.props.onReplace(loc),
        blockTransitions: (getPromptMessage) => this.blockTransitions(getPromptMessage)
      }
    }
  }

  createLocationFromPathname() {
    const { location:pathname, parseQuery } = this.props
    return {
      ...createLocation({ input: pathname, parseQuery }),
      state: null
    }
  }

  createLocationFromLocationWithPath() {
    const { location:loc, parseQuery } = this.props
    return {
      ...createLocation({ input: loc.path, parseQuery }),
      state: loc.state || null
    }
  }

  getLocation() {
    // TODO: maybe memoize this on willReceiveProps to get extreme w/ perf
    const { location } = this.props
    return typeof location === 'string' ? (
      this.createLocationFromPathname(location)
    ) : isPartialDescriptor(location) ? (
      this.createLocationFromLocationWithPath(location.path)
    ) : location
  }
{'fraction_non_alphanumeric': 0.11406423034330011, 'fraction_numerical': 0.0008859357696566999, 'mean_word_length': 3.371732817037754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1842409', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1305, 'n_words': 290}