UglifyJS/lib/index.html

109 lines
2.9 KiB
HTML
Raw Normal View History

<!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>
2014-04-16 18:39:27 +00:00
<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"),
2014-04-16 18:39:27 +00:00
isjs = document.getElementById("is_js"),
source;
sourceArea.value = source = localStorage.source;
2014-04-16 18:39:27 +00:00
isjs.checked = localStorage.isjs == "t";
function compile(){
source = sourceArea.value;
localStorage.source = source;
2014-04-16 18:39:27 +00:00
localStorage.isjs = isjs.checked ? "t" : "f";
2014-04-17 16:21:45 +00:00
stream = new Cola.OutputStream({ beautify : true, is_js : isjs.checked });
2014-04-18 06:10:20 +00:00
compressor = new Cola.Compressor({ is_js : isjs.checked });
try {
// 1. compile
2014-04-18 06:10:20 +00:00
ast = Cola.parse(source, { is_js : isjs.checked });
2014-04-17 16:21:45 +00:00
if(!isjs.checked) ast = ast.toJavaScript();
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();
2014-04-17 10:10:18 +00:00
ast.mangle_names({ is_js : isjs.checked, sort : true, toplevel : true });
2014-04-18 06:10:20 +00:00
stream = new Cola.OutputStream({ is_js : isjs.checked });
ast.print(stream);
resultArea.value = stream.toString();
} catch(e){
translationArea.value = '';
resultArea.value = '';
2014-04-16 16:43:40 +00:00
throw e;
}
}
function exec(){
eval(resultArea.value)
}
function Translate(){
2014-04-17 16:21:45 +00:00
stream = new Cola.OutputStream({ beautify : true });
2014-04-16 18:39:27 +00:00
translate(Cola.parse(source, null, isjs.checked)).print(stream);
return stream.toString();
}
compile();
</script>
</html>