<commit_before>/*!
 * grunt-snakeskin
 * https://github.com/SnakeskinTpl/grunt-snakeskin
 *
 * Released under the MIT license
 * https://github.com/SnakeskinTpl/grunt-snakeskin/blob/master/LICENSE
 */

require('core-js/es6/object');

var
	$C = require('collection.js').$C;

var
	path = require('path'),
	snakeskin = require('snakeskin'),
	babel = require('babel-core'),
	beautify = require('js-beautify'),
	exists = require('exists-sync');

module.exports = function (grunt) {
	grunt.registerMultiTask('snakeskin', 'Compile Snakeskin templates', function () {
		var
			ssrc = path.join(process.cwd(), '.snakeskinrc'),
			opts = this.options(),
			prettyPrint;

		if (!this.data.options && exists(ssrc)) {
			opts = snakeskin.toObj(ssrc);
		}

		opts = opts || {};
		opts.throws = true;
		opts.cache = false;
		var n = opts.eol = opts.eol || '\n';

		if (opts.jsx) {
			opts.literalBounds = ['{', '}'];
			opts.renderMode = 'stringConcat';
			opts.exec = false;

		} else if (opts.exec && opts.prettyPrint) {
			opts.prettyPrint = false;
			prettyPrint = true;
		}

		function filter(src) {
			if (grunt.file.exists(src)) {
				return true;
			}

			grunt.log.warn('Source file "' + src + '" not found.');
			return false;
		}

		$C(this.files).forEach(function (file) {
			var
				isDir = !path.extname(file.dest);

			function map(src) {
				var
					params = Object.assign({}, opts),
					tpls = {},
					res = '';

				if (params.exec || opts.jsx) {
					params.context = tpls;
				}

				try {
					res = snakeskin.compile(grunt.file.read(src), params, {file: src});
					var compileJSX = function (tpls, prop) {
						prop = prop || 'exports';
						$C(tpls).forEach(function (el, key) {
							var val = prop + '["' + key.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"]';

							if (typeof el !== 'function') {
								res += 'if (' + val + ' instanceof Object === false) {' + n + '\t' + val + ' = {};' + n + '}' + n + n;
								return compileJSX(el, val);
							}

							var decl = /function .*?\)\s*\{/.exec(el.toString());
							res += babel.transform(val + ' = ' + decl[0] + ' ' + el(opts.data) + '};', {
								babelrc: false,
								plugins: [
									require('babel-plugin-syntax-jsx'),
									require('babel-plugin-transform-react-jsx'),
									require('babel-plugin-transform-react-display-name')
								]
							}).code;
						});
					};<commit_msg>:wrench:<commit_after>/*!
 * grunt-snakeskin
 * https://github.com/SnakeskinTpl/grunt-snakeskin
 *
 * Released under the MIT license
 * https://github.com/SnakeskinTpl/grunt-snakeskin/blob/master/LICENSE
 */

require('core-js/es6/object');

var
	$C = require('collection.js').$C;

var
	path = require('path'),
	snakeskin = require('snakeskin'),
	babel = require('babel-core'),
	beautify = require('js-beautify'),
	exists = require('exists-sync');

module.exports = function (grunt) {
	grunt.registerMultiTask('snakeskin', 'Compile Snakeskin templates', function () {
		var
			ssrc = path.join(process.cwd(), '.snakeskinrc'),
			opts = this.options(),
			prettyPrint;

		if (!this.data.options && exists(ssrc)) {
			opts = snakeskin.toObj(ssrc);
		}

		opts = opts || {};
		opts.throws = true;
		opts.cache = false;
		var n = opts.eol = opts.eol || '\n';

		if (opts.jsx) {
			opts.literalBounds = ['{', '}'];
			opts.renderMode = 'stringConcat';
			opts.exec = false;

		} else if (opts.exec && opts.prettyPrint) {
			opts.prettyPrint = false;
			prettyPrint = true;
		}

		function filter(src) {
			if (grunt.file.exists(src)) {
				return true;
			}

			grunt.log.warn('Source file "' + src + '" not found.');
			return false;
		}

		$C(this.files).forEach(function (file) {
			var
				isDir = !path.extname(file.dest);

			function map(src) {
				var
					params = Object.assign({}, opts),
					tpls = {},
					res = '';

				if (params.exec || opts.jsx) {
					params.context = tpls;
				}

				try {
					res = snakeskin.compile(grunt.file.read(src), params, {file: src});
					var compileJSX = function (tpls, prop) {
						prop = prop || 'exports';
						$C(tpls).forEach(function (el, key) {
							var val = prop + '["' + key.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"]';

							if (typeof el !== 'function') {
								res += 'if (' + val + ' instanceof Object === false) {' + n + '  ' + val + ' = {};' + n + '}' + n + n;
								return compileJSX(el, val);
							}

							var decl = /function .*?\)\s*\{/.exec(el.toString());
							res += babel.transform(val + ' = ' + decl[0] + ' ' + el(opts.data) + '};', {
								babelrc: false,
								plugins: [
									require('babel-plugin-syntax-jsx'),
									require('babel-plugin-transform-react-jsx'),
									require('babel-plugin-transform-react-display-name')
								]
							}).code;
						});
					};
{'fraction_non_alphanumeric': 0.19865461425268027, 'fraction_numerical': 0.0008408660920748371, 'mean_word_length': 2.5990922844175492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '3469357', 'n_tokens_mistral': 2119, 'n_tokens_neox': 1678, 'n_words': 313}