<commit_before>import {CompilerHost} from './compiler-host';
import {Transpiler} from './transpiler';
import {TypeChecker} from './type-checker';

import Logger from './logger';
import {formatErrors} from './format-errors';
import {isTypescript} from './utils';

let logger = new Logger({ debug: false });
let host = new CompilerHost(System.typescriptOptions);
let transpiler = new Transpiler(host);
let typeChecker = new TypeChecker(host, _resolve, _fetch);

/*
 * load.name
 * load.address
 * load.metadata
 * load.source: the fetched source
 */
export function translate(load) {
	logger.debug(`systemjs translating ${load.address}`);

	let result = transpiler.transpile(load.address, load.source);
	formatErrors(result.errors, logger);

	if (result.failure)
		throw new Error("TypeScript transpilation failed");

	if (host.options.typeCheck && isTypescript(load.address))
		typeChecker.check(load.address, load.source)
			.then((diags) => formatErrors(diags, logger));

	load.source = wrapSource(result.js, load);
	load.metadata.sourceMap = result.sourceMap;
	load.metadata.format = 'register';
	return load;
}

function wrapSource(source, load) {
	return '(function(__moduleName){' + source + '\n})("' + load.name + '");\n//# sourceURL=' + load.address + '!transpiled';
}

/*
 * called by the type-checker when it needs to resolve a file
 */
function _resolve(dep, parent) {
	if (!parent)
		parent = __moduleName;

	return System.normalize(dep, parent)
		.then(function (normalized) {
			if (normalized.slice(-6) == '.ts.js')
				normalized = normalized.slice(0, -3);
<commit_msg>chore(extensions): remove unneeded code<commit_after>import {CompilerHost} from './compiler-host';
import {Transpiler} from './transpiler';
import {TypeChecker} from './type-checker';

import Logger from './logger';
import {formatErrors} from './format-errors';
import {isTypescript} from './utils';

let logger = new Logger({ debug: false });
let host = new CompilerHost(System.typescriptOptions);
let transpiler = new Transpiler(host);
let typeChecker = new TypeChecker(host, _resolve, _fetch);

/*
 * load.name
 * load.address
 * load.metadata
 * load.source: the fetched source
 */
export function translate(load) {
	logger.debug(`systemjs translating ${load.address}`);

	let result = transpiler.transpile(load.address, load.source);
	formatErrors(result.errors, logger);

	if (result.failure)
		throw new Error("TypeScript transpilation failed");

	if (host.options.typeCheck && isTypescript(load.address))
		typeChecker.check(load.address, load.source)
			.then((diags) => formatErrors(diags, logger));

	load.source = wrapSource(result.js, load);
	load.metadata.sourceMap = result.sourceMap;
	load.metadata.format = 'register';
	return load;
}

function wrapSource(source, load) {
	return '(function(__moduleName){' + source + '\n})("' + load.name + '");\n//# sourceURL=' + load.address + '!transpiled';
}

/*
 * called by the type-checker when it needs to resolve a file
 */
function _resolve(dep, parent) {
	if (!parent) parent = __moduleName;

	return System.normalize(dep, parent)
		.then(function (normalized) {
{'fraction_non_alphanumeric': 0.15186615186615188, 'fraction_numerical': 0.0009652509652509653, 'mean_word_length': 4.9788461538461535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2916339', 'n_tokens_mistral': 992, 'n_tokens_neox': 970, 'n_words': 253}