<commit_before>// This component renders the current code.

// Include React.
var React = require('react');

// We'll use esprima to validate javascript code.
var esprima = require('esprima');

// Create the component.
var Output = React.createClass({

	renderHTML: function(code) {
		var iframe = window.frames[0];
		var doc = iframe.document;

		doc.body.innerHTML = code;
	},

	renderCSS: function(code) {
		var iframe = window.frames[0];
		var doc = iframe.document;

		doc.head.querySelector('style.custom').textContent = code;
	},

	renderJavaScript: function(code) {
		var iframe = window.frames[0];

		var AST;
		var isValid = false;
		try {
			// use esprima to validate the code
			AST = esprima.parse(code, {tolerant: true, loc: true});
			isValid = !AST.errors.length;
		} catch(e) {}

		// and only pass in the javascript string if code is valid.
		if (isValid) {
			iframe.livecoding.callCode(code);
		}
	},

	// Render the component. We use an iframe to prevent
	// the user's JS/CSS from interfering with the application.
	render: function() {
		return (
			<div className='output'>
				<iframe src='iframe.html' />
			</div>
		);
	},

	// Tell React not to manage this component's DOM.
	shouldComponentUpdate: function(nextProps) {

		// Get the iframe.
		var iframe = window.frames[0];
		var doc = iframe.document;

		// If `renderAll` is true, then render all codes.<commit_msg>don't run esprima on Output, it's way too slow<commit_after>// This component renders the current code.

// Include React.
var React = require('react');

// Create the component.
var Output = React.createClass({

	renderHTML: function(code) {
		var iframe = window.frames[0];
		var doc = iframe.document;

		doc.body.innerHTML = code;
	},

	renderCSS: function(code) {
		var iframe = window.frames[0];
		var doc = iframe.document;

		doc.head.querySelector('style.custom').textContent = code;
	},

	renderJavaScript: function(code) {
		var iframe = window.frames[0];

		iframe.livecoding.callCode(code);
	},

	// Render the component. We use an iframe to prevent
	// the user's JS/CSS from interfering with the application.
	render: function() {
		return (
			<div className='output'>
				<iframe src='iframe.html' />
			</div>
		);
	},

	// Tell React not to manage this component's DOM.
	shouldComponentUpdate: function(nextProps) {

		// Get the iframe.
		var iframe = window.frames[0];
		var doc = iframe.document;

		// If `renderAll` is true, then render all codes.
{'fraction_non_alphanumeric': 0.130064829821718, 'fraction_numerical': 0.0032414910858995136, 'mean_word_length': 3.377659574468085, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6787918', 'n_tokens_mistral': 901, 'n_tokens_neox': 781, 'n_words': 243}