<commit_before>import { assign, kebabCase } from './helpers';
import {
  DIRECTIVE_SUFFIX,
  identifierForController,
  instantiateDirective,
  removeReplaceableDirectiveProperties,
} from './ngHelpers';
import attachToModule from './attachToModule';
import proxifyAngular from './proxifyAngular';


function injectDirective(name, directiveFactory, injularData) {
  const { $injector } = injularData;
  const directives = $injector.get(`${name}${DIRECTIVE_SUFFIX}`);
  const directive = directives[0];
  const newDirective = instantiateDirective(name, directiveFactory, $injector);
  removeReplaceableDirectiveProperties(directive);
  assign(directive, newDirective);
  const $compile = $injector.get('$compile');
  const $rootElement = $injector.get('$rootElement');
  const kebabName = kebabCase(name);
  const $componentElements = $rootElement.find(kebabName);
  for (let i = 0; i < $componentElements.length; i += 1) {
    const $componentElement = $componentElements.eq(i);
    const scope = $componentElement.scope();
    const isolateScope = $componentElement.isolateScope();
    const componentScope = isolateScope || scope;
    const parentScope = isolateScope ? scope : scope.$parent;
    componentScope.$destroy();
    let componentTemplate;
    if (directive.template) {
      $componentElement.children().remove();
      componentTemplate = $componentElement[0].outerHTML;
    } else {
      componentTemplate = $componentElement[0].$injularTemplate;
    }
    const $newComponentElement = $compile(componentTemplate)(parentScope);
    $componentElement.replaceWith($newComponentElement);
    $newComponentElement.scope().$digest();
  }
}


function injectComponent(name, options, injularData) {
  // Code from $compileProvider.component
  // eslint-disable-next-line func-names
  const controller = options.controller || function () {};

  function factory($injector) {
    function makeInjectable(fn) {
      if (typeof fn === 'function' || Array.isArray(fn)) {
        // eslint-disable-next-line func-names
        return function (tElement, tAttrs) {
          return $injector.invoke(fn, this, { $element: tElement, $attrs: tAttrs });
        };
      }
      return fn;
    }

    const template = (!options.template && !options.templateUrl ? '' : options.template);
    const ddo = {
      controller,
      controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
      template: makeInjectable(template),
      templateUrl: makeInjectable(options.templateUrl),
      transclude: options.transclude,
      scope: {},
      bindToController: options.bindings || {},
      restrict: 'E',
      require: options.require,<commit_msg>Fix undefined scope<commit_after>import { assign, kebabCase } from './helpers';
import {
  DIRECTIVE_SUFFIX,
  identifierForController,
  instantiateDirective,
  removeReplaceableDirectiveProperties,
} from './ngHelpers';
import attachToModule from './attachToModule';
import proxifyAngular from './proxifyAngular';


function injectDirective(name, directiveFactory, injularData) {
  const { $injector } = injularData;
  const directives = $injector.get(`${name}${DIRECTIVE_SUFFIX}`);
  const directive = directives[0];
  const newDirective = instantiateDirective(name, directiveFactory, $injector);
  removeReplaceableDirectiveProperties(directive);
  assign(directive, newDirective);
  const $compile = $injector.get('$compile');
  const $rootElement = $injector.get('$rootElement');
  const kebabName = kebabCase(name);
  const $componentElements = $rootElement.find(kebabName);
  for (let i = 0; i < $componentElements.length; i += 1) {
    const $componentElement = $componentElements.eq(i);
    const scope = $componentElement.scope();
    const isolateScope = $componentElement.isolateScope();
    const componentScope = isolateScope || scope;
    const parentScope = isolateScope ? scope : scope.$parent;
    componentScope.$destroy();
    let componentTemplate;
    if (directive.template) {
      $componentElement.children().remove();
      componentTemplate = $componentElement[0].outerHTML;
    } else {
      componentTemplate = $componentElement[0].$injularTemplate;
    }
    const $newComponentElement = $compile(componentTemplate)(parentScope);
    $componentElement.replaceWith($newComponentElement);
    parentScope.$digest();
  }
}


function injectComponent(name, options, injularData) {
  // Code from $compileProvider.component
  // eslint-disable-next-line func-names
  const controller = options.controller || function () {};

  function factory($injector) {
    function makeInjectable(fn) {
      if (typeof fn === 'function' || Array.isArray(fn)) {
        // eslint-disable-next-line func-names
        return function (tElement, tAttrs) {
          return $injector.invoke(fn, this, { $element: tElement, $attrs: tAttrs });
        };
      }
      return fn;
    }

    const template = (!options.template && !options.templateUrl ? '' : options.template);
    const ddo = {
      controller,
      controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
      template: makeInjectable(template),
      templateUrl: makeInjectable(options.templateUrl),
      transclude: options.transclude,
      scope: {},
      bindToController: options.bindings || {},
      restrict: 'E',
      require: options.require,
{'fraction_non_alphanumeric': 0.12525629077353215, 'fraction_numerical': 0.001863932898415657, 'mean_word_length': 4.209708737864077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7170349', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1487, 'n_words': 315}