<commit_before>'use strict';

// Bind globals first, before anything has a chance to interfere.
var globals = require('./globals');

var sourceMapCache = Object.create(null);

var sourceMapSupport = require('source-map-support');
sourceMapSupport.install({
	retrieveSourceMap: function (source) {
		if (sourceMapCache[source]) {
			return {
				url: source,
				map: sourceMapCache[source]
			};
		}
		return sourceMapSupport.retrieveSourceMap(source);
	}
});

var createEspowerPlugin = require('babel-plugin-espower/create');
var requireFromString = require('require-from-string');
var loudRejection = require('loud-rejection/api')(process);
var resolveFrom = require('resolve-from');
var hasGenerator = require('has-generator');
var serializeError = require('serialize-error');
var send = require('./send');

var testPath = process.argv[2];

// include local babel and fallback to ava's babel
var babel;

try {
	var localBabel = resolveFrom('.', 'babel-core') || resolveFrom('.', 'babel');
	babel = require(localBabel);
} catch (err) {
	babel = require('babel-core');
}

// initialize power-assert
var powerAssert = createEspowerPlugin(babel, {
	patterns: require('./enhance-assert').PATTERNS
});

// if generators are not supported, use regenerator
var options = {
	blacklist: hasGenerator ? ['regenerator'] : [],
	optional: hasGenerator ? ['asyncToGenerator', 'runtime'] : ['runtime'],
	plugins: [powerAssert],
	sourceMaps: true,
	inputSourceMap: null
};

// check if test files required ava and show error, when they didn't
exports.avaRequired = false;

process.on('uncaughtException', function (exception) {
	send('uncaughtException', {exception: serializeError(exception)});
});

// try to load an input source map for the test file, in case the file was
// already compiled once by the user
var inputSourceMap = sourceMapSupport.retrieveSourceMap(testPath);
if (inputSourceMap) {
	// source-map-support returns the source map as a json-encoded string, but
	// babel requires an actual object
	options.inputSourceMap = JSON.parse(inputSourceMap.map);
}

// include test file
var transpiled = babel.transformFileSync(testPath, options);
sourceMapCache[testPath] = JSON.stringify(transpiled.map);
requireFromString(transpiled.code, testPath, {
	appendPaths: module.paths
});
<commit_msg>No need to tringify source maps before caching<commit_after>'use strict';

// Bind globals first, before anything has a chance to interfere.
var globals = require('./globals');

var sourceMapCache = Object.create(null);

var sourceMapSupport = require('source-map-support');
sourceMapSupport.install({
	retrieveSourceMap: function (source) {
		if (sourceMapCache[source]) {
			return {
				url: source,
				map: sourceMapCache[source]
			};
		}
		return sourceMapSupport.retrieveSourceMap(source);
	}
});

var createEspowerPlugin = require('babel-plugin-espower/create');
var requireFromString = require('require-from-string');
var loudRejection = require('loud-rejection/api')(process);
var resolveFrom = require('resolve-from');
var hasGenerator = require('has-generator');
var serializeError = require('serialize-error');
var send = require('./send');

var testPath = process.argv[2];

// include local babel and fallback to ava's babel
var babel;

try {
	var localBabel = resolveFrom('.', 'babel-core') || resolveFrom('.', 'babel');
	babel = require(localBabel);
} catch (err) {
	babel = require('babel-core');
}

// initialize power-assert
var powerAssert = createEspowerPlugin(babel, {
	patterns: require('./enhance-assert').PATTERNS
});

// if generators are not supported, use regenerator
var options = {
	blacklist: hasGenerator ? ['regenerator'] : [],
	optional: hasGenerator ? ['asyncToGenerator', 'runtime'] : ['runtime'],
	plugins: [powerAssert],
	sourceMaps: true,
	inputSourceMap: null
};

// check if test files required ava and show error, when they didn't
exports.avaRequired = false;

process.on('uncaughtException', function (exception) {
	send('uncaughtException', {exception: serializeError(exception)});
});

// try to load an input source map for the test file, in case the file was
// already compiled once by the user
var inputSourceMap = sourceMapSupport.retrieveSourceMap(testPath);
if (inputSourceMap) {
	// source-map-support returns the source map as a json-encoded string, but
	// babel requires an actual object
	options.inputSourceMap = JSON.parse(inputSourceMap.map);
}

// include test file
var transpiled = babel.transformFileSync(testPath, options);
sourceMapCache[testPath] = transpiled.map;
requireFromString(transpiled.code, testPath, {
	appendPaths: module.paths
});

{'fraction_non_alphanumeric': 0.13192784177352748, 'fraction_numerical': 0.0004346881112801565, 'mean_word_length': 5.347586206896552, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1618614', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1345, 'n_words': 383}