UglifyJS/lib/index.html
Onoshko Dan 10db7a5ef4 Refactoring
step 1
2014-04-16 23:43:40 +07:00

106 lines
2.5 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></div>
</body>
<script>
var sourceArea = document.getElementById("source"),
translationArea = document.getElementById("translation"),
resultArea = document.getElementById("result"),
source;
sourceArea.value = source = localStorage.source;
function compile(){
source = sourceArea.value;
localStorage.source = source;
stream = OutputStream({ beautify : true });
compressor = Compressor();
try {
// 1. compile
ast = Cola.parse(source);
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)).print(stream);
return stream.toString();
}
compile();
</script>
</html>