UglifyJS/lib/index.html

327 lines
9.4 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>
<script src="./typecheck.js"></script>
<style>
body {
padding: 0;
margin: 0;
line-height: 100%;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
2014-05-19 09:58:17 +00:00
.triple textarea {
width: 33.333%;
}
.double textarea {
width: 50%;
}
textarea {
2014-04-28 08:20:12 +00:00
-moz-box-sizing: border-box;
2014-05-19 09:58:17 +00:00
box-sizing: border-box;
height: 100%;
font-size: 15px;
float: left;
font-family: "Andale Mono";
2014-04-28 08:20:12 +00:00
padding: 0 5px 26px 5px;
background-color: #272A32;
color: #D6D7D9;
}
#controls {
position: fixed;
bottom: 0;
left: 0;
2014-04-20 15:57:10 +00:00
height: 25px;
width: 100%;
}
2014-04-20 15:57:10 +00:00
#controls .m {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 2px 0 0 2px;
2014-04-20 15:57:10 +00:00
}
#controls .bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: white;
opacity: 0.8;
2014-04-20 15:57:10 +00:00
}
2014-04-28 08:20:12 +00:00
#lenstat {
float: right;
margin: 2px 10px;
2014-04-28 08:20:12 +00:00
}
2014-09-04 05:11:50 +00:00
#version {
float: right;
margin: 2px 10px;
}
</style>
</head>
2014-05-19 09:58:17 +00:00
<body class="triple">
2014-04-28 08:20:12 +00:00
<textarea id="source" onkeyup="compile()">// `main` functions may binding to a onload event
// Functions can defined without `function` keyword, with and without `type`
main(){
// Unary operators
2014-09-04 05:13:32 +00:00
// `isset` operator.
2014-04-28 08:20:12 +00:00
bool _seted = true, _empty;
2014-09-04 05:13:32 +00:00
console.log("`_seted` is", _seted? ? "seted" : "empty");
2014-04-28 08:20:12 +00:00
// `clone` operator
Array _first = [584], _second = clone _first;
_first.push(404);
2014-09-04 05:13:32 +00:00
console.log("`_first`:", _first, "`_second`:", _second);
2014-04-28 08:20:12 +00:00
// Binary operators
// `pow` operator
console.log("5 ** 3 =", 5 ** 3);
// `modulo` operator
console.log("10 %% 4 = ", 10 %% 4);
// `isset` conditional assignment
2014-04-28 08:20:12 +00:00
int a, b = 4;
console.log("`a` is", a, ", now `a` is", a ?= b);
console.log("`a` is", a, ", now `a` still", a ?= 584);
// `isset` binary conditional
int x, y = 5;
console.log("`x` is", x, ", `y` is", y, ", x ? y = ", x ? y), x = 1;
console.log("`x` is", x, ", `y` is", y, ", x ? y = ", x ? y);
// `is` operator
console.log("'hello'", "hello" is String ? "is" : "isnt", "`String`");
// `isnt` operator
console.log("'goodby'", "goodby" isnt Number ? "isnt" : "is", "`Number`");
// Boolean alternatives
console.log("`yes` and `no`", yes is Boolean && no is Boolean ? "is" : "isnt", "`Boolean`");
console.log("`on` and `off`", on is Boolean && off is Boolean ? "is" : "isnt", "`Boolean`");
// Strings
// New quotes symbol, multi-lining and templating
2014-04-18 07:14:54 +00:00
console.log(`
Hello!
My name is ColaScript, and i know who you are }:->
2014-04-28 08:20:12 +00:00
User agent: @{navigator.userAgent}
Vendor: {{navigator.vendor}}
2014-04-18 07:14:54 +00:00
`);
2014-04-28 08:20:12 +00:00
// Raw strings
console.log(r"\n \r \t some@email.ru");
2014-04-28 08:20:12 +00:00
// Multiline RegExp's
2014-04-18 18:33:08 +00:00
RegExp isEmail = /
2014-04-18 07:14:54 +00:00
([\w-\.]+)
@
((?:[\w]+\.)+)
([a-zA-Z]{2,4})
2014-04-28 08:20:12 +00:00
/;
String email = r'some@email.ru';
console.log("@email {{ isEmail.test(email) ? "is" : "isnt" }} valid email adress");
// Arrays
// Empty getter and setter ( pushing )
2014-04-28 08:20:12 +00:00
Array arr = [2, 4, 8, 16, 32];
console.log("Last element of `arr` is", arr[]), arr[] = 64;
console.log("Now last element of `arr` is", arr[]);
// Splice assignment
2014-04-28 08:20:12 +00:00
arr[2..4] = [3, 2, 1];
console.log("`arr` is", arr);
// Range
console.log("`[0..10]` is", [0..10]);
// Calling function
Object pro;
console.log(pro = Profile(
"Dan", "Green", "Russia",
2014-04-28 08:20:12 +00:00
"HTML5", "JavaScript", "Dart", "PHP", "CSS3", "LESS", "Qt",
age : 19,
petName : "Felix"
));
// Cascade operator
pro
..firstName += "iil"
..secondName = "Onoshko"
..skills:
..[1] = "JS";
;
console.log(pro);
2014-04-18 07:14:54 +00:00
}
2014-04-28 08:20:12 +00:00
// Functions
// Named, positional and splated arguments, with default values.
// Arrow functions.
Object Profile(String firstName, String secondName, String country = "Russia", Array skills..., age:, petName: "Tux"){
skills.forEach((val) => val == "JavaScript" && console.log("JavaScript - It Awesome!"));
return {
firstName : firstName,
secondName : secondName,
age : age,
country : country,
skills : skills,
petName : petName
};
}
main();</textarea>
<textarea id="translation"></textarea>
<textarea id="result"></textarea>
2014-04-20 15:57:10 +00:00
<div id="controls">
<div class="bg">&nbsp;</div>
<div class="m">
<button id="exec" onclick="exec()">Execute</button>
<button onclick="benchmarkTranslate()">Benchmark Translation</button>
<button onclick="benchmarkResult()">Benchmark Result</button>
2014-04-20 15:57:10 +00:00
<input type="checkbox" id="is_js" onclick="compile()">
<label for="is_js">js parser</label>
2014-04-28 08:20:12 +00:00
<input type="checkbox" id="main_binding" onclick="compile()">
<label for="main_binding">`main` binding</label>
2014-05-19 09:58:17 +00:00
<input type="checkbox" id="compressed" onclick="changeClass()">
<label for="compressed">compressed</label>
2014-09-04 05:11:50 +00:00
<span id="version">v0.6.0</span>
2014-09-04 05:13:32 +00:00
<span id="lenstat"></span>
2014-04-20 15:57:10 +00:00
</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"),
2014-04-28 08:20:12 +00:00
mainbinding = document.getElementById("main_binding"),
2014-05-19 09:58:17 +00:00
compressed = document.getElementById("compressed"),
source;
//localStorage.clear();
2014-04-18 07:14:54 +00:00
if(!localStorage.source) localStorage.source = source = sourceArea.value;
else sourceArea.value = source = localStorage.source;
2014-04-16 18:39:27 +00:00
isjs.checked = localStorage.isjs == "t";
2014-04-28 08:20:12 +00:00
mainbinding.checked = localStorage.mainbinding == "t";
2014-05-19 09:58:17 +00:00
compressed.checked = localStorage.compressed == "t";
function changeClass(){
document.body.className = compressed.checked ? "triple" : "double";
localStorage.compressed = compressed.checked ? "t" : "f";
}
function compile(){
source = sourceArea.value;
localStorage.source = source;
2014-04-16 18:39:27 +00:00
localStorage.isjs = isjs.checked ? "t" : "f";
2014-04-28 08:20:12 +00:00
localStorage.mainbinding = mainbinding.checked ? "t" : "f";
2014-05-31 20:14:13 +00:00
stream = new Cola.OutputStream({ beautify : true, comments : true });
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-28 08:20:12 +00:00
if(!isjs.checked) ast = ast.toJavaScript({ main_binding : mainbinding.checked });
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-22 13:33:43 +00:00
ast.mangle_names({ sort : true, toplevel : true });
2014-04-22 13:33:43 +00:00
stream = new Cola.OutputStream();
ast.print(stream);
resultArea.value = stream.toString();
} catch(e){
translationArea.value = '';
resultArea.value = '';
2014-04-20 18:56:47 +00:00
throw e;
}
2014-04-20 15:57:10 +00:00
document.querySelector('#lenstat').innerHTML = sourceArea.value.length+" : "+translationArea.value.length+" : "+resultArea.value.length;
}
function benchmarkResult(){
console.time("Result");
eval(resultArea.value);
console.timeEnd("Result");
}
function benchmarkTranslate(){
console.time("Translation");
eval(translationArea.value);
console.timeEnd("Translation");
2014-04-22 13:33:43 +00:00
}
function exec(){
2014-05-22 15:44:11 +00:00
eval.call(window, translationArea.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();
}
function Test(){
2014-06-11 19:14:36 +00:00
var ast;
try {
// 1. compile
ast = Cola.parse(source, { is_js : isjs.checked });
if(!isjs.checked) ast = ast.toJavaScript({ main_binding : mainbinding.checked });
// 3. mangle
ast.figure_out_scope();
2014-06-11 19:14:36 +00:00
//ast.compute_char_frequency();
//ast.mangle_names({ sort : true, toplevel : true });
return ast;
} catch(e){
throw e;
}
}
2014-05-19 09:58:17 +00:00
changeClass();
compile();
</script>
</html>