UglifyJS/lib/index.html
Onoshko Dan db5ea25e30 Refactoring
Step 2
2014-04-17 01:39:27 +07:00

109 lines
2.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>ColaScript Playground</title>
<script src="./utils.js"></script>
<script src="./ast.js"></script>
<script src="./parse.js"></script>
<script src="./transform.js"></script>
<script src="./scope.js"></script>
<script src="./output.js"></script>
<script src="./compress.js"></script>
<script src="./sourcemap.js"></script>
<script src="./mozilla-ast.js"></script>
<script src="./translate.js"></script>
<script src="./std.js"></script>
<style>
body {
padding: 0;
margin: 0;
line-height: 100%;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
textarea {
box-sizing: border-box;
width: 33.333%;
height: 100%;
font-size: 12px;
float: left;
font-family: "Andale Mono";
}
#controls {
position: fixed;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<textarea id="source" onkeyup="compile()"></textarea>
<textarea id="translation"></textarea>
<textarea id="result"></textarea>
<div id="controls"><button id="exec" onclick="exec()">Execute</button><input type="checkbox" id="is_js" onclick="compile()"><label for="is_js">js parser</label></div>
</body>
<script>
var sourceArea = document.getElementById("source"),
translationArea = document.getElementById("translation"),
resultArea = document.getElementById("result"),
isjs = document.getElementById("is_js"),
source;
sourceArea.value = source = localStorage.source;
isjs.checked = localStorage.isjs == "t";
function compile(){
source = sourceArea.value;
localStorage.source = source;
localStorage.isjs = isjs.checked ? "t" : "f";
stream = OutputStream({ beautify : true });
compressor = Compressor();
try {
// 1. compile
ast = Cola.parse(source, null, isjs.checked);
if(!isjs.checked) ast = translate(ast);
ast.print(stream);
translationArea.value = stream.toString();
// 2. compress
ast.figure_out_scope();
ast = ast.transform(compressor);
// 3. mangle
ast.figure_out_scope();
ast.compute_char_frequency();
ast.mangle_names({ sort : true, toplevel : true });
stream = OutputStream();
ast.print(stream);
resultArea.value = stream.toString();
} catch(e){
translationArea.value = '';
resultArea.value = '';
throw e;
}
}
function exec(){
eval(resultArea.value)
}
function Translate(){
stream = OutputStream({ beautify : true });
translate(Cola.parse(source, null, isjs.checked)).print(stream);
return stream.toString();
}
compile();
</script>
</html>