<commit_before>import { parse } from 'babylon';
import { tryRequire } from '../utils';

const typescript = tryRequire('typescript');

const defaultCompileOptions = {
  module: typescript.ModuleKind.CommonJS,
  target: typescript.ScriptTarget.Latest,
  jsx: typescript.JsxEmit.React,
};

export default function parseTypescript(content, filePath) {
  if (!typescript) {
    return [];
  }

  const result = typescript.transpile(
    content,
    defaultCompileOptions,
    filePath);

  // TODO avoid parse source file twice, use Typescript native traverser to find out dependencies.
  // Reference: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter
  return parse(result, {
    sourceType: 'module',
  });
}<commit_msg>Enable ES6/7 syntax in Typescript (#258)<commit_after>import { parse } from 'babylon';
import { tryRequire } from '../utils';

const typescript = tryRequire('typescript');

const defaultCompileOptions = {
  module: typescript.ModuleKind.CommonJS,
  target: typescript.ScriptTarget.Latest,
  jsx: typescript.JsxEmit.React,
};

export default function parseTypescript(content, filePath) {
  if (!typescript) {
    return [];
  }

  const result = typescript.transpile(
    content,
    defaultCompileOptions,
    filePath);

  // TODO avoid parse source file twice, use Typescript native traverser to find out dependencies.
  // Reference: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter
  return parse(result, {
    sourceType: 'module',
    plugins: ['*'],
  });
}
{'fraction_non_alphanumeric': 0.12304809494066209, 'fraction_numerical': 0.003123048094940662, 'mean_word_length': 4.252459016393443, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7286754', 'n_tokens_mistral': 496, 'n_tokens_neox': 476, 'n_words': 112}