<commit_before>import { camelize, dasherize, cssText, toCSS, forEach, keys, reduce, map, trim } from 'dinosheets/utils';

var sheet;
function testerSheet() {
  if (sheet) {
    return sheet;
  }

  const element = document.createElement('style');
  const head = document.getElementsByTagName('head')[0] ||
               document.documentElement;
  element.type = 'text/css';
  head.appendChild(element);

  return sheet = document.styleSheets[document.styleSheets.length - 1];
}
const supportedCssRules = {};

class StyleSheetShim {
  constructor(styleSheet) {
    this.styleSheet = styleSheet;
    this.indexes = {};
    this.styles = {};
  }

  rules() {
    const { styleSheet } = this;
    return styleSheet.cssRules || styleSheet.rules || [];
  }

  ruleFor(selector) {
    const index = this.indexes[selector];
    if (index == null) { return null; }
    const rules = this.rules();

    return {
      index,
      rule: rules[index]
    };
  }

  canApplyRule(rule, value) {
    if (supportedCssRules.hasOwnProperty(rule)) {
      return supportedCssRules[rule];
    }

    const styleSheet = testerSheet();
    const selector = '#dinosheet---tester---selector';
    const css = `${dasherize(rule)}: ${value};`;

    if (styleSheet.insertRule) {
      styleSheet.insertRule(`${selector} { ${css} }`, 0);
    } else {
      styleSheet.addRule(selector, css, 0);
    }

    const rules = sheet.cssRules || sheet.rules || [];
    if (cssText(rules[0]).length > selector.length + css.length) {
      supportedCssRules[rule] = true;
    } else {
      supportedCssRules[rule] = false;
    }

    if (styleSheet.deleteRule) {
      styleSheet.deleteRule(selector, 0);
    } else {
      styleSheet.removeRule(0);
    }
    return supportedCssRules[rule];
  }

  insertRule(selector, rules, index) {
    const { styleSheet } = this;

    // Lint out all rules that can't be applied
/*    rules = reduce(keys(rules), (E, rule) => {
      let value = rules[rule];
      if (this.canApplyRule(rule, value)) {
        E[rule] = value;
      }
      return E;
    }, {});*/

    const css = toCSS(rules);

    if (index == null) {
      index = this.rules().length;
    }

    if (css.length) {
      this.indexes[selector] = index;
      this.styles[selector] = rules;
      if (styleSheet.insertRule) {
        styleSheet.insertRule(`${selector} { ${css} }`, index);
      } else {
        styleSheet.addRule(selector, css, index);

        if (this.ruleFor(selector).rule.selectorText.toLowerCase() !== selector.toLowerCase()) {
          delete this.indexes[selector];
          delete this.styles[selector];
          this._splitsSelectors = true;
          forEach(map(selector.split(','), trim), (selector) => {
            this.indexes[selector] = index++;
            this.styles[selector] = rules;
          });
        }
      }
    }
  }

  updateRule(selector, rules) {
    if (this._splitsSelectors && selector.indexOf(',') !== -1) {
      forEach(map(selector.split(','), trim), (selector) => {
        this.updateRule(selector, rules);
      });
      return;
    }

    // Lint out all rules that can't be applied
/*    rules = reduce(keys(rules), (E, rule) => {
      let value = rules[rule];
      if (this.canApplyRule(rule, value)) {
        E[rule] = value;
      }
      return E;
    }, {});*/

    const { rule } = this.ruleFor(selector);
    for (let key in rules) {
      if (!rules.hasOwnProperty(key)) { continue; }
      let value = rules[key];
      key = camelize(key);
      if (key == null) { continue; }

      if (value == null) {
        delete this.styles[selector][key];
        if (rule.style.removeProperty) {
          rule.style.removeProperty(dasherize(key));
        } else {
          rule.style[key] = null;
        }
      } else {
        this.styles[selector][key] = value;
        rule.style[key] = value;
      }
    }
  }

  insertOrUpdateRule(selector, rules) {
    if (this.ruleFor(selector)) {
      this.updateRule(selector, rules);
    } else {
      this.insertRule(selector, rules);
    }
  }<commit_msg>Revert "temporarily remove canApplyRule calls to see where failures are in IE8"<commit_after>import { camelize, dasherize, cssText, toCSS, forEach, keys, reduce, map, trim } from 'dinosheets/utils';

var sheet;
function testerSheet() {
  if (sheet) {
    return sheet;
  }

  const element = document.createElement('style');
  const head = document.getElementsByTagName('head')[0] ||
               document.documentElement;
  element.type = 'text/css';
  head.appendChild(element);

  return sheet = document.styleSheets[document.styleSheets.length - 1];
}
const supportedCssRules = {};

class StyleSheetShim {
  constructor(styleSheet) {
    this.styleSheet = styleSheet;
    this.indexes = {};
    this.styles = {};
  }

  rules() {
    const { styleSheet } = this;
    return styleSheet.cssRules || styleSheet.rules || [];
  }

  ruleFor(selector) {
    const index = this.indexes[selector];
    if (index == null) { return null; }
    const rules = this.rules();

    return {
      index,
      rule: rules[index]
    };
  }

  canApplyRule(rule, value) {
    if (supportedCssRules.hasOwnProperty(rule)) {
      return supportedCssRules[rule];
    }

    const styleSheet = testerSheet();
    const selector = '#dinosheet---tester---selector';
    const css = `${dasherize(rule)}: ${value};`;

    if (styleSheet.insertRule) {
      styleSheet.insertRule(`${selector} { ${css} }`, 0);
    } else {
      styleSheet.addRule(selector, css, 0);
    }

    const rules = sheet.cssRules || sheet.rules || [];
    if (cssText(rules[0]).length > selector.length + css.length) {
      supportedCssRules[rule] = true;
    } else {
      supportedCssRules[rule] = false;
    }

    if (styleSheet.deleteRule) {
      styleSheet.deleteRule(selector, 0);
    } else {
      styleSheet.removeRule(0);
    }
    return supportedCssRules[rule];
  }

  insertRule(selector, rules, index) {
    const { styleSheet } = this;

    // Lint out all rules that can't be applied
    rules = reduce(keys(rules), (E, rule) => {
      let value = rules[rule];
      if (this.canApplyRule(rule, value)) {
        E[rule] = value;
      }
      return E;
    }, {});

    const css = toCSS(rules);

    if (index == null) {
      index = this.rules().length;
    }

    if (css.length) {
      this.indexes[selector] = index;
      this.styles[selector] = rules;
      if (styleSheet.insertRule) {
        styleSheet.insertRule(`${selector} { ${css} }`, index);
      } else {
        styleSheet.addRule(selector, css, index);

        if (this.ruleFor(selector).rule.selectorText.toLowerCase() !== selector.toLowerCase()) {
          delete this.indexes[selector];
          delete this.styles[selector];
          this._splitsSelectors = true;
          forEach(map(selector.split(','), trim), (selector) => {
            this.indexes[selector] = index++;
            this.styles[selector] = rules;
          });
        }
      }
    }
  }

  updateRule(selector, rules) {
    if (this._splitsSelectors && selector.indexOf(',') !== -1) {
      forEach(map(selector.split(','), trim), (selector) => {
        this.updateRule(selector, rules);
      });
      return;
    }

    // Lint out all rules that can't be applied
    rules = reduce(keys(rules), (E, rule) => {
      let value = rules[rule];
      if (this.canApplyRule(rule, value)) {
        E[rule] = value;
      }
      return E;
    }, {});

    const { rule } = this.ruleFor(selector);
    for (let key in rules) {
      if (!rules.hasOwnProperty(key)) { continue; }
      let value = rules[key];
      key = camelize(key);
      if (key == null) { continue; }

      if (value == null) {
        delete this.styles[selector][key];
        if (rule.style.removeProperty) {
          rule.style.removeProperty(dasherize(key));
        } else {
          rule.style[key] = null;
        }
      } else {
        this.styles[selector][key] = value;
        rule.style[key] = value;
      }
    }
  }

  insertOrUpdateRule(selector, rules) {
    if (this.ruleFor(selector)) {
      this.updateRule(selector, rules);
    } else {
      this.insertRule(selector, rules);
    }
  }
{'fraction_non_alphanumeric': 0.15036674816625917, 'fraction_numerical': 0.002078239608801956, 'mean_word_length': 2.4783163265306123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '45314', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2547, 'n_words': 527}