<commit_before>/*global __dirname */
'use strict';
const ts = require('typescript');
const anymatch = require('anymatch');
const path = require('path');

const resolveEnum = (choice, opts) => {
  const defaultValue = 1; // CommonJS/ES5 defaults;
  if (!choice) {
    return defaultValue;
  }
  if (!isNaN(choice)) {
    return choice - 0;
  }
  for (let opt of Object.keys(opts)) {
    if (choice && choice.toUpperCase() === opt.toUpperCase()) {
      return opts[opt];
    }
  }
  return defaultValue;
};

const getTsconfig = (root) => {
  if (!root) {
    return {};
  }
  const file = path.resolve(root, 'tsconfig.json');
  let tsconf;
  try {
    tsconf = require(file);
  } catch (e) {
    return {};
  }
  return tsconf.compilerOptions || {};
};

class TypeScriptCompiler {
  constructor(config) {
    if (!config) config = {};
    const options = config.plugins &&
      config.plugins.brunchTypescript || {};
    this.options = getTsconfig(config.paths && config.paths.root);
    Object.keys(options).forEach(key => {
      if (key === 'sourceMap' || key === 'ignore') return;
      this.options[key] = options[key];
    });
    this.options.module = resolveEnum(this.options.module, ts.ModuleKind);
    this.options.target = resolveEnum(this.options.target, ts.ScriptTarget);
    this.options.emitDecoratorMetadata = this.options.emitDecoratorMetadata !== false,
    this.options.experimentalDecorators = this.options.experimentalDecorators !== false,
    this.options.sourceMap = !!config.sourceMaps;
    this.isIgnored = anymatch(options.ignore || /^(bower_components|vendor|node_modules)/);
    if (this.options.pattern) {
      this.pattern = this.options.pattern;
      delete this.options.pattern;
    }
  }
  
  compile(params) {
    if (this.isIgnored(params.path)) {
      return Promise.resolve(params);
    }
    let tsOptions = {
      fileName: params.path,
      compilerOptions: this.options
    }<commit_msg>Fixed bug with the jsx compiler option not being handled properly.<commit_after>/*global __dirname */
'use strict';
const ts = require('typescript');
const anymatch = require('anymatch');
const path = require('path');

const resolveEnum = (choice, opts) => {
  const defaultValue = 1; // CommonJS/ES5/Preserve JSX defaults
  if (!choice) {
    return defaultValue;
  }
  if (!isNaN(choice)) {
    return choice - 0;
  }
  for (let opt of Object.keys(opts)) {
    if (choice && choice.toUpperCase() === opt.toUpperCase()) {
      return opts[opt];
    }
  }
  return defaultValue;
};

const getTsconfig = (root) => {
  if (!root) {
    return {};
  }
  const file = path.resolve(root, 'tsconfig.json');
  let tsconf;
  try {
    tsconf = require(file);
  } catch (e) {
    return {};
  }
  return tsconf.compilerOptions || {};
};

class TypeScriptCompiler {
  constructor(config) {
    if (!config) config = {};
    const options = config.plugins &&
      config.plugins.brunchTypescript || {};
    this.options = getTsconfig(config.paths && config.paths.root);
    Object.keys(options).forEach(key => {
      if (key === 'sourceMap' || key === 'ignore') return;
      this.options[key] = options[key];
    });
    this.options.module = resolveEnum(this.options.module, ts.ModuleKind);
    this.options.target = resolveEnum(this.options.target, ts.ScriptTarget);
    this.options.jsx = resolveEnum(this.options.jsx, ts.JsxEmit);
    this.options.emitDecoratorMetadata = this.options.emitDecoratorMetadata !== false,
    this.options.experimentalDecorators = this.options.experimentalDecorators !== false,
    this.options.sourceMap = !!config.sourceMaps;
    this.isIgnored = anymatch(options.ignore || /^(bower_components|vendor|node_modules)/);
    if (this.options.pattern) {
      this.pattern = this.options.pattern;
      delete this.options.pattern;
    }
  }
  
  compile(params) {
    if (this.isIgnored(params.path)) {
      return Promise.resolve(params);
    }
    let tsOptions = {
      fileName: params.path,
      compilerOptions: this.options
    }
{'fraction_non_alphanumeric': 0.14886164623467601, 'fraction_numerical': 0.0015011258443832875, 'mean_word_length': 3.3598691384950925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '150731', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1243, 'n_words': 254}