<commit_before>import {
  assign,
  guidFor,
  dictionary,
  getOwner
} from 'ember-utils';
import Logger from 'ember-console';
import {
  get,
  set,
  defineProperty,
  computed,
  run,
  deprecateProperty
} from 'ember-metal';
import {
  Error as EmberError,
  deprecate,
  assert,
  info
} from 'ember-debug';
import {
  Object as EmberObject,
  Evented,
  typeOf,
  A as emberA
} from 'ember-runtime';
import {
  defaultSerialize,
  hasDefaultSerialize
} from './route';
import EmberRouterDSL from './dsl';
import EmberLocation from '../location/api';
import {
  routeArgs,
  getActiveTargetName,
  calculateCacheKey
} from '../utils';
import RouterState from './router_state';
import { DEBUG } from 'ember-env-flags';

/**
@module @ember/routing
*/

import Router from 'router';

function K() { return this; }

const { slice } = Array.prototype;


/**
  The `Ember.Router` class manages the application state and URLs. Refer to
  the [routing guide](https://emberjs.com/guides/routing/) for documentation.

  @class Router
  @extends EmberObject
  @uses Evented
  @public
*/
const EmberRouter = EmberObject.extend(Evented, {
  /**
    The `location` property determines the type of URL's that your
    application will use.

    The following location types are currently available:

    * `history` - use the browser's history API to make the URLs look just like any standard URL
    * `hash` - use `#` to separate the server part of the URL from the Ember part: `/blog/#/posts/new`
    * `none` - do not store the Ember URL in the actual browser URL (mainly used for testing)
    * `auto` - use the best option based on browser capabilities: `history` if possible, then `hash` if possible, otherwise `none`

    This value is defaulted to `auto` by the `locationType` setting of `/config/environment.js`

    @property location
    @default 'hash'
    @see {Location}
    @public
  */
  location: 'hash',

  /**
   Represents the URL of the root of the application, often '/'. This prefix is
   assumed on all routes defined on this router.

   @property rootURL
   @default '/'
   @public
  */
  rootURL: '/',

  _initRouterJs() {
    let routerMicrolib = this._routerMicrolib = new Router();
    routerMicrolib.triggerEvent = triggerEvent.bind(this);

    routerMicrolib._triggerWillChangeContext = K;
    routerMicrolib._triggerWillLeave = K;

    let dslCallbacks = this.constructor.dslCallbacks || [K];
    let dsl = this._buildDSL();

    dsl.route('application', { path: '/', resetNamespace: true, overrideNameAssertion: true }, function() {
      for (let i = 0; i < dslCallbacks.length; i++) {
        dslCallbacks[i].call(this);
      }
    });

    if (DEBUG) {
      if (get(this, 'namespace.LOG_TRANSITIONS_INTERNAL')) {
        routerMicrolib.log = Logger.debug;
      }
    }

    routerMicrolib.map(dsl.generate());
  },

  _buildDSL() {
    let moduleBasedResolver = this._hasModuleBasedResolver();
    let options = {
      enableLoadingSubstates: !!moduleBasedResolver
    };

    let owner = getOwner(this);
    let router = this;

    options.resolveRouteMap = name => owner.factoryFor(`route-map:${name}`);

    options.addRouteForEngine = (name, engineInfo) => {
      if (!router._engineInfoByRoute[name]) {
        router._engineInfoByRoute[name] = engineInfo;
      }
    };

    return new EmberRouterDSL(null, options);
  },

  init() {
    this._super(...arguments);

    this.currentURL = null;
    this.currentRouteName = null;
    this.currentPath = null;

    this._qpCache = Object.create(null);
    this._resetQueuedQueryParameterChanges();
    this._handledErrors = dictionary(null);
    this._engineInstances = Object.create(null);
    this._engineInfoByRoute = Object.create(null)
  },

  /*
    Resets all pending query parameter changes.
    Called after transitioning to a new route
    based on query parameter changes.
  */
  _resetQueuedQueryParameterChanges() {
    this._queuedQPChanges = {};
  },

  /**
    Represents the current URL.

    @method url
    @return {String} The current URL.
    @private
  */
  url: computed(function() {
    return get(this, 'location').getURL();
  }),

  _hasModuleBasedResolver() {
    let owner = getOwner(this);

    if (!owner) { return false; }

    let resolver = owner.application && owner.application.__registry__ && owner.application.__registry__.resolver;

    if (!resolver) { return false; }

    return !!resolver.moduleBasedResolver;
  },

  /**
    Initializes the current router instance and sets up the change handling
    event listeners used by the instances `location` implementation.
<commit_msg>avoid extra boolean conversion<commit_after>import {
  assign,
  guidFor,
  dictionary,
  getOwner
} from 'ember-utils';
import Logger from 'ember-console';
import {
  get,
  set,
  defineProperty,
  computed,
  run,
  deprecateProperty
} from 'ember-metal';
import {
  Error as EmberError,
  deprecate,
  assert,
  info
} from 'ember-debug';
import {
  Object as EmberObject,
  Evented,
  typeOf,
  A as emberA
} from 'ember-runtime';
import {
  defaultSerialize,
  hasDefaultSerialize
} from './route';
import EmberRouterDSL from './dsl';
import EmberLocation from '../location/api';
import {
  routeArgs,
  getActiveTargetName,
  calculateCacheKey
} from '../utils';
import RouterState from './router_state';
import { DEBUG } from 'ember-env-flags';

/**
@module @ember/routing
*/

import Router from 'router';

function K() { return this; }

const { slice } = Array.prototype;


/**
  The `Ember.Router` class manages the application state and URLs. Refer to
  the [routing guide](https://emberjs.com/guides/routing/) for documentation.

  @class Router
  @extends EmberObject
  @uses Evented
  @public
*/
const EmberRouter = EmberObject.extend(Evented, {
  /**
    The `location` property determines the type of URL's that your
    application will use.

    The following location types are currently available:

    * `history` - use the browser's history API to make the URLs look just like any standard URL
    * `hash` - use `#` to separate the server part of the URL from the Ember part: `/blog/#/posts/new`
    * `none` - do not store the Ember URL in the actual browser URL (mainly used for testing)
    * `auto` - use the best option based on browser capabilities: `history` if possible, then `hash` if possible, otherwise `none`

    This value is defaulted to `auto` by the `locationType` setting of `/config/environment.js`

    @property location
    @default 'hash'
    @see {Location}
    @public
  */
  location: 'hash',

  /**
   Represents the URL of the root of the application, often '/'. This prefix is
   assumed on all routes defined on this router.

   @property rootURL
   @default '/'
   @public
  */
  rootURL: '/',

  _initRouterJs() {
    let routerMicrolib = this._routerMicrolib = new Router();
    routerMicrolib.triggerEvent = triggerEvent.bind(this);

    routerMicrolib._triggerWillChangeContext = K;
    routerMicrolib._triggerWillLeave = K;

    let dslCallbacks = this.constructor.dslCallbacks || [K];
    let dsl = this._buildDSL();

    dsl.route('application', { path: '/', resetNamespace: true, overrideNameAssertion: true }, function() {
      for (let i = 0; i < dslCallbacks.length; i++) {
        dslCallbacks[i].call(this);
      }
    });

    if (DEBUG) {
      if (get(this, 'namespace.LOG_TRANSITIONS_INTERNAL')) {
        routerMicrolib.log = Logger.debug;
      }
    }

    routerMicrolib.map(dsl.generate());
  },

  _buildDSL() {
    let enableLoadingSubstates = this._hasModuleBasedResolver();
    let options = { enableLoadingSubstates };

    let owner = getOwner(this);
    let router = this;

    options.resolveRouteMap = name => owner.factoryFor(`route-map:${name}`);

    options.addRouteForEngine = (name, engineInfo) => {
      if (!router._engineInfoByRoute[name]) {
        router._engineInfoByRoute[name] = engineInfo;
      }
    };

    return new EmberRouterDSL(null, options);
  },

  init() {
    this._super(...arguments);

    this.currentURL = null;
    this.currentRouteName = null;
    this.currentPath = null;

    this._qpCache = Object.create(null);
    this._resetQueuedQueryParameterChanges();
    this._handledErrors = dictionary(null);
    this._engineInstances = Object.create(null);
    this._engineInfoByRoute = Object.create(null)
  },

  /*
    Resets all pending query parameter changes.
    Called after transitioning to a new route
    based on query parameter changes.
  */
  _resetQueuedQueryParameterChanges() {
    this._queuedQPChanges = {};
  },

  /**
    Represents the current URL.

    @method url
    @return {String} The current URL.
    @private
  */
  url: computed(function() {
    return get(this, 'location').getURL();
  }),

  _hasModuleBasedResolver() {
    let owner = getOwner(this);
    if (!owner) { return false; }

    let resolver = get(owner, 'application.__registry__.resolver.moduleBasedResolver');
    return !!resolver;
  },

  /**
    Initializes the current router instance and sets up the change handling
    event listeners used by the instances `location` implementation.

{'fraction_non_alphanumeric': 0.11498793065613343, 'fraction_numerical': 0.00021944261575597982, 'mean_word_length': 3.2894117647058825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '1204492', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2731, 'n_words': 797}