JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://esprima.org/esprima.js"></script>
<script src="http://esprima.org/test/3rdparty/escodegen.browser.js"></script>
JavaScript
(function (window) {
'use strict';
Array.prototype.contains = function (item, from) {
return this.indexOf(item, from) != -1;
};
if (!esprima) {
throw 'Esprima not loaded';
}
if (!escodegen) {
throw 'Escodegen not loaded';
}
var JSTypes = ['String', 'Boolean', 'Number', 'Null', 'Array', 'Null', 'Undefined'];
var anonymousFunctionRegx = /function(?:[\s\S]*?)\(/m;
var allowedOperators = '+ - * / << >> ~'.split(' ');
var allowedBinary = '+ - * / << >>'.split(' ');
var allowedUnary = '~'.split(' ');
var Callee = esprima.parse('that.__operator__(op,lval,rval);').body[0].expression.callee;
function traverse(node, func) {
func(node);
for (var key in node) {
if (node.hasOwnProperty(key)) {
var child = node[key];
if (typeof child === 'object' && child !== null) {
if (typeOf(child) == 'Array') {
for (var i = 0; i < child.length; ++i) {
traverse(child[i], func);
}
} else {
traverse(child, func);
}
}
}
}
}
function typeOf(obj) {
return Object.prototype.toString.call(obj).slice(8, -1);
}
function toCallExp(node) {
var operatorNode = {
'type': 'Literal',
'value': node.operator,
'raw': JSON.stringify(node.operator)
};
if (node.type == 'BinaryExpression' || node.type == 'LogicalExpression') {
node['arguments'] = [operatorNode, node.left, node.right];
} else if (node.type == 'UnaryExpression' || node.type == 'UpdateExpression') {
var prefixNode = {
'type': 'Literal',
'value': node.prefix,
'raw': JSON.stringify(node.prefix)
};
node['arguments'] =...