UglifyJS/lib/index.html
2014-04-20 22:38:58 +07:00

158 lines
4.1 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()">main(){
console.log(`
Hello!
My name is ColaScript, and i know who you are }:->
@{navigator.userAgent}
`);
console.log("pow:", 5 ** 2, "; modulo:", 5 %% 3, ";");
Number a = 3.14, b = 584, c;
a ?= b; console.log(a);
a = undefined;
a ?= b; console.log(a);
console.log(a = c ? b);
c = 404;
console.log(a = c ? b);
b = undefined;
Array x, y;
x = [123];
y = clone x;
y.push(321);
console.log('original:',x,'cloned:',y);
y.forEach((val){
console.log(val);
});
console.log("a is {{isset a ? 'set' : 'undefiend'}}, b is {{b?? ? 'set' : 'undefined'}}");
console.log(`is:`, location.href is String, `; isnt:`, 123 isnt Number, ";");
if(yes === true && on === true && no === false && off === false) console.log('Boolean alternatives');
console.log('Raw string:', r`@test \n \t \r`);
RegExp isEmail = /
([\w-\.]+)
@
((?:[\w]+\.)+)
([a-zA-Z]{2,4})
/, email = r'danon0404@gmail.com';
console.log("@email is email:", isEmail.test(email));
}
main();</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;
if(!localStorage.source) localStorage.source = source = sourceArea.value;
else 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 = new Cola.OutputStream({ beautify : true, is_js : isjs.checked });
compressor = new Cola.Compressor({ is_js : isjs.checked });
try {
// 1. compile
ast = Cola.parse(source, { is_js : isjs.checked });
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();
ast.mangle_names({ is_js : isjs.checked, sort : true, toplevel : true });
stream = new Cola.OutputStream({ is_js : isjs.checked });
ast.print(stream);
resultArea.value = stream.toString();
} catch(e){
translationArea.value = '';
resultArea.value = '';
}
}
function exec(){
eval(resultArea.value)
}
function Translate(){
stream = new Cola.OutputStream({ beautify : true });
translate(Cola.parse(source, null, isjs.checked)).print(stream);
return stream.toString();
}
compile();
</script>
</html>