<commit_before>"use strict";

var fs = require("fs");
var fsp = require("path");
var util = require('./util');
var cacheSync = require('./cacheSync');

function tsCompile(source, path, options) {
	var ts = require('typescript');
	var tsOptions = {
		compilerOptions: options.typescript || {
			target: ts.ScriptTarget.ES2015,
			module: ts.ModuleKind.ES2015,
			sourceMap: true,
		},
		fileName: path,
	};
	return ts.transpileModule(source, tsOptions);
}

exports.transform = function(source, options) {
	var path = options.filename;
	if (options.ignore && path && options.ignore(path)) {
		return {
			code: source,
		};
	}
	if (!options.quiet) util.log("transforming (" + options.runtime + "): " + path);<commit_msg>issue #361 - fail if typescript transpiler reports syntax errors<commit_after>"use strict";

var fs = require("fs");
var fsp = require("path");
var util = require('./util');
var cacheSync = require('./cacheSync');

function tsCheck(result, path) {
	if (result.diagnostics.length > 0) {
		result.diagnostics.forEach(function(diag) {
			var lines = diag.file.text.substring(0, diag.start).split('\n');
			var line = lines.length;
			var col = lines[line - 1].length;
			console.error(diag.file.path + ': ' + diag.messageText + ' (' + line + ':' + col + ')');
		});
		throw new Error(path + ': typescript transpilation failed (' + result.diagnostics.length + ' error(s))');
	}
	return result;
}

function tsCompile(source, path, options) {
	var ts = require('typescript');
	var tsOptions = {
		compilerOptions: options.typescript || {
			target: ts.ScriptTarget.ES2015,
			module: ts.ModuleKind.ES2015,
			sourceMap: true,
		},
		fileName: path,
		reportDiagnostics: true,
	};
	return tsCheck(ts.transpileModule(source, tsOptions), path);
}

exports.transform = function(source, options) {
	var path = options.filename;
	if (options.ignore && path && options.ignore(path)) {
		return {
			code: source,
		};
	}
	if (!options.quiet) util.log("transforming (" + options.runtime + "): " + path);
{'fraction_non_alphanumeric': 0.16641753861484804, 'fraction_numerical': 0.01096163428001993, 'mean_word_length': 4.270341207349081, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2716998', 'n_tokens_mistral': 706, 'n_tokens_neox': 644, 'n_words': 150}