mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +00:00
Added uglify.js
This commit is contained in:
parent
f096b19e4a
commit
0d1a2ef21c
54
js/Recipe.js
54
js/Recipe.js
@ -71,6 +71,13 @@ var Recipe = function(options,callback) {
|
|||||||
if(err) {
|
if(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
|
if(task.recipeLine.fields) {
|
||||||
|
for(var t=0; t<data.length; t++) {
|
||||||
|
for(var f in task.recipeLine.fields) {
|
||||||
|
data[t][f] = task.recipeLine.fields[f];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
task.recipeLine.tiddlers = data;
|
task.recipeLine.tiddlers = data;
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
@ -137,21 +144,42 @@ Recipe.prototype.sortTiddlersForMarker = function(marker) {
|
|||||||
|
|
||||||
// Process the contents of a recipe file
|
// Process the contents of a recipe file
|
||||||
Recipe.prototype.processRecipeFile = function(recipe,text,contextPath) {
|
Recipe.prototype.processRecipeFile = function(recipe,text,contextPath) {
|
||||||
var me = this;
|
var matchLine = function(linetext) {
|
||||||
text.split("\n").forEach(function(line) {
|
var lineRegExp = /^(\s*)([^\s\:]+)\s*:\s*(.+)*$/,
|
||||||
var p = line.indexOf(":"),
|
match = lineRegExp.exec(linetext);
|
||||||
insertionPoint;
|
return match ? {
|
||||||
if(p !== -1) {
|
indent: match[1],
|
||||||
var marker = line.substr(0, p).trim(),
|
marker: match[2],
|
||||||
value = line.substr(p+1).trim();
|
value: match[3]
|
||||||
if(marker === "recipe") {
|
} : null;
|
||||||
insertionPoint = recipe.push([]) - 1;
|
},
|
||||||
me.recipeQueue.push({filepath: value, contextPath: contextPath, recipe: recipe[insertionPoint]});
|
lines = text.split("\n"),
|
||||||
|
line = 0;
|
||||||
|
while(line < lines.length) {
|
||||||
|
var linetext = lines[line++],
|
||||||
|
match = matchLine(linetext);
|
||||||
|
if(match) {
|
||||||
|
if(match.indent.length > 0) {
|
||||||
|
throw "Unexpected indentation in recipe file";
|
||||||
|
}
|
||||||
|
if(match.marker === "recipe") {
|
||||||
|
var insertionPoint = recipe.push([]) - 1;
|
||||||
|
this.recipeQueue.push({filepath: match.value, contextPath: contextPath, recipe: recipe[insertionPoint]});
|
||||||
} else {
|
} else {
|
||||||
recipe.push({marker: marker, filepath: value, contextPath: contextPath});
|
var fieldLines = [],
|
||||||
|
fieldMatch = matchLine(lines[line]);
|
||||||
|
while(fieldMatch && fieldMatch.indent.length > 0) {
|
||||||
|
fieldLines.push(lines[line++]);
|
||||||
|
fieldMatch = matchLine(lines[line]);
|
||||||
|
}
|
||||||
|
var fields = {};
|
||||||
|
if(fieldLines.length > 0) {
|
||||||
|
fields = this.tiddlerConverters.deserialize("application/x-tiddler",fieldLines.join("\n"),{})[0];
|
||||||
|
}
|
||||||
|
recipe.push({marker: match.marker, filepath: match.value, contextPath: contextPath, fields: fields});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read a tiddler file and callback with an array of hashmaps of tiddler fields. For single
|
// Read a tiddler file and callback with an array of hashmaps of tiddler fields. For single
|
||||||
@ -279,7 +307,7 @@ Recipe.tiddlerOutputter = {
|
|||||||
var title = tiddlers[t],
|
var title = tiddlers[t],
|
||||||
tid = this.store.getTiddler(title);
|
tid = this.store.getTiddler(title);
|
||||||
out.push("<" + "script type=\"application/javascript\">");
|
out.push("<" + "script type=\"application/javascript\">");
|
||||||
out.push("define(\"" + title + "\",function(require,exports) {");
|
out.push("define(\"" + title + "\",function(require,exports,module) {");
|
||||||
out.push(tid.fields.text);
|
out.push(tid.fields.text);
|
||||||
out.push("});");
|
out.push("});");
|
||||||
out.push("</" + "script>");
|
out.push("</" + "script>");
|
||||||
|
1
node_modules/.bin/uglifyjs
generated
vendored
Symbolic link
1
node_modules/.bin/uglifyjs
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../uglify-js/bin/uglifyjs
|
4
node_modules/uglify-js/.npmignore
generated
vendored
Normal file
4
node_modules/uglify-js/.npmignore
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.DS_Store
|
||||||
|
.tmp*~
|
||||||
|
*.local.*
|
||||||
|
.pinf-*
|
981
node_modules/uglify-js/README.html
generated
vendored
Normal file
981
node_modules/uglify-js/README.html
generated
vendored
Normal file
@ -0,0 +1,981 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
lang="en" xml:lang="en">
|
||||||
|
<head>
|
||||||
|
<title>UglifyJS – a JavaScript parser/compressor/beautifier</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
||||||
|
<meta name="generator" content="Org-mode"/>
|
||||||
|
<meta name="generated" content="2011-12-09 14:59:08 EET"/>
|
||||||
|
<meta name="author" content="Mihai Bazon"/>
|
||||||
|
<meta name="description" content="a JavaScript parser/compressor/beautifier in JavaScript"/>
|
||||||
|
<meta name="keywords" content="javascript, js, parser, compiler, compressor, mangle, minify, minifier"/>
|
||||||
|
<style type="text/css">
|
||||||
|
<!--/*--><![CDATA[/*><!--*/
|
||||||
|
html { font-family: Times, serif; font-size: 12pt; }
|
||||||
|
.title { text-align: center; }
|
||||||
|
.todo { color: red; }
|
||||||
|
.done { color: green; }
|
||||||
|
.tag { background-color: #add8e6; font-weight:normal }
|
||||||
|
.target { }
|
||||||
|
.timestamp { color: #bebebe; }
|
||||||
|
.timestamp-kwd { color: #5f9ea0; }
|
||||||
|
.right {margin-left:auto; margin-right:0px; text-align:right;}
|
||||||
|
.left {margin-left:0px; margin-right:auto; text-align:left;}
|
||||||
|
.center {margin-left:auto; margin-right:auto; text-align:center;}
|
||||||
|
p.verse { margin-left: 3% }
|
||||||
|
pre {
|
||||||
|
border: 1pt solid #AEBDCC;
|
||||||
|
background-color: #F3F5F7;
|
||||||
|
padding: 5pt;
|
||||||
|
font-family: courier, monospace;
|
||||||
|
font-size: 90%;
|
||||||
|
overflow:auto;
|
||||||
|
}
|
||||||
|
table { border-collapse: collapse; }
|
||||||
|
td, th { vertical-align: top; }
|
||||||
|
th.right { text-align:center; }
|
||||||
|
th.left { text-align:center; }
|
||||||
|
th.center { text-align:center; }
|
||||||
|
td.right { text-align:right; }
|
||||||
|
td.left { text-align:left; }
|
||||||
|
td.center { text-align:center; }
|
||||||
|
dt { font-weight: bold; }
|
||||||
|
div.figure { padding: 0.5em; }
|
||||||
|
div.figure p { text-align: center; }
|
||||||
|
div.inlinetask {
|
||||||
|
padding:10px;
|
||||||
|
border:2px solid gray;
|
||||||
|
margin:10px;
|
||||||
|
background: #ffffcc;
|
||||||
|
}
|
||||||
|
textarea { overflow-x: auto; }
|
||||||
|
.linenr { font-size:smaller }
|
||||||
|
.code-highlighted {background-color:#ffff00;}
|
||||||
|
.org-info-js_info-navigation { border-style:none; }
|
||||||
|
#org-info-js_console-label { font-size:10px; font-weight:bold;
|
||||||
|
white-space:nowrap; }
|
||||||
|
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
|
||||||
|
font-weight:bold; }
|
||||||
|
/*]]>*/-->
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" type="text/css" href="docstyle.css" />
|
||||||
|
<script type="text/javascript">
|
||||||
|
<!--/*--><![CDATA[/*><!--*/
|
||||||
|
function CodeHighlightOn(elem, id)
|
||||||
|
{
|
||||||
|
var target = document.getElementById(id);
|
||||||
|
if(null != target) {
|
||||||
|
elem.cacheClassElem = elem.className;
|
||||||
|
elem.cacheClassTarget = target.className;
|
||||||
|
target.className = "code-highlighted";
|
||||||
|
elem.className = "code-highlighted";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function CodeHighlightOff(elem, id)
|
||||||
|
{
|
||||||
|
var target = document.getElementById(id);
|
||||||
|
if(elem.cacheClassElem)
|
||||||
|
elem.className = elem.cacheClassElem;
|
||||||
|
if(elem.cacheClassTarget)
|
||||||
|
target.className = elem.cacheClassTarget;
|
||||||
|
}
|
||||||
|
/*]]>*///-->
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="preamble">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
<h1 class="title">UglifyJS – a JavaScript parser/compressor/beautifier</h1>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="table-of-contents">
|
||||||
|
<h2>Table of Contents</h2>
|
||||||
|
<div id="text-table-of-contents">
|
||||||
|
<ul>
|
||||||
|
<li><a href="#sec-1">1 UglifyJS — a JavaScript parser/compressor/beautifier </a>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#sec-1-1">1.1 Unsafe transformations </a>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#sec-1-1-1">1.1.1 Calls involving the global Array constructor </a></li>
|
||||||
|
<li><a href="#sec-1-1-2">1.1.2 <code>obj.toString()</code> ==> <code>obj+“”</code> </a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a href="#sec-1-2">1.2 Install (NPM) </a></li>
|
||||||
|
<li><a href="#sec-1-3">1.3 Install latest code from GitHub </a></li>
|
||||||
|
<li><a href="#sec-1-4">1.4 Usage </a>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#sec-1-4-1">1.4.1 API </a></li>
|
||||||
|
<li><a href="#sec-1-4-2">1.4.2 Beautifier shortcoming – no more comments </a></li>
|
||||||
|
<li><a href="#sec-1-4-3">1.4.3 Use as a code pre-processor </a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a href="#sec-1-5">1.5 Compression – how good is it? </a></li>
|
||||||
|
<li><a href="#sec-1-6">1.6 Bugs? </a></li>
|
||||||
|
<li><a href="#sec-1-7">1.7 Links </a></li>
|
||||||
|
<li><a href="#sec-1-8">1.8 License </a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1" class="outline-2">
|
||||||
|
<h2 id="sec-1"><span class="section-number-2">1</span> UglifyJS — a JavaScript parser/compressor/beautifier </h2>
|
||||||
|
<div class="outline-text-2" id="text-1">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This package implements a general-purpose JavaScript
|
||||||
|
parser/compressor/beautifier toolkit. It is developed on <a href="http://nodejs.org/">NodeJS</a>, but it
|
||||||
|
should work on any JavaScript platform supporting the CommonJS module system
|
||||||
|
(and if your platform of choice doesn't support CommonJS, you can easily
|
||||||
|
implement it, or discard the <code>exports.*</code> lines from UglifyJS sources).
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The tokenizer/parser generates an abstract syntax tree from JS code. You
|
||||||
|
can then traverse the AST to learn more about the code, or do various
|
||||||
|
manipulations on it. This part is implemented in <a href="../lib/parse-js.js">parse-js.js</a> and it's a
|
||||||
|
port to JavaScript of the excellent <a href="http://marijn.haverbeke.nl/parse-js/">parse-js</a> Common Lisp library from <a href="http://marijn.haverbeke.nl/">Marijn Haverbeke</a>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
( See <a href="http://github.com/mishoo/cl-uglify-js">cl-uglify-js</a> if you're looking for the Common Lisp version of
|
||||||
|
UglifyJS. )
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The second part of this package, implemented in <a href="../lib/process.js">process.js</a>, inspects and
|
||||||
|
manipulates the AST generated by the parser to provide the following:
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>ability to re-generate JavaScript code from the AST. Optionally
|
||||||
|
indented—you can use this if you want to “beautify” a program that has
|
||||||
|
been compressed, so that you can inspect the source. But you can also run
|
||||||
|
our code generator to print out an AST without any whitespace, so you
|
||||||
|
achieve compression as well.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>shorten variable names (usually to single characters). Our mangler will
|
||||||
|
analyze the code and generate proper variable names, depending on scope
|
||||||
|
and usage, and is smart enough to deal with globals defined elsewhere, or
|
||||||
|
with <code>eval()</code> calls or <code>with{}</code> statements. In short, if <code>eval()</code> or
|
||||||
|
<code>with{}</code> are used in some scope, then all variables in that scope and any
|
||||||
|
variables in the parent scopes will remain unmangled, and any references
|
||||||
|
to such variables remain unmangled as well.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>various small optimizations that may lead to faster code but certainly
|
||||||
|
lead to smaller code. Where possible, we do the following:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>foo["bar"] ==> foo.bar
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>remove block brackets <code>{}</code>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>join consecutive var declarations:
|
||||||
|
var a = 10; var b = 20; ==> var a=10,b=20;
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>resolve simple constant expressions: 1 +2 * 3 ==> 7. We only do the
|
||||||
|
replacement if the result occupies less bytes; for example 1/3 would
|
||||||
|
translate to 0.333333333333, so in this case we don't replace it.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>consecutive statements in blocks are merged into a sequence; in many
|
||||||
|
cases, this leaves blocks with a single statement, so then we can remove
|
||||||
|
the block brackets.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>various optimizations for IF statements:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>if (foo) bar(); else baz(); ==> foo?bar():baz();
|
||||||
|
</li>
|
||||||
|
<li>if (!foo) bar(); else baz(); ==> foo?baz():bar();
|
||||||
|
</li>
|
||||||
|
<li>if (foo) bar(); ==> foo&&bar();
|
||||||
|
</li>
|
||||||
|
<li>if (!foo) bar(); ==> foo||bar();
|
||||||
|
</li>
|
||||||
|
<li>if (foo) return bar(); else return baz(); ==> return foo?bar():baz();
|
||||||
|
</li>
|
||||||
|
<li>if (foo) return bar(); else something(); ==> {if(foo)return bar();something()}
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>remove some unreachable code and warn about it (code that follows a
|
||||||
|
<code>return</code>, <code>throw</code>, <code>break</code> or <code>continue</code> statement, except
|
||||||
|
function/variable declarations).
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li>act a limited version of a pre-processor (c.f. the pre-processor of
|
||||||
|
C/C++) to allow you to safely replace selected global symbols with
|
||||||
|
specified values. When combined with the optimisations above this can
|
||||||
|
make UglifyJS operate slightly more like a compilation process, in
|
||||||
|
that when certain symbols are replaced by constant values, entire code
|
||||||
|
blocks may be optimised away as unreachable.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-1" class="outline-3">
|
||||||
|
<h3 id="sec-1-1"><span class="section-number-3">1.1</span> <span class="target">Unsafe transformations</span> </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-1">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The following transformations can in theory break code, although they're
|
||||||
|
probably safe in most practical cases. To enable them you need to pass the
|
||||||
|
<code>--unsafe</code> flag.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-1-1" class="outline-4">
|
||||||
|
<h4 id="sec-1-1-1"><span class="section-number-4">1.1.1</span> Calls involving the global Array constructor </h4>
|
||||||
|
<div class="outline-text-4" id="text-1-1-1">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The following transformations occur:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="src src-js"><span class="org-keyword">new</span> <span class="org-type">Array</span>(1, 2, 3, 4) => [1,2,3,4]
|
||||||
|
Array(a, b, c) => [a,b,c]
|
||||||
|
<span class="org-keyword">new</span> <span class="org-type">Array</span>(5) => Array(5)
|
||||||
|
<span class="org-keyword">new</span> <span class="org-type">Array</span>(a) => Array(a)
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
These are all safe if the Array name isn't redefined. JavaScript does allow
|
||||||
|
one to globally redefine Array (and pretty much everything, in fact) but I
|
||||||
|
personally don't see why would anyone do that.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
UglifyJS does handle the case where Array is redefined locally, or even
|
||||||
|
globally but with a <code>function</code> or <code>var</code> declaration. Therefore, in the
|
||||||
|
following cases UglifyJS <b>doesn't touch</b> calls or instantiations of Array:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="src src-js"><span class="org-comment-delimiter">// </span><span class="org-comment">case 1. globally declared variable</span>
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">Array</span>;
|
||||||
|
<span class="org-keyword">new</span> <span class="org-type">Array</span>(1, 2, 3);
|
||||||
|
Array(a, b);
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">// </span><span class="org-comment">or (can be declared later)</span>
|
||||||
|
<span class="org-keyword">new</span> <span class="org-type">Array</span>(1, 2, 3);
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">Array</span>;
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">// </span><span class="org-comment">or (can be a function)</span>
|
||||||
|
<span class="org-keyword">new</span> <span class="org-type">Array</span>(1, 2, 3);
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">Array</span>() { ... }
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">// </span><span class="org-comment">case 2. declared in a function</span>
|
||||||
|
(<span class="org-keyword">function</span>(){
|
||||||
|
a = <span class="org-keyword">new</span> <span class="org-type">Array</span>(1, 2, 3);
|
||||||
|
b = Array(5, 6);
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">Array</span>;
|
||||||
|
})();
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">// </span><span class="org-comment">or</span>
|
||||||
|
(<span class="org-keyword">function</span>(<span class="org-variable-name">Array</span>){
|
||||||
|
<span class="org-keyword">return</span> Array(5, 6, 7);
|
||||||
|
})();
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">// </span><span class="org-comment">or</span>
|
||||||
|
(<span class="org-keyword">function</span>(){
|
||||||
|
<span class="org-keyword">return</span> <span class="org-keyword">new</span> <span class="org-type">Array</span>(1, 2, 3, 4);
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">Array</span>() { ... }
|
||||||
|
})();
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">// </span><span class="org-comment">etc.</span>
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-1-2" class="outline-4">
|
||||||
|
<h4 id="sec-1-1-2"><span class="section-number-4">1.1.2</span> <code>obj.toString()</code> ==> <code>obj+“”</code> </h4>
|
||||||
|
<div class="outline-text-4" id="text-1-1-2">
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-2" class="outline-3">
|
||||||
|
<h3 id="sec-1-2"><span class="section-number-3">1.2</span> Install (NPM) </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-2">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
UglifyJS is now available through NPM — <code>npm install uglify-js</code> should do
|
||||||
|
the job.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-3" class="outline-3">
|
||||||
|
<h3 id="sec-1-3"><span class="section-number-3">1.3</span> Install latest code from GitHub </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-3">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="src src-sh"><span class="org-comment-delimiter">## </span><span class="org-comment">clone the repository</span>
|
||||||
|
mkdir -p /where/you/wanna/put/it
|
||||||
|
<span class="org-builtin">cd</span> /where/you/wanna/put/it
|
||||||
|
git clone git://github.com/mishoo/UglifyJS.git
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">## </span><span class="org-comment">make the module available to Node</span>
|
||||||
|
mkdir -p ~/.node_libraries/
|
||||||
|
<span class="org-builtin">cd</span> ~/.node_libraries/
|
||||||
|
ln -s /where/you/wanna/put/it/UglifyJS/uglify-js.js
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">## </span><span class="org-comment">and if you want the CLI script too:</span>
|
||||||
|
mkdir -p ~/bin
|
||||||
|
<span class="org-builtin">cd</span> ~/bin
|
||||||
|
ln -s /where/you/wanna/put/it/UglifyJS/bin/uglifyjs
|
||||||
|
<span class="org-comment-delimiter"># </span><span class="org-comment">(then add ~/bin to your $PATH if it's not there already)</span>
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-4" class="outline-3">
|
||||||
|
<h3 id="sec-1-4"><span class="section-number-3">1.4</span> Usage </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-4">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There is a command-line tool that exposes the functionality of this library
|
||||||
|
for your shell-scripting needs:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="src src-sh">uglifyjs [ options... ] [ filename ]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<code>filename</code> should be the last argument and should name the file from which
|
||||||
|
to read the JavaScript code. If you don't specify it, it will read code
|
||||||
|
from STDIN.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Supported options:
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>-b</code> or <code>--beautify</code> — output indented code; when passed, additional
|
||||||
|
options control the beautifier:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>-i N</code> or <code>--indent N</code> — indentation level (number of spaces)
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-q</code> or <code>--quote-keys</code> — quote keys in literal objects (by default,
|
||||||
|
only keys that cannot be identifier names will be quotes).
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--ascii</code> — pass this argument to encode non-ASCII characters as
|
||||||
|
<code>\uXXXX</code> sequences. By default UglifyJS won't bother to do it and will
|
||||||
|
output Unicode characters instead. (the output is always encoded in UTF8,
|
||||||
|
but if you pass this option you'll only get ASCII).
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-nm</code> or <code>--no-mangle</code> — don't mangle names.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-nmf</code> or <code>--no-mangle-functions</code> – in case you want to mangle variable
|
||||||
|
names, but not touch function names.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-ns</code> or <code>--no-squeeze</code> — don't call <code>ast_squeeze()</code> (which does various
|
||||||
|
optimizations that result in smaller, less readable code).
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-mt</code> or <code>--mangle-toplevel</code> — mangle names in the toplevel scope too
|
||||||
|
(by default we don't do this).
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--no-seqs</code> — when <code>ast_squeeze()</code> is called (thus, unless you pass
|
||||||
|
<code>--no-squeeze</code>) it will reduce consecutive statements in blocks into a
|
||||||
|
sequence. For example, "a = 10; b = 20; foo();" will be written as
|
||||||
|
"a=10,b=20,foo();". In various occasions, this allows us to discard the
|
||||||
|
block brackets (since the block becomes a single statement). This is ON
|
||||||
|
by default because it seems safe and saves a few hundred bytes on some
|
||||||
|
libs that I tested it on, but pass <code>--no-seqs</code> to disable it.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--no-dead-code</code> — by default, UglifyJS will remove code that is
|
||||||
|
obviously unreachable (code that follows a <code>return</code>, <code>throw</code>, <code>break</code> or
|
||||||
|
<code>continue</code> statement and is not a function/variable declaration). Pass
|
||||||
|
this option to disable this optimization.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-nc</code> or <code>--no-copyright</code> — by default, <code>uglifyjs</code> will keep the initial
|
||||||
|
comment tokens in the generated code (assumed to be copyright information
|
||||||
|
etc.). If you pass this it will discard it.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-o filename</code> or <code>--output filename</code> — put the result in <code>filename</code>. If
|
||||||
|
this isn't given, the result goes to standard output (or see next one).
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--overwrite</code> — if the code is read from a file (not from STDIN) and you
|
||||||
|
pass <code>--overwrite</code> then the output will be written in the same file.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--ast</code> — pass this if you want to get the Abstract Syntax Tree instead
|
||||||
|
of JavaScript as output. Useful for debugging or learning more about the
|
||||||
|
internals.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-v</code> or <code>--verbose</code> — output some notes on STDERR (for now just how long
|
||||||
|
each operation takes).
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-d SYMBOL[=VALUE]</code> or <code>--define SYMBOL[=VALUE]</code> — will replace
|
||||||
|
all instances of the specified symbol where used as an identifier
|
||||||
|
(except where symbol has properly declared by a var declaration or
|
||||||
|
use as function parameter or similar) with the specified value. This
|
||||||
|
argument may be specified multiple times to define multiple
|
||||||
|
symbols - if no value is specified the symbol will be replaced with
|
||||||
|
the value <code>true</code>, or you can specify a numeric value (such as
|
||||||
|
<code>1024</code>), a quoted string value (such as ="object"= or
|
||||||
|
='https://github.com'<code>), or the name of another symbol or keyword (such as =null</code> or <code>document</code>).
|
||||||
|
This allows you, for example, to assign meaningful names to key
|
||||||
|
constant values but discard the symbolic names in the uglified
|
||||||
|
version for brevity/efficiency, or when used wth care, allows
|
||||||
|
UglifyJS to operate as a form of <b>conditional compilation</b>
|
||||||
|
whereby defining appropriate values may, by dint of the constant
|
||||||
|
folding and dead code removal features above, remove entire
|
||||||
|
superfluous code blocks (e.g. completely remove instrumentation or
|
||||||
|
trace code for production use).
|
||||||
|
Where string values are being defined, the handling of quotes are
|
||||||
|
likely to be subject to the specifics of your command shell
|
||||||
|
environment, so you may need to experiment with quoting styles
|
||||||
|
depending on your platform, or you may find the option
|
||||||
|
<code>--define-from-module</code> more suitable for use.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>-define-from-module SOMEMODULE</code> — will load the named module (as
|
||||||
|
per the NodeJS <code>require()</code> function) and iterate all the exported
|
||||||
|
properties of the module defining them as symbol names to be defined
|
||||||
|
(as if by the <code>--define</code> option) per the name of each property
|
||||||
|
(i.e. without the module name prefix) and given the value of the
|
||||||
|
property. This is a much easier way to handle and document groups of
|
||||||
|
symbols to be defined rather than a large number of <code>--define</code>
|
||||||
|
options.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--unsafe</code> — enable other additional optimizations that are known to be
|
||||||
|
unsafe in some contrived situations, but could still be generally useful.
|
||||||
|
For now only these:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>foo.toString() ==> foo+""
|
||||||
|
</li>
|
||||||
|
<li>new Array(x,…) ==> [x,…]
|
||||||
|
</li>
|
||||||
|
<li>new Array(x) ==> Array(x)
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--max-line-len</code> (default 32K characters) — add a newline after around
|
||||||
|
32K characters. I've seen both FF and Chrome croak when all the code was
|
||||||
|
on a single line of around 670K. Pass –max-line-len 0 to disable this
|
||||||
|
safety feature.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--reserved-names</code> — some libraries rely on certain names to be used, as
|
||||||
|
pointed out in issue #92 and #81, so this option allow you to exclude such
|
||||||
|
names from the mangler. For example, to keep names <code>require</code> and <code>$super</code>
|
||||||
|
intact you'd specify –reserved-names "require,$super".
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--inline-script</code> – when you want to include the output literally in an
|
||||||
|
HTML <code><script></code> tag you can use this option to prevent <code></script</code> from
|
||||||
|
showing up in the output.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>--lift-vars</code> – when you pass this, UglifyJS will apply the following
|
||||||
|
transformations (see the notes in API, <code>ast_lift_variables</code>):
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>put all <code>var</code> declarations at the start of the scope
|
||||||
|
</li>
|
||||||
|
<li>make sure a variable is declared only once
|
||||||
|
</li>
|
||||||
|
<li>discard unused function arguments
|
||||||
|
</li>
|
||||||
|
<li>discard unused inner (named) functions
|
||||||
|
</li>
|
||||||
|
<li>finally, try to merge assignments into that one <code>var</code> declaration, if
|
||||||
|
possible.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-4-1" class="outline-4">
|
||||||
|
<h4 id="sec-1-4-1"><span class="section-number-4">1.4.1</span> API </h4>
|
||||||
|
<div class="outline-text-4" id="text-1-4-1">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
To use the library from JavaScript, you'd do the following (example for
|
||||||
|
NodeJS):
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="src src-js"><span class="org-keyword">var</span> <span class="org-variable-name">jsp</span> = require(<span class="org-string">"uglify-js"</span>).parser;
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">pro</span> = require(<span class="org-string">"uglify-js"</span>).uglify;
|
||||||
|
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">orig_code</span> = <span class="org-string">"... JS code here"</span>;
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">ast</span> = jsp.parse(orig_code); <span class="org-comment-delimiter">// </span><span class="org-comment">parse code and get the initial AST</span>
|
||||||
|
ast = pro.ast_mangle(ast); <span class="org-comment-delimiter">// </span><span class="org-comment">get a new AST with mangled names</span>
|
||||||
|
ast = pro.ast_squeeze(ast); <span class="org-comment-delimiter">// </span><span class="org-comment">get an AST with compression optimizations</span>
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">final_code</span> = pro.gen_code(ast); <span class="org-comment-delimiter">// </span><span class="org-comment">compressed code here</span>
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The above performs the full compression that is possible right now. As you
|
||||||
|
can see, there are a sequence of steps which you can apply. For example if
|
||||||
|
you want compressed output but for some reason you don't want to mangle
|
||||||
|
variable names, you would simply skip the line that calls
|
||||||
|
<code>pro.ast_mangle(ast)</code>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Some of these functions take optional arguments. Here's a description:
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>jsp.parse(code, strict_semicolons)</code> – parses JS code and returns an AST.
|
||||||
|
<code>strict_semicolons</code> is optional and defaults to <code>false</code>. If you pass
|
||||||
|
<code>true</code> then the parser will throw an error when it expects a semicolon and
|
||||||
|
it doesn't find it. For most JS code you don't want that, but it's useful
|
||||||
|
if you want to strictly sanitize your code.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>pro.ast_lift_variables(ast)</code> – merge and move <code>var</code> declarations to the
|
||||||
|
scop of the scope; discard unused function arguments or variables; discard
|
||||||
|
unused (named) inner functions. It also tries to merge assignments
|
||||||
|
following the <code>var</code> declaration into it.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If your code is very hand-optimized concerning <code>var</code> declarations, this
|
||||||
|
lifting variable declarations might actually increase size. For me it
|
||||||
|
helps out. On jQuery it adds 865 bytes (243 after gzip). YMMV. Also
|
||||||
|
note that (since it's not enabled by default) this operation isn't yet
|
||||||
|
heavily tested (please report if you find issues!).
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Note that although it might increase the image size (on jQuery it gains
|
||||||
|
865 bytes, 243 after gzip) it's technically more correct: in certain
|
||||||
|
situations, dead code removal might drop variable declarations, which
|
||||||
|
would not happen if the variables are lifted in advance.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Here's an example of what it does:
|
||||||
|
</p></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="src src-js"><span class="org-keyword">function</span> <span class="org-function-name">f</span>(<span class="org-variable-name">a</span>, <span class="org-variable-name">b</span>, <span class="org-variable-name">c</span>, <span class="org-variable-name">d</span>, <span class="org-variable-name">e</span>) {
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">q</span>;
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">w</span>;
|
||||||
|
w = 10;
|
||||||
|
q = 20;
|
||||||
|
<span class="org-keyword">for</span> (<span class="org-keyword">var</span> <span class="org-variable-name">i</span> = 1; i < 10; ++i) {
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">boo</span> = foo(a);
|
||||||
|
}
|
||||||
|
<span class="org-keyword">for</span> (<span class="org-keyword">var</span> <span class="org-variable-name">i</span> = 0; i < 1; ++i) {
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">boo</span> = bar(c);
|
||||||
|
}
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">foo</span>(){ ... }
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">bar</span>(){ ... }
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">baz</span>(){ ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="org-comment-delimiter">// </span><span class="org-comment">transforms into ==></span>
|
||||||
|
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">f</span>(<span class="org-variable-name">a</span>, <span class="org-variable-name">b</span>, <span class="org-variable-name">c</span>) {
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">i</span>, <span class="org-variable-name">boo</span>, <span class="org-variable-name">w</span> = 10, <span class="org-variable-name">q</span> = 20;
|
||||||
|
<span class="org-keyword">for</span> (i = 1; i < 10; ++i) {
|
||||||
|
boo = foo(a);
|
||||||
|
}
|
||||||
|
<span class="org-keyword">for</span> (i = 0; i < 1; ++i) {
|
||||||
|
boo = bar(c);
|
||||||
|
}
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">foo</span>() { ... }
|
||||||
|
<span class="org-keyword">function</span> <span class="org-function-name">bar</span>() { ... }
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>pro.ast_mangle(ast, options)</code> – generates a new AST containing mangled
|
||||||
|
(compressed) variable and function names. It supports the following
|
||||||
|
options:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>toplevel</code> – mangle toplevel names (by default we don't touch them).
|
||||||
|
</li>
|
||||||
|
<li><code>except</code> – an array of names to exclude from compression.
|
||||||
|
</li>
|
||||||
|
<li><code>defines</code> – an object with properties named after symbols to
|
||||||
|
replace (see the <code>--define</code> option for the script) and the values
|
||||||
|
representing the AST replacement value.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>pro.ast_squeeze(ast, options)</code> – employs further optimizations designed
|
||||||
|
to reduce the size of the code that <code>gen_code</code> would generate from the
|
||||||
|
AST. Returns a new AST. <code>options</code> can be a hash; the supported options
|
||||||
|
are:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>make_seqs</code> (default true) which will cause consecutive statements in a
|
||||||
|
block to be merged using the "sequence" (comma) operator
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>dead_code</code> (default true) which will remove unreachable code.
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li><code>pro.gen_code(ast, options)</code> – generates JS code from the AST. By
|
||||||
|
default it's minified, but using the <code>options</code> argument you can get nicely
|
||||||
|
formatted output. <code>options</code> is, well, optional :-) and if you pass it it
|
||||||
|
must be an object and supports the following properties (below you can see
|
||||||
|
the default values):
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>beautify: false</code> – pass <code>true</code> if you want indented output
|
||||||
|
</li>
|
||||||
|
<li><code>indent_start: 0</code> (only applies when <code>beautify</code> is <code>true</code>) – initial
|
||||||
|
indentation in spaces
|
||||||
|
</li>
|
||||||
|
<li><code>indent_level: 4</code> (only applies when <code>beautify</code> is <code>true</code>) --
|
||||||
|
indentation level, in spaces (pass an even number)
|
||||||
|
</li>
|
||||||
|
<li><code>quote_keys: false</code> – if you pass <code>true</code> it will quote all keys in
|
||||||
|
literal objects
|
||||||
|
</li>
|
||||||
|
<li><code>space_colon: false</code> (only applies when <code>beautify</code> is <code>true</code>) – wether
|
||||||
|
to put a space before the colon in object literals
|
||||||
|
</li>
|
||||||
|
<li><code>ascii_only: false</code> – pass <code>true</code> if you want to encode non-ASCII
|
||||||
|
characters as <code>\uXXXX</code>.
|
||||||
|
</li>
|
||||||
|
<li><code>inline_script: false</code> – pass <code>true</code> to escape occurrences of
|
||||||
|
<code></script</code> in strings
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-4-2" class="outline-4">
|
||||||
|
<h4 id="sec-1-4-2"><span class="section-number-4">1.4.2</span> Beautifier shortcoming – no more comments </h4>
|
||||||
|
<div class="outline-text-4" id="text-1-4-2">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The beautifier can be used as a general purpose indentation tool. It's
|
||||||
|
useful when you want to make a minified file readable. One limitation,
|
||||||
|
though, is that it discards all comments, so you don't really want to use it
|
||||||
|
to reformat your code, unless you don't have, or don't care about, comments.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
In fact it's not the beautifier who discards comments — they are dumped at
|
||||||
|
the parsing stage, when we build the initial AST. Comments don't really
|
||||||
|
make sense in the AST, and while we could add nodes for them, it would be
|
||||||
|
inconvenient because we'd have to add special rules to ignore them at all
|
||||||
|
the processing stages.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-4-3" class="outline-4">
|
||||||
|
<h4 id="sec-1-4-3"><span class="section-number-4">1.4.3</span> Use as a code pre-processor </h4>
|
||||||
|
<div class="outline-text-4" id="text-1-4-3">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The <code>--define</code> option can be used, particularly when combined with the
|
||||||
|
constant folding logic, as a form of pre-processor to enable or remove
|
||||||
|
particular constructions, such as might be used for instrumenting
|
||||||
|
development code, or to produce variations aimed at a specific
|
||||||
|
platform.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The code below illustrates the way this can be done, and how the
|
||||||
|
symbol replacement is performed.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="src src-js">CLAUSE1: <span class="org-keyword">if</span> (<span class="org-keyword">typeof</span> DEVMODE === <span class="org-string">'undefined'</span>) {
|
||||||
|
DEVMODE = <span class="org-constant">true</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="org-function-name">CLAUSE2</span>: <span class="org-keyword">function</span> init() {
|
||||||
|
<span class="org-keyword">if</span> (DEVMODE) {
|
||||||
|
console.log(<span class="org-string">"init() called"</span>);
|
||||||
|
}
|
||||||
|
....
|
||||||
|
DEVMODE &amp;&amp; console.log(<span class="org-string">"init() complete"</span>);
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="org-function-name">CLAUSE3</span>: <span class="org-keyword">function</span> reportDeviceStatus(<span class="org-variable-name">device</span>) {
|
||||||
|
<span class="org-keyword">var</span> <span class="org-variable-name">DEVMODE</span> = device.mode, <span class="org-variable-name">DEVNAME</span> = device.name;
|
||||||
|
<span class="org-keyword">if</span> (DEVMODE === <span class="org-string">'open'</span>) {
|
||||||
|
....
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
When the above code is normally executed, the undeclared global
|
||||||
|
variable <code>DEVMODE</code> will be assigned the value <b>true</b> (see <code>CLAUSE1</code>)
|
||||||
|
and so the <code>init()</code> function (<code>CLAUSE2</code>) will write messages to the
|
||||||
|
console log when executed, but in <code>CLAUSE3</code> a locally declared
|
||||||
|
variable will mask access to the <code>DEVMODE</code> global symbol.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
If the above code is processed by UglifyJS with an argument of
|
||||||
|
<code>--define DEVMODE=false</code> then UglifyJS will replace <code>DEVMODE</code> with the
|
||||||
|
boolean constant value <b>false</b> within <code>CLAUSE1</code> and <code>CLAUSE2</code>, but it
|
||||||
|
will leave <code>CLAUSE3</code> as it stands because there <code>DEVMODE</code> resolves to
|
||||||
|
a validly declared variable.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
And more so, the constant-folding features of UglifyJS will recognise
|
||||||
|
that the <code>if</code> condition of <code>CLAUSE1</code> is thus always false, and so will
|
||||||
|
remove the test and body of <code>CLAUSE1</code> altogether (including the
|
||||||
|
otherwise slightly problematical statement <code>false = true;</code> which it
|
||||||
|
will have formed by replacing <code>DEVMODE</code> in the body). Similarly,
|
||||||
|
within <code>CLAUSE2</code> both calls to <code>console.log()</code> will be removed
|
||||||
|
altogether.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
In this way you can mimic, to a limited degree, the functionality of
|
||||||
|
the C/C++ pre-processor to enable or completely remove blocks
|
||||||
|
depending on how certain symbols are defined - perhaps using UglifyJS
|
||||||
|
to generate different versions of source aimed at different
|
||||||
|
environments
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
It is recommmended (but not made mandatory) that symbols designed for
|
||||||
|
this purpose are given names consisting of <code>UPPER_CASE_LETTERS</code> to
|
||||||
|
distinguish them from other (normal) symbols and avoid the sort of
|
||||||
|
clash that <code>CLAUSE3</code> above illustrates.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-5" class="outline-3">
|
||||||
|
<h3 id="sec-1-5"><span class="section-number-3">1.5</span> Compression – how good is it? </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-5">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Here are updated statistics. (I also updated my Google Closure and YUI
|
||||||
|
installations).
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
We're still a lot better than YUI in terms of compression, though slightly
|
||||||
|
slower. We're still a lot faster than Closure, and compression after gzip
|
||||||
|
is comparable.
|
||||||
|
</p>
|
||||||
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
||||||
|
<caption></caption>
|
||||||
|
<colgroup><col class="left" /><col class="left" /><col class="right" /><col class="left" /><col class="right" /><col class="left" /><col class="right" />
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<tr><th scope="col" class="left">File</th><th scope="col" class="left">UglifyJS</th><th scope="col" class="right">UglifyJS+gzip</th><th scope="col" class="left">Closure</th><th scope="col" class="right">Closure+gzip</th><th scope="col" class="left">YUI</th><th scope="col" class="right">YUI+gzip</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td class="left">jquery-1.6.2.js</td><td class="left">91001 (0:01.59)</td><td class="right">31896</td><td class="left">90678 (0:07.40)</td><td class="right">31979</td><td class="left">101527 (0:01.82)</td><td class="right">34646</td></tr>
|
||||||
|
<tr><td class="left">paper.js</td><td class="left">142023 (0:01.65)</td><td class="right">43334</td><td class="left">134301 (0:07.42)</td><td class="right">42495</td><td class="left">173383 (0:01.58)</td><td class="right">48785</td></tr>
|
||||||
|
<tr><td class="left">prototype.js</td><td class="left">88544 (0:01.09)</td><td class="right">26680</td><td class="left">86955 (0:06.97)</td><td class="right">26326</td><td class="left">92130 (0:00.79)</td><td class="right">28624</td></tr>
|
||||||
|
<tr><td class="left">thelib-full.js (DynarchLIB)</td><td class="left">251939 (0:02.55)</td><td class="right">72535</td><td class="left">249911 (0:09.05)</td><td class="right">72696</td><td class="left">258869 (0:01.94)</td><td class="right">76584</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-6" class="outline-3">
|
||||||
|
<h3 id="sec-1-6"><span class="section-number-3">1.6</span> Bugs? </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-6">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Unfortunately, for the time being there is no automated test suite. But I
|
||||||
|
ran the compressor manually on non-trivial code, and then I tested that the
|
||||||
|
generated code works as expected. A few hundred times.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
DynarchLIB was started in times when there was no good JS minifier.
|
||||||
|
Therefore I was quite religious about trying to write short code manually,
|
||||||
|
and as such DL contains a lot of syntactic hacks<sup><a class="footref" name="fnr.1" href="#fn.1">1</a></sup> such as “foo == bar ? a
|
||||||
|
= 10 : b = 20”, though the more readable version would clearly be to use
|
||||||
|
“if/else”.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Since the parser/compressor runs fine on DL and jQuery, I'm quite confident
|
||||||
|
that it's solid enough for production use. If you can identify any bugs,
|
||||||
|
I'd love to hear about them (<a href="http://groups.google.com/group/uglifyjs">use the Google Group</a> or email me directly).
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-7" class="outline-3">
|
||||||
|
<h3 id="sec-1-7"><span class="section-number-3">1.7</span> Links </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-7">
|
||||||
|
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Twitter: <a href="http://twitter.com/UglifyJS">@UglifyJS</a>
|
||||||
|
</li>
|
||||||
|
<li>Project at GitHub: <a href="http://github.com/mishoo/UglifyJS">http://github.com/mishoo/UglifyJS</a>
|
||||||
|
</li>
|
||||||
|
<li>Google Group: <a href="http://groups.google.com/group/uglifyjs">http://groups.google.com/group/uglifyjs</a>
|
||||||
|
</li>
|
||||||
|
<li>Common Lisp JS parser: <a href="http://marijn.haverbeke.nl/parse-js/">http://marijn.haverbeke.nl/parse-js/</a>
|
||||||
|
</li>
|
||||||
|
<li>JS-to-Lisp compiler: <a href="http://github.com/marijnh/js">http://github.com/marijnh/js</a>
|
||||||
|
</li>
|
||||||
|
<li>Common Lisp JS uglifier: <a href="http://github.com/mishoo/cl-uglify-js">http://github.com/mishoo/cl-uglify-js</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="outline-container-1-8" class="outline-3">
|
||||||
|
<h3 id="sec-1-8"><span class="section-number-3">1.8</span> License </h3>
|
||||||
|
<div class="outline-text-3" id="text-1-8">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
UglifyJS is released under the BSD license:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<pre class="example">Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||||
|
Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the following
|
||||||
|
disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following
|
||||||
|
disclaimer in the documentation and/or other materials
|
||||||
|
provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
||||||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="footnotes">
|
||||||
|
<h2 class="footnotes">Footnotes: </h2>
|
||||||
|
<div id="text-footnotes">
|
||||||
|
<p class="footnote"><sup><a class="footnum" name="fn.1" href="#fnr.1">1</a></sup> I even reported a few bugs and suggested some fixes in the original
|
||||||
|
<a href="http://marijn.haverbeke.nl/parse-js/">parse-js</a> library, and Marijn pushed fixes literally in minutes.
|
||||||
|
</p></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="postamble">
|
||||||
|
<p class="date">Date: 2011-12-09 14:59:08 EET</p>
|
||||||
|
<p class="author">Author: Mihai Bazon</p>
|
||||||
|
<p class="creator">Org version 7.7 with Emacs version 23</p>
|
||||||
|
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
574
node_modules/uglify-js/README.org
generated
vendored
Normal file
574
node_modules/uglify-js/README.org
generated
vendored
Normal file
@ -0,0 +1,574 @@
|
|||||||
|
#+TITLE: UglifyJS -- a JavaScript parser/compressor/beautifier
|
||||||
|
#+KEYWORDS: javascript, js, parser, compiler, compressor, mangle, minify, minifier
|
||||||
|
#+DESCRIPTION: a JavaScript parser/compressor/beautifier in JavaScript
|
||||||
|
#+STYLE: <link rel="stylesheet" type="text/css" href="docstyle.css" />
|
||||||
|
#+AUTHOR: Mihai Bazon
|
||||||
|
#+EMAIL: mihai.bazon@gmail.com
|
||||||
|
|
||||||
|
* UglifyJS --- a JavaScript parser/compressor/beautifier
|
||||||
|
|
||||||
|
This package implements a general-purpose JavaScript
|
||||||
|
parser/compressor/beautifier toolkit. It is developed on [[http://nodejs.org/][NodeJS]], but it
|
||||||
|
should work on any JavaScript platform supporting the CommonJS module system
|
||||||
|
(and if your platform of choice doesn't support CommonJS, you can easily
|
||||||
|
implement it, or discard the =exports.*= lines from UglifyJS sources).
|
||||||
|
|
||||||
|
The tokenizer/parser generates an abstract syntax tree from JS code. You
|
||||||
|
can then traverse the AST to learn more about the code, or do various
|
||||||
|
manipulations on it. This part is implemented in [[../lib/parse-js.js][parse-js.js]] and it's a
|
||||||
|
port to JavaScript of the excellent [[http://marijn.haverbeke.nl/parse-js/][parse-js]] Common Lisp library from [[http://marijn.haverbeke.nl/][Marijn
|
||||||
|
Haverbeke]].
|
||||||
|
|
||||||
|
( See [[http://github.com/mishoo/cl-uglify-js][cl-uglify-js]] if you're looking for the Common Lisp version of
|
||||||
|
UglifyJS. )
|
||||||
|
|
||||||
|
The second part of this package, implemented in [[../lib/process.js][process.js]], inspects and
|
||||||
|
manipulates the AST generated by the parser to provide the following:
|
||||||
|
|
||||||
|
- ability to re-generate JavaScript code from the AST. Optionally
|
||||||
|
indented---you can use this if you want to “beautify” a program that has
|
||||||
|
been compressed, so that you can inspect the source. But you can also run
|
||||||
|
our code generator to print out an AST without any whitespace, so you
|
||||||
|
achieve compression as well.
|
||||||
|
|
||||||
|
- shorten variable names (usually to single characters). Our mangler will
|
||||||
|
analyze the code and generate proper variable names, depending on scope
|
||||||
|
and usage, and is smart enough to deal with globals defined elsewhere, or
|
||||||
|
with =eval()= calls or =with{}= statements. In short, if =eval()= or
|
||||||
|
=with{}= are used in some scope, then all variables in that scope and any
|
||||||
|
variables in the parent scopes will remain unmangled, and any references
|
||||||
|
to such variables remain unmangled as well.
|
||||||
|
|
||||||
|
- various small optimizations that may lead to faster code but certainly
|
||||||
|
lead to smaller code. Where possible, we do the following:
|
||||||
|
|
||||||
|
- foo["bar"] ==> foo.bar
|
||||||
|
|
||||||
|
- remove block brackets ={}=
|
||||||
|
|
||||||
|
- join consecutive var declarations:
|
||||||
|
var a = 10; var b = 20; ==> var a=10,b=20;
|
||||||
|
|
||||||
|
- resolve simple constant expressions: 1 +2 * 3 ==> 7. We only do the
|
||||||
|
replacement if the result occupies less bytes; for example 1/3 would
|
||||||
|
translate to 0.333333333333, so in this case we don't replace it.
|
||||||
|
|
||||||
|
- consecutive statements in blocks are merged into a sequence; in many
|
||||||
|
cases, this leaves blocks with a single statement, so then we can remove
|
||||||
|
the block brackets.
|
||||||
|
|
||||||
|
- various optimizations for IF statements:
|
||||||
|
|
||||||
|
- if (foo) bar(); else baz(); ==> foo?bar():baz();
|
||||||
|
- if (!foo) bar(); else baz(); ==> foo?baz():bar();
|
||||||
|
- if (foo) bar(); ==> foo&&bar();
|
||||||
|
- if (!foo) bar(); ==> foo||bar();
|
||||||
|
- if (foo) return bar(); else return baz(); ==> return foo?bar():baz();
|
||||||
|
- if (foo) return bar(); else something(); ==> {if(foo)return bar();something()}
|
||||||
|
|
||||||
|
- remove some unreachable code and warn about it (code that follows a
|
||||||
|
=return=, =throw=, =break= or =continue= statement, except
|
||||||
|
function/variable declarations).
|
||||||
|
|
||||||
|
- act a limited version of a pre-processor (c.f. the pre-processor of
|
||||||
|
C/C++) to allow you to safely replace selected global symbols with
|
||||||
|
specified values. When combined with the optimisations above this can
|
||||||
|
make UglifyJS operate slightly more like a compilation process, in
|
||||||
|
that when certain symbols are replaced by constant values, entire code
|
||||||
|
blocks may be optimised away as unreachable.
|
||||||
|
|
||||||
|
** <<Unsafe transformations>>
|
||||||
|
|
||||||
|
The following transformations can in theory break code, although they're
|
||||||
|
probably safe in most practical cases. To enable them you need to pass the
|
||||||
|
=--unsafe= flag.
|
||||||
|
|
||||||
|
*** Calls involving the global Array constructor
|
||||||
|
|
||||||
|
The following transformations occur:
|
||||||
|
|
||||||
|
#+BEGIN_SRC js
|
||||||
|
new Array(1, 2, 3, 4) => [1,2,3,4]
|
||||||
|
Array(a, b, c) => [a,b,c]
|
||||||
|
new Array(5) => Array(5)
|
||||||
|
new Array(a) => Array(a)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
These are all safe if the Array name isn't redefined. JavaScript does allow
|
||||||
|
one to globally redefine Array (and pretty much everything, in fact) but I
|
||||||
|
personally don't see why would anyone do that.
|
||||||
|
|
||||||
|
UglifyJS does handle the case where Array is redefined locally, or even
|
||||||
|
globally but with a =function= or =var= declaration. Therefore, in the
|
||||||
|
following cases UglifyJS *doesn't touch* calls or instantiations of Array:
|
||||||
|
|
||||||
|
#+BEGIN_SRC js
|
||||||
|
// case 1. globally declared variable
|
||||||
|
var Array;
|
||||||
|
new Array(1, 2, 3);
|
||||||
|
Array(a, b);
|
||||||
|
|
||||||
|
// or (can be declared later)
|
||||||
|
new Array(1, 2, 3);
|
||||||
|
var Array;
|
||||||
|
|
||||||
|
// or (can be a function)
|
||||||
|
new Array(1, 2, 3);
|
||||||
|
function Array() { ... }
|
||||||
|
|
||||||
|
// case 2. declared in a function
|
||||||
|
(function(){
|
||||||
|
a = new Array(1, 2, 3);
|
||||||
|
b = Array(5, 6);
|
||||||
|
var Array;
|
||||||
|
})();
|
||||||
|
|
||||||
|
// or
|
||||||
|
(function(Array){
|
||||||
|
return Array(5, 6, 7);
|
||||||
|
})();
|
||||||
|
|
||||||
|
// or
|
||||||
|
(function(){
|
||||||
|
return new Array(1, 2, 3, 4);
|
||||||
|
function Array() { ... }
|
||||||
|
})();
|
||||||
|
|
||||||
|
// etc.
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
*** =obj.toString()= ==> =obj+“”=
|
||||||
|
|
||||||
|
** Install (NPM)
|
||||||
|
|
||||||
|
UglifyJS is now available through NPM --- =npm install uglify-js= should do
|
||||||
|
the job.
|
||||||
|
|
||||||
|
** Install latest code from GitHub
|
||||||
|
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
## clone the repository
|
||||||
|
mkdir -p /where/you/wanna/put/it
|
||||||
|
cd /where/you/wanna/put/it
|
||||||
|
git clone git://github.com/mishoo/UglifyJS.git
|
||||||
|
|
||||||
|
## make the module available to Node
|
||||||
|
mkdir -p ~/.node_libraries/
|
||||||
|
cd ~/.node_libraries/
|
||||||
|
ln -s /where/you/wanna/put/it/UglifyJS/uglify-js.js
|
||||||
|
|
||||||
|
## and if you want the CLI script too:
|
||||||
|
mkdir -p ~/bin
|
||||||
|
cd ~/bin
|
||||||
|
ln -s /where/you/wanna/put/it/UglifyJS/bin/uglifyjs
|
||||||
|
# (then add ~/bin to your $PATH if it's not there already)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Usage
|
||||||
|
|
||||||
|
There is a command-line tool that exposes the functionality of this library
|
||||||
|
for your shell-scripting needs:
|
||||||
|
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
uglifyjs [ options... ] [ filename ]
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
=filename= should be the last argument and should name the file from which
|
||||||
|
to read the JavaScript code. If you don't specify it, it will read code
|
||||||
|
from STDIN.
|
||||||
|
|
||||||
|
Supported options:
|
||||||
|
|
||||||
|
- =-b= or =--beautify= --- output indented code; when passed, additional
|
||||||
|
options control the beautifier:
|
||||||
|
|
||||||
|
- =-i N= or =--indent N= --- indentation level (number of spaces)
|
||||||
|
|
||||||
|
- =-q= or =--quote-keys= --- quote keys in literal objects (by default,
|
||||||
|
only keys that cannot be identifier names will be quotes).
|
||||||
|
|
||||||
|
- =--ascii= --- pass this argument to encode non-ASCII characters as
|
||||||
|
=\uXXXX= sequences. By default UglifyJS won't bother to do it and will
|
||||||
|
output Unicode characters instead. (the output is always encoded in UTF8,
|
||||||
|
but if you pass this option you'll only get ASCII).
|
||||||
|
|
||||||
|
- =-nm= or =--no-mangle= --- don't mangle names.
|
||||||
|
|
||||||
|
- =-nmf= or =--no-mangle-functions= -- in case you want to mangle variable
|
||||||
|
names, but not touch function names.
|
||||||
|
|
||||||
|
- =-ns= or =--no-squeeze= --- don't call =ast_squeeze()= (which does various
|
||||||
|
optimizations that result in smaller, less readable code).
|
||||||
|
|
||||||
|
- =-mt= or =--mangle-toplevel= --- mangle names in the toplevel scope too
|
||||||
|
(by default we don't do this).
|
||||||
|
|
||||||
|
- =--no-seqs= --- when =ast_squeeze()= is called (thus, unless you pass
|
||||||
|
=--no-squeeze=) it will reduce consecutive statements in blocks into a
|
||||||
|
sequence. For example, "a = 10; b = 20; foo();" will be written as
|
||||||
|
"a=10,b=20,foo();". In various occasions, this allows us to discard the
|
||||||
|
block brackets (since the block becomes a single statement). This is ON
|
||||||
|
by default because it seems safe and saves a few hundred bytes on some
|
||||||
|
libs that I tested it on, but pass =--no-seqs= to disable it.
|
||||||
|
|
||||||
|
- =--no-dead-code= --- by default, UglifyJS will remove code that is
|
||||||
|
obviously unreachable (code that follows a =return=, =throw=, =break= or
|
||||||
|
=continue= statement and is not a function/variable declaration). Pass
|
||||||
|
this option to disable this optimization.
|
||||||
|
|
||||||
|
- =-nc= or =--no-copyright= --- by default, =uglifyjs= will keep the initial
|
||||||
|
comment tokens in the generated code (assumed to be copyright information
|
||||||
|
etc.). If you pass this it will discard it.
|
||||||
|
|
||||||
|
- =-o filename= or =--output filename= --- put the result in =filename=. If
|
||||||
|
this isn't given, the result goes to standard output (or see next one).
|
||||||
|
|
||||||
|
- =--overwrite= --- if the code is read from a file (not from STDIN) and you
|
||||||
|
pass =--overwrite= then the output will be written in the same file.
|
||||||
|
|
||||||
|
- =--ast= --- pass this if you want to get the Abstract Syntax Tree instead
|
||||||
|
of JavaScript as output. Useful for debugging or learning more about the
|
||||||
|
internals.
|
||||||
|
|
||||||
|
- =-v= or =--verbose= --- output some notes on STDERR (for now just how long
|
||||||
|
each operation takes).
|
||||||
|
|
||||||
|
- =-d SYMBOL[=VALUE]= or =--define SYMBOL[=VALUE]= --- will replace
|
||||||
|
all instances of the specified symbol where used as an identifier
|
||||||
|
(except where symbol has properly declared by a var declaration or
|
||||||
|
use as function parameter or similar) with the specified value. This
|
||||||
|
argument may be specified multiple times to define multiple
|
||||||
|
symbols - if no value is specified the symbol will be replaced with
|
||||||
|
the value =true=, or you can specify a numeric value (such as
|
||||||
|
=1024=), a quoted string value (such as ="object"= or
|
||||||
|
='https://github.com'=), or the name of another symbol or keyword
|
||||||
|
(such as =null= or =document=).
|
||||||
|
This allows you, for example, to assign meaningful names to key
|
||||||
|
constant values but discard the symbolic names in the uglified
|
||||||
|
version for brevity/efficiency, or when used wth care, allows
|
||||||
|
UglifyJS to operate as a form of *conditional compilation*
|
||||||
|
whereby defining appropriate values may, by dint of the constant
|
||||||
|
folding and dead code removal features above, remove entire
|
||||||
|
superfluous code blocks (e.g. completely remove instrumentation or
|
||||||
|
trace code for production use).
|
||||||
|
Where string values are being defined, the handling of quotes are
|
||||||
|
likely to be subject to the specifics of your command shell
|
||||||
|
environment, so you may need to experiment with quoting styles
|
||||||
|
depending on your platform, or you may find the option
|
||||||
|
=--define-from-module= more suitable for use.
|
||||||
|
|
||||||
|
- =-define-from-module SOMEMODULE= --- will load the named module (as
|
||||||
|
per the NodeJS =require()= function) and iterate all the exported
|
||||||
|
properties of the module defining them as symbol names to be defined
|
||||||
|
(as if by the =--define= option) per the name of each property
|
||||||
|
(i.e. without the module name prefix) and given the value of the
|
||||||
|
property. This is a much easier way to handle and document groups of
|
||||||
|
symbols to be defined rather than a large number of =--define=
|
||||||
|
options.
|
||||||
|
|
||||||
|
- =--unsafe= --- enable other additional optimizations that are known to be
|
||||||
|
unsafe in some contrived situations, but could still be generally useful.
|
||||||
|
For now only these:
|
||||||
|
|
||||||
|
- foo.toString() ==> foo+""
|
||||||
|
- new Array(x,...) ==> [x,...]
|
||||||
|
- new Array(x) ==> Array(x)
|
||||||
|
|
||||||
|
- =--max-line-len= (default 32K characters) --- add a newline after around
|
||||||
|
32K characters. I've seen both FF and Chrome croak when all the code was
|
||||||
|
on a single line of around 670K. Pass --max-line-len 0 to disable this
|
||||||
|
safety feature.
|
||||||
|
|
||||||
|
- =--reserved-names= --- some libraries rely on certain names to be used, as
|
||||||
|
pointed out in issue #92 and #81, so this option allow you to exclude such
|
||||||
|
names from the mangler. For example, to keep names =require= and =$super=
|
||||||
|
intact you'd specify --reserved-names "require,$super".
|
||||||
|
|
||||||
|
- =--inline-script= -- when you want to include the output literally in an
|
||||||
|
HTML =<script>= tag you can use this option to prevent =</script= from
|
||||||
|
showing up in the output.
|
||||||
|
|
||||||
|
- =--lift-vars= -- when you pass this, UglifyJS will apply the following
|
||||||
|
transformations (see the notes in API, =ast_lift_variables=):
|
||||||
|
|
||||||
|
- put all =var= declarations at the start of the scope
|
||||||
|
- make sure a variable is declared only once
|
||||||
|
- discard unused function arguments
|
||||||
|
- discard unused inner (named) functions
|
||||||
|
- finally, try to merge assignments into that one =var= declaration, if
|
||||||
|
possible.
|
||||||
|
|
||||||
|
*** API
|
||||||
|
|
||||||
|
To use the library from JavaScript, you'd do the following (example for
|
||||||
|
NodeJS):
|
||||||
|
|
||||||
|
#+BEGIN_SRC js
|
||||||
|
var jsp = require("uglify-js").parser;
|
||||||
|
var pro = require("uglify-js").uglify;
|
||||||
|
|
||||||
|
var orig_code = "... JS code here";
|
||||||
|
var ast = jsp.parse(orig_code); // parse code and get the initial AST
|
||||||
|
ast = pro.ast_mangle(ast); // get a new AST with mangled names
|
||||||
|
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
|
||||||
|
var final_code = pro.gen_code(ast); // compressed code here
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
The above performs the full compression that is possible right now. As you
|
||||||
|
can see, there are a sequence of steps which you can apply. For example if
|
||||||
|
you want compressed output but for some reason you don't want to mangle
|
||||||
|
variable names, you would simply skip the line that calls
|
||||||
|
=pro.ast_mangle(ast)=.
|
||||||
|
|
||||||
|
Some of these functions take optional arguments. Here's a description:
|
||||||
|
|
||||||
|
- =jsp.parse(code, strict_semicolons)= -- parses JS code and returns an AST.
|
||||||
|
=strict_semicolons= is optional and defaults to =false=. If you pass
|
||||||
|
=true= then the parser will throw an error when it expects a semicolon and
|
||||||
|
it doesn't find it. For most JS code you don't want that, but it's useful
|
||||||
|
if you want to strictly sanitize your code.
|
||||||
|
|
||||||
|
- =pro.ast_lift_variables(ast)= -- merge and move =var= declarations to the
|
||||||
|
scop of the scope; discard unused function arguments or variables; discard
|
||||||
|
unused (named) inner functions. It also tries to merge assignments
|
||||||
|
following the =var= declaration into it.
|
||||||
|
|
||||||
|
If your code is very hand-optimized concerning =var= declarations, this
|
||||||
|
lifting variable declarations might actually increase size. For me it
|
||||||
|
helps out. On jQuery it adds 865 bytes (243 after gzip). YMMV. Also
|
||||||
|
note that (since it's not enabled by default) this operation isn't yet
|
||||||
|
heavily tested (please report if you find issues!).
|
||||||
|
|
||||||
|
Note that although it might increase the image size (on jQuery it gains
|
||||||
|
865 bytes, 243 after gzip) it's technically more correct: in certain
|
||||||
|
situations, dead code removal might drop variable declarations, which
|
||||||
|
would not happen if the variables are lifted in advance.
|
||||||
|
|
||||||
|
Here's an example of what it does:
|
||||||
|
|
||||||
|
#+BEGIN_SRC js
|
||||||
|
function f(a, b, c, d, e) {
|
||||||
|
var q;
|
||||||
|
var w;
|
||||||
|
w = 10;
|
||||||
|
q = 20;
|
||||||
|
for (var i = 1; i < 10; ++i) {
|
||||||
|
var boo = foo(a);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 1; ++i) {
|
||||||
|
var boo = bar(c);
|
||||||
|
}
|
||||||
|
function foo(){ ... }
|
||||||
|
function bar(){ ... }
|
||||||
|
function baz(){ ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
// transforms into ==>
|
||||||
|
|
||||||
|
function f(a, b, c) {
|
||||||
|
var i, boo, w = 10, q = 20;
|
||||||
|
for (i = 1; i < 10; ++i) {
|
||||||
|
boo = foo(a);
|
||||||
|
}
|
||||||
|
for (i = 0; i < 1; ++i) {
|
||||||
|
boo = bar(c);
|
||||||
|
}
|
||||||
|
function foo() { ... }
|
||||||
|
function bar() { ... }
|
||||||
|
}
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- =pro.ast_mangle(ast, options)= -- generates a new AST containing mangled
|
||||||
|
(compressed) variable and function names. It supports the following
|
||||||
|
options:
|
||||||
|
|
||||||
|
- =toplevel= -- mangle toplevel names (by default we don't touch them).
|
||||||
|
- =except= -- an array of names to exclude from compression.
|
||||||
|
- =defines= -- an object with properties named after symbols to
|
||||||
|
replace (see the =--define= option for the script) and the values
|
||||||
|
representing the AST replacement value.
|
||||||
|
|
||||||
|
- =pro.ast_squeeze(ast, options)= -- employs further optimizations designed
|
||||||
|
to reduce the size of the code that =gen_code= would generate from the
|
||||||
|
AST. Returns a new AST. =options= can be a hash; the supported options
|
||||||
|
are:
|
||||||
|
|
||||||
|
- =make_seqs= (default true) which will cause consecutive statements in a
|
||||||
|
block to be merged using the "sequence" (comma) operator
|
||||||
|
|
||||||
|
- =dead_code= (default true) which will remove unreachable code.
|
||||||
|
|
||||||
|
- =pro.gen_code(ast, options)= -- generates JS code from the AST. By
|
||||||
|
default it's minified, but using the =options= argument you can get nicely
|
||||||
|
formatted output. =options= is, well, optional :-) and if you pass it it
|
||||||
|
must be an object and supports the following properties (below you can see
|
||||||
|
the default values):
|
||||||
|
|
||||||
|
- =beautify: false= -- pass =true= if you want indented output
|
||||||
|
- =indent_start: 0= (only applies when =beautify= is =true=) -- initial
|
||||||
|
indentation in spaces
|
||||||
|
- =indent_level: 4= (only applies when =beautify= is =true=) --
|
||||||
|
indentation level, in spaces (pass an even number)
|
||||||
|
- =quote_keys: false= -- if you pass =true= it will quote all keys in
|
||||||
|
literal objects
|
||||||
|
- =space_colon: false= (only applies when =beautify= is =true=) -- wether
|
||||||
|
to put a space before the colon in object literals
|
||||||
|
- =ascii_only: false= -- pass =true= if you want to encode non-ASCII
|
||||||
|
characters as =\uXXXX=.
|
||||||
|
- =inline_script: false= -- pass =true= to escape occurrences of
|
||||||
|
=</script= in strings
|
||||||
|
|
||||||
|
*** Beautifier shortcoming -- no more comments
|
||||||
|
|
||||||
|
The beautifier can be used as a general purpose indentation tool. It's
|
||||||
|
useful when you want to make a minified file readable. One limitation,
|
||||||
|
though, is that it discards all comments, so you don't really want to use it
|
||||||
|
to reformat your code, unless you don't have, or don't care about, comments.
|
||||||
|
|
||||||
|
In fact it's not the beautifier who discards comments --- they are dumped at
|
||||||
|
the parsing stage, when we build the initial AST. Comments don't really
|
||||||
|
make sense in the AST, and while we could add nodes for them, it would be
|
||||||
|
inconvenient because we'd have to add special rules to ignore them at all
|
||||||
|
the processing stages.
|
||||||
|
|
||||||
|
*** Use as a code pre-processor
|
||||||
|
|
||||||
|
The =--define= option can be used, particularly when combined with the
|
||||||
|
constant folding logic, as a form of pre-processor to enable or remove
|
||||||
|
particular constructions, such as might be used for instrumenting
|
||||||
|
development code, or to produce variations aimed at a specific
|
||||||
|
platform.
|
||||||
|
|
||||||
|
The code below illustrates the way this can be done, and how the
|
||||||
|
symbol replacement is performed.
|
||||||
|
|
||||||
|
#+BEGIN_SRC js
|
||||||
|
CLAUSE1: if (typeof DEVMODE === 'undefined') {
|
||||||
|
DEVMODE = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CLAUSE2: function init() {
|
||||||
|
if (DEVMODE) {
|
||||||
|
console.log("init() called");
|
||||||
|
}
|
||||||
|
....
|
||||||
|
DEVMODE && console.log("init() complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
CLAUSE3: function reportDeviceStatus(device) {
|
||||||
|
var DEVMODE = device.mode, DEVNAME = device.name;
|
||||||
|
if (DEVMODE === 'open') {
|
||||||
|
....
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
When the above code is normally executed, the undeclared global
|
||||||
|
variable =DEVMODE= will be assigned the value *true* (see =CLAUSE1=)
|
||||||
|
and so the =init()= function (=CLAUSE2=) will write messages to the
|
||||||
|
console log when executed, but in =CLAUSE3= a locally declared
|
||||||
|
variable will mask access to the =DEVMODE= global symbol.
|
||||||
|
|
||||||
|
If the above code is processed by UglifyJS with an argument of
|
||||||
|
=--define DEVMODE=false= then UglifyJS will replace =DEVMODE= with the
|
||||||
|
boolean constant value *false* within =CLAUSE1= and =CLAUSE2=, but it
|
||||||
|
will leave =CLAUSE3= as it stands because there =DEVMODE= resolves to
|
||||||
|
a validly declared variable.
|
||||||
|
|
||||||
|
And more so, the constant-folding features of UglifyJS will recognise
|
||||||
|
that the =if= condition of =CLAUSE1= is thus always false, and so will
|
||||||
|
remove the test and body of =CLAUSE1= altogether (including the
|
||||||
|
otherwise slightly problematical statement =false = true;= which it
|
||||||
|
will have formed by replacing =DEVMODE= in the body). Similarly,
|
||||||
|
within =CLAUSE2= both calls to =console.log()= will be removed
|
||||||
|
altogether.
|
||||||
|
|
||||||
|
In this way you can mimic, to a limited degree, the functionality of
|
||||||
|
the C/C++ pre-processor to enable or completely remove blocks
|
||||||
|
depending on how certain symbols are defined - perhaps using UglifyJS
|
||||||
|
to generate different versions of source aimed at different
|
||||||
|
environments
|
||||||
|
|
||||||
|
It is recommmended (but not made mandatory) that symbols designed for
|
||||||
|
this purpose are given names consisting of =UPPER_CASE_LETTERS= to
|
||||||
|
distinguish them from other (normal) symbols and avoid the sort of
|
||||||
|
clash that =CLAUSE3= above illustrates.
|
||||||
|
|
||||||
|
** Compression -- how good is it?
|
||||||
|
|
||||||
|
Here are updated statistics. (I also updated my Google Closure and YUI
|
||||||
|
installations).
|
||||||
|
|
||||||
|
We're still a lot better than YUI in terms of compression, though slightly
|
||||||
|
slower. We're still a lot faster than Closure, and compression after gzip
|
||||||
|
is comparable.
|
||||||
|
|
||||||
|
| File | UglifyJS | UglifyJS+gzip | Closure | Closure+gzip | YUI | YUI+gzip |
|
||||||
|
|-----------------------------+------------------+---------------+------------------+--------------+------------------+----------|
|
||||||
|
| jquery-1.6.2.js | 91001 (0:01.59) | 31896 | 90678 (0:07.40) | 31979 | 101527 (0:01.82) | 34646 |
|
||||||
|
| paper.js | 142023 (0:01.65) | 43334 | 134301 (0:07.42) | 42495 | 173383 (0:01.58) | 48785 |
|
||||||
|
| prototype.js | 88544 (0:01.09) | 26680 | 86955 (0:06.97) | 26326 | 92130 (0:00.79) | 28624 |
|
||||||
|
| thelib-full.js (DynarchLIB) | 251939 (0:02.55) | 72535 | 249911 (0:09.05) | 72696 | 258869 (0:01.94) | 76584 |
|
||||||
|
|
||||||
|
** Bugs?
|
||||||
|
|
||||||
|
Unfortunately, for the time being there is no automated test suite. But I
|
||||||
|
ran the compressor manually on non-trivial code, and then I tested that the
|
||||||
|
generated code works as expected. A few hundred times.
|
||||||
|
|
||||||
|
DynarchLIB was started in times when there was no good JS minifier.
|
||||||
|
Therefore I was quite religious about trying to write short code manually,
|
||||||
|
and as such DL contains a lot of syntactic hacks[1] such as “foo == bar ? a
|
||||||
|
= 10 : b = 20”, though the more readable version would clearly be to use
|
||||||
|
“if/else”.
|
||||||
|
|
||||||
|
Since the parser/compressor runs fine on DL and jQuery, I'm quite confident
|
||||||
|
that it's solid enough for production use. If you can identify any bugs,
|
||||||
|
I'd love to hear about them ([[http://groups.google.com/group/uglifyjs][use the Google Group]] or email me directly).
|
||||||
|
|
||||||
|
[1] I even reported a few bugs and suggested some fixes in the original
|
||||||
|
[[http://marijn.haverbeke.nl/parse-js/][parse-js]] library, and Marijn pushed fixes literally in minutes.
|
||||||
|
|
||||||
|
** Links
|
||||||
|
|
||||||
|
- Twitter: [[http://twitter.com/UglifyJS][@UglifyJS]]
|
||||||
|
- Project at GitHub: [[http://github.com/mishoo/UglifyJS][http://github.com/mishoo/UglifyJS]]
|
||||||
|
- Google Group: [[http://groups.google.com/group/uglifyjs][http://groups.google.com/group/uglifyjs]]
|
||||||
|
- Common Lisp JS parser: [[http://marijn.haverbeke.nl/parse-js/][http://marijn.haverbeke.nl/parse-js/]]
|
||||||
|
- JS-to-Lisp compiler: [[http://github.com/marijnh/js][http://github.com/marijnh/js]]
|
||||||
|
- Common Lisp JS uglifier: [[http://github.com/mishoo/cl-uglify-js][http://github.com/mishoo/cl-uglify-js]]
|
||||||
|
|
||||||
|
** License
|
||||||
|
|
||||||
|
UglifyJS is released under the BSD license:
|
||||||
|
|
||||||
|
#+BEGIN_EXAMPLE
|
||||||
|
Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||||
|
Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the following
|
||||||
|
disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following
|
||||||
|
disclaimer in the documentation and/or other materials
|
||||||
|
provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
||||||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
#+END_EXAMPLE
|
323
node_modules/uglify-js/bin/uglifyjs
generated
vendored
Executable file
323
node_modules/uglify-js/bin/uglifyjs
generated
vendored
Executable file
@ -0,0 +1,323 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
// -*- js -*-
|
||||||
|
|
||||||
|
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
|
||||||
|
var fs = require("fs");
|
||||||
|
var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
|
||||||
|
jsp = uglify.parser,
|
||||||
|
pro = uglify.uglify;
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
ast: false,
|
||||||
|
mangle: true,
|
||||||
|
mangle_toplevel: false,
|
||||||
|
no_mangle_functions: false,
|
||||||
|
squeeze: true,
|
||||||
|
make_seqs: true,
|
||||||
|
dead_code: true,
|
||||||
|
verbose: false,
|
||||||
|
show_copyright: true,
|
||||||
|
out_same_file: false,
|
||||||
|
max_line_length: 32 * 1024,
|
||||||
|
unsafe: false,
|
||||||
|
reserved_names: null,
|
||||||
|
defines: { },
|
||||||
|
lift_vars: false,
|
||||||
|
codegen_options: {
|
||||||
|
ascii_only: false,
|
||||||
|
beautify: false,
|
||||||
|
indent_level: 4,
|
||||||
|
indent_start: 0,
|
||||||
|
quote_keys: false,
|
||||||
|
space_colon: false,
|
||||||
|
inline_script: false
|
||||||
|
},
|
||||||
|
make: false,
|
||||||
|
output: true // stdout
|
||||||
|
};
|
||||||
|
|
||||||
|
var args = jsp.slice(process.argv, 2);
|
||||||
|
var filename;
|
||||||
|
|
||||||
|
out: while (args.length > 0) {
|
||||||
|
var v = args.shift();
|
||||||
|
switch (v) {
|
||||||
|
case "-b":
|
||||||
|
case "--beautify":
|
||||||
|
options.codegen_options.beautify = true;
|
||||||
|
break;
|
||||||
|
case "-i":
|
||||||
|
case "--indent":
|
||||||
|
options.codegen_options.indent_level = args.shift();
|
||||||
|
break;
|
||||||
|
case "-q":
|
||||||
|
case "--quote-keys":
|
||||||
|
options.codegen_options.quote_keys = true;
|
||||||
|
break;
|
||||||
|
case "-mt":
|
||||||
|
case "--mangle-toplevel":
|
||||||
|
options.mangle_toplevel = true;
|
||||||
|
break;
|
||||||
|
case "-nmf":
|
||||||
|
case "--no-mangle-functions":
|
||||||
|
options.no_mangle_functions = true;
|
||||||
|
break;
|
||||||
|
case "--no-mangle":
|
||||||
|
case "-nm":
|
||||||
|
options.mangle = false;
|
||||||
|
break;
|
||||||
|
case "--no-squeeze":
|
||||||
|
case "-ns":
|
||||||
|
options.squeeze = false;
|
||||||
|
break;
|
||||||
|
case "--no-seqs":
|
||||||
|
options.make_seqs = false;
|
||||||
|
break;
|
||||||
|
case "--no-dead-code":
|
||||||
|
options.dead_code = false;
|
||||||
|
break;
|
||||||
|
case "--no-copyright":
|
||||||
|
case "-nc":
|
||||||
|
options.show_copyright = false;
|
||||||
|
break;
|
||||||
|
case "-o":
|
||||||
|
case "--output":
|
||||||
|
options.output = args.shift();
|
||||||
|
break;
|
||||||
|
case "--overwrite":
|
||||||
|
options.out_same_file = true;
|
||||||
|
break;
|
||||||
|
case "-v":
|
||||||
|
case "--verbose":
|
||||||
|
options.verbose = true;
|
||||||
|
break;
|
||||||
|
case "--ast":
|
||||||
|
options.ast = true;
|
||||||
|
break;
|
||||||
|
case "--unsafe":
|
||||||
|
options.unsafe = true;
|
||||||
|
break;
|
||||||
|
case "--max-line-len":
|
||||||
|
options.max_line_length = parseInt(args.shift(), 10);
|
||||||
|
break;
|
||||||
|
case "--reserved-names":
|
||||||
|
options.reserved_names = args.shift().split(",");
|
||||||
|
break;
|
||||||
|
case "--lift-vars":
|
||||||
|
options.lift_vars = true;
|
||||||
|
break;
|
||||||
|
case "-d":
|
||||||
|
case "--define":
|
||||||
|
var defarg = args.shift();
|
||||||
|
try {
|
||||||
|
var defsym = function(sym) {
|
||||||
|
// KEYWORDS_ATOM doesn't include NaN or Infinity - should we check
|
||||||
|
// for them too ?? We don't check reserved words and the like as the
|
||||||
|
// define values are only substituted AFTER parsing
|
||||||
|
if (jsp.KEYWORDS_ATOM.hasOwnProperty(sym)) {
|
||||||
|
throw "Don't define values for inbuilt constant '"+sym+"'";
|
||||||
|
}
|
||||||
|
return sym;
|
||||||
|
},
|
||||||
|
defval = function(v) {
|
||||||
|
if (v.match(/^"(.*)"$/) || v.match(/^'(.*)'$/)) {
|
||||||
|
return [ "string", RegExp.$1 ];
|
||||||
|
}
|
||||||
|
else if (!isNaN(parseFloat(v))) {
|
||||||
|
return [ "num", parseFloat(v) ];
|
||||||
|
}
|
||||||
|
else if (v.match(/^[a-z\$_][a-z\$_0-9]*$/i)) {
|
||||||
|
return [ "name", v ];
|
||||||
|
}
|
||||||
|
else if (!v.match(/"/)) {
|
||||||
|
return [ "string", v ];
|
||||||
|
}
|
||||||
|
else if (!v.match(/'/)) {
|
||||||
|
return [ "string", v ];
|
||||||
|
}
|
||||||
|
throw "Can't understand the specified value: "+v;
|
||||||
|
};
|
||||||
|
if (defarg.match(/^([a-z_\$][a-z_\$0-9]*)(=(.*))?$/i)) {
|
||||||
|
var sym = defsym(RegExp.$1),
|
||||||
|
val = RegExp.$2 ? defval(RegExp.$2.substr(1)) : [ 'name', 'true' ];
|
||||||
|
options.defines[sym] = val;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw "The --define option expects SYMBOL[=value]";
|
||||||
|
}
|
||||||
|
} catch(ex) {
|
||||||
|
sys.print("ERROR: In option --define "+defarg+"\n"+ex+"\n");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "--define-from-module":
|
||||||
|
var defmodarg = args.shift(),
|
||||||
|
defmodule = require(defmodarg),
|
||||||
|
sym,
|
||||||
|
val;
|
||||||
|
for (sym in defmodule) {
|
||||||
|
if (defmodule.hasOwnProperty(sym)) {
|
||||||
|
options.defines[sym] = function(val) {
|
||||||
|
if (typeof val == "string")
|
||||||
|
return [ "string", val ];
|
||||||
|
if (typeof val == "number")
|
||||||
|
return [ "num", val ];
|
||||||
|
if (val === true)
|
||||||
|
return [ 'name', 'true' ];
|
||||||
|
if (val === false)
|
||||||
|
return [ 'name', 'false' ];
|
||||||
|
if (val === null)
|
||||||
|
return [ 'name', 'null' ];
|
||||||
|
if (val === undefined)
|
||||||
|
return [ 'name', 'undefined' ];
|
||||||
|
sys.print("ERROR: In option --define-from-module "+defmodarg+"\n");
|
||||||
|
sys.print("ERROR: Unknown object type for: "+sym+"="+val+"\n");
|
||||||
|
process.exit(1);
|
||||||
|
return null;
|
||||||
|
}(defmodule[sym]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "--ascii":
|
||||||
|
options.codegen_options.ascii_only = true;
|
||||||
|
break;
|
||||||
|
case "--make":
|
||||||
|
options.make = true;
|
||||||
|
break;
|
||||||
|
case "--inline-script":
|
||||||
|
options.codegen_options.inline_script = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
filename = v;
|
||||||
|
break out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.verbose) {
|
||||||
|
pro.set_logger(function(msg){
|
||||||
|
sys.debug(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
jsp.set_logger(function(msg){
|
||||||
|
sys.debug(msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (options.make) {
|
||||||
|
options.out_same_file = false; // doesn't make sense in this case
|
||||||
|
var makefile = JSON.parse(fs.readFileSync(filename || "Makefile.uglify.js").toString());
|
||||||
|
output(makefile.files.map(function(file){
|
||||||
|
var code = fs.readFileSync(file.name);
|
||||||
|
if (file.module) {
|
||||||
|
code = "!function(exports, global){global = this;\n" + code + "\n;this." + file.module + " = exports;}({})";
|
||||||
|
}
|
||||||
|
else if (file.hide) {
|
||||||
|
code = "(function(){" + code + "}());";
|
||||||
|
}
|
||||||
|
return squeeze_it(code);
|
||||||
|
}).join("\n"));
|
||||||
|
}
|
||||||
|
else if (filename) {
|
||||||
|
fs.readFile(filename, "utf8", function(err, text){
|
||||||
|
if (err) throw err;
|
||||||
|
output(squeeze_it(text));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var stdin = process.openStdin();
|
||||||
|
stdin.setEncoding("utf8");
|
||||||
|
var text = "";
|
||||||
|
stdin.on("data", function(chunk){
|
||||||
|
text += chunk;
|
||||||
|
});
|
||||||
|
stdin.on("end", function() {
|
||||||
|
output(squeeze_it(text));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function output(text) {
|
||||||
|
var out;
|
||||||
|
if (options.out_same_file && filename)
|
||||||
|
options.output = filename;
|
||||||
|
if (options.output === true) {
|
||||||
|
out = process.stdout;
|
||||||
|
} else {
|
||||||
|
out = fs.createWriteStream(options.output, {
|
||||||
|
flags: "w",
|
||||||
|
encoding: "utf8",
|
||||||
|
mode: 0644
|
||||||
|
});
|
||||||
|
}
|
||||||
|
out.write(text.replace(/;*$/, ";"));
|
||||||
|
if (options.output !== true) {
|
||||||
|
out.end();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// --------- main ends here.
|
||||||
|
|
||||||
|
function show_copyright(comments) {
|
||||||
|
var ret = "";
|
||||||
|
for (var i = 0; i < comments.length; ++i) {
|
||||||
|
var c = comments[i];
|
||||||
|
if (c.type == "comment1") {
|
||||||
|
ret += "//" + c.value + "\n";
|
||||||
|
} else {
|
||||||
|
ret += "/*" + c.value + "*/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
function squeeze_it(code) {
|
||||||
|
var result = "";
|
||||||
|
if (options.show_copyright) {
|
||||||
|
var tok = jsp.tokenizer(code), c;
|
||||||
|
c = tok();
|
||||||
|
result += show_copyright(c.comments_before);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var ast = time_it("parse", function(){ return jsp.parse(code); });
|
||||||
|
if (options.lift_vars) {
|
||||||
|
ast = time_it("lift", function(){ return pro.ast_lift_variables(ast); });
|
||||||
|
}
|
||||||
|
if (options.mangle) ast = time_it("mangle", function(){
|
||||||
|
return pro.ast_mangle(ast, {
|
||||||
|
toplevel : options.mangle_toplevel,
|
||||||
|
defines : options.defines,
|
||||||
|
except : options.reserved_names,
|
||||||
|
no_functions : options.no_mangle_functions
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (options.squeeze) ast = time_it("squeeze", function(){
|
||||||
|
ast = pro.ast_squeeze(ast, {
|
||||||
|
make_seqs : options.make_seqs,
|
||||||
|
dead_code : options.dead_code,
|
||||||
|
keep_comps : !options.unsafe
|
||||||
|
});
|
||||||
|
if (options.unsafe)
|
||||||
|
ast = pro.ast_squeeze_more(ast);
|
||||||
|
return ast;
|
||||||
|
});
|
||||||
|
if (options.ast)
|
||||||
|
return sys.inspect(ast, null, null);
|
||||||
|
result += time_it("generate", function(){ return pro.gen_code(ast, options.codegen_options) });
|
||||||
|
if (!options.codegen_options.beautify && options.max_line_length) {
|
||||||
|
result = time_it("split", function(){ return pro.split_lines(result, options.max_line_length) });
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch(ex) {
|
||||||
|
sys.debug(ex.stack);
|
||||||
|
sys.debug(sys.inspect(ex));
|
||||||
|
sys.debug(JSON.stringify(ex));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function time_it(name, cont) {
|
||||||
|
if (!options.verbose)
|
||||||
|
return cont();
|
||||||
|
var t1 = new Date().getTime();
|
||||||
|
try { return cont(); }
|
||||||
|
finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
|
||||||
|
};
|
75
node_modules/uglify-js/docstyle.css
generated
vendored
Normal file
75
node_modules/uglify-js/docstyle.css
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
html { font-family: "Lucida Grande","Trebuchet MS",sans-serif; font-size: 12pt; }
|
||||||
|
body { max-width: 60em; }
|
||||||
|
.title { text-align: center; }
|
||||||
|
.todo { color: red; }
|
||||||
|
.done { color: green; }
|
||||||
|
.tag { background-color:lightblue; font-weight:normal }
|
||||||
|
.target { }
|
||||||
|
.timestamp { color: grey }
|
||||||
|
.timestamp-kwd { color: CadetBlue }
|
||||||
|
p.verse { margin-left: 3% }
|
||||||
|
pre {
|
||||||
|
border: 1pt solid #AEBDCC;
|
||||||
|
background-color: #F3F5F7;
|
||||||
|
padding: 5pt;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 90%;
|
||||||
|
overflow:auto;
|
||||||
|
}
|
||||||
|
pre.src {
|
||||||
|
background-color: #eee; color: #112; border: 1px solid #000;
|
||||||
|
}
|
||||||
|
table { border-collapse: collapse; }
|
||||||
|
td, th { vertical-align: top; }
|
||||||
|
dt { font-weight: bold; }
|
||||||
|
div.figure { padding: 0.5em; }
|
||||||
|
div.figure p { text-align: center; }
|
||||||
|
.linenr { font-size:smaller }
|
||||||
|
.code-highlighted {background-color:#ffff00;}
|
||||||
|
.org-info-js_info-navigation { border-style:none; }
|
||||||
|
#org-info-js_console-label { font-size:10px; font-weight:bold;
|
||||||
|
white-space:nowrap; }
|
||||||
|
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
|
||||||
|
font-weight:bold; }
|
||||||
|
|
||||||
|
sup {
|
||||||
|
vertical-align: baseline;
|
||||||
|
position: relative;
|
||||||
|
top: -0.5em;
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
|
sup a:link, sup a:visited {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #c00;
|
||||||
|
}
|
||||||
|
|
||||||
|
sup a:before { content: "["; color: #999; }
|
||||||
|
sup a:after { content: "]"; color: #999; }
|
||||||
|
|
||||||
|
h1.title { border-bottom: 4px solid #000; padding-bottom: 5px; margin-bottom: 2em; }
|
||||||
|
|
||||||
|
#postamble {
|
||||||
|
color: #777;
|
||||||
|
font-size: 90%;
|
||||||
|
padding-top: 1em; padding-bottom: 1em; border-top: 1px solid #999;
|
||||||
|
margin-top: 2em;
|
||||||
|
padding-left: 2em;
|
||||||
|
padding-right: 2em;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
#postamble p { margin: 0; }
|
||||||
|
|
||||||
|
#footnotes { border-top: 1px solid #000; }
|
||||||
|
|
||||||
|
h1 { font-size: 200% }
|
||||||
|
h2 { font-size: 175% }
|
||||||
|
h3 { font-size: 150% }
|
||||||
|
h4 { font-size: 125% }
|
||||||
|
|
||||||
|
h1, h2, h3, h4 { font-family: "Bookman",Georgia,"Times New Roman",serif; font-weight: normal; }
|
||||||
|
|
||||||
|
@media print {
|
||||||
|
html { font-size: 11pt; }
|
||||||
|
}
|
75
node_modules/uglify-js/lib/object-ast.js
generated
vendored
Normal file
75
node_modules/uglify-js/lib/object-ast.js
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
var jsp = require("./parse-js"),
|
||||||
|
pro = require("./process");
|
||||||
|
|
||||||
|
var BY_TYPE = {};
|
||||||
|
|
||||||
|
function HOP(obj, prop) {
|
||||||
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||||
|
};
|
||||||
|
|
||||||
|
function AST_Node(parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
AST_Node.prototype.init = function(){};
|
||||||
|
|
||||||
|
function DEFINE_NODE_CLASS(type, props, methods) {
|
||||||
|
var base = methods && methods.BASE || AST_Node;
|
||||||
|
if (!base) base = AST_Node;
|
||||||
|
function D(parent, data) {
|
||||||
|
base.apply(this, arguments);
|
||||||
|
if (props) props.forEach(function(name, i){
|
||||||
|
this["_" + name] = data[i];
|
||||||
|
});
|
||||||
|
this.init();
|
||||||
|
};
|
||||||
|
var P = D.prototype = new AST_Node;
|
||||||
|
P.node_type = function(){ return type };
|
||||||
|
if (props) props.forEach(function(name){
|
||||||
|
var propname = "_" + name;
|
||||||
|
P["set_" + name] = function(val) {
|
||||||
|
this[propname] = val;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
P["get_" + name] = function() {
|
||||||
|
return this[propname];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
if (type != null) BY_TYPE[type] = D;
|
||||||
|
if (methods) for (var i in methods) if (HOP(methods, i)) {
|
||||||
|
P[i] = methods[i];
|
||||||
|
}
|
||||||
|
return D;
|
||||||
|
};
|
||||||
|
|
||||||
|
var AST_String_Node = DEFINE_NODE_CLASS("string", ["value"]);
|
||||||
|
var AST_Number_Node = DEFINE_NODE_CLASS("num", ["value"]);
|
||||||
|
var AST_Name_Node = DEFINE_NODE_CLASS("name", ["value"]);
|
||||||
|
|
||||||
|
var AST_Statlist_Node = DEFINE_NODE_CLASS(null, ["body"]);
|
||||||
|
var AST_Root_Node = DEFINE_NODE_CLASS("toplevel", null, { BASE: AST_Statlist_Node });
|
||||||
|
var AST_Block_Node = DEFINE_NODE_CLASS("block", null, { BASE: AST_Statlist_Node });
|
||||||
|
var AST_Splice_Node = DEFINE_NODE_CLASS("splice", null, { BASE: AST_Statlist_Node });
|
||||||
|
|
||||||
|
var AST_Var_Node = DEFINE_NODE_CLASS("var", ["definitions"]);
|
||||||
|
var AST_Const_Node = DEFINE_NODE_CLASS("const", ["definitions"]);
|
||||||
|
|
||||||
|
var AST_Try_Node = DEFINE_NODE_CLASS("try", ["body", "catch", "finally"]);
|
||||||
|
var AST_Throw_Node = DEFINE_NODE_CLASS("throw", ["exception"]);
|
||||||
|
|
||||||
|
var AST_New_Node = DEFINE_NODE_CLASS("new", ["constructor", "arguments"]);
|
||||||
|
|
||||||
|
var AST_Switch_Node = DEFINE_NODE_CLASS("switch", ["expression", "branches"]);
|
||||||
|
var AST_Switch_Branch_Node = DEFINE_NODE_CLASS(null, ["expression", "body"]);
|
||||||
|
|
||||||
|
var AST_Break_Node = DEFINE_NODE_CLASS("break", ["label"]);
|
||||||
|
var AST_Continue_Node = DEFINE_NODE_CLASS("continue", ["label"]);
|
||||||
|
var AST_Assign_Node = DEFINE_NODE_CLASS("assign", ["operator", "lvalue", "rvalue"]);
|
||||||
|
var AST_Dot_Node = DEFINE_NODE_CLASS("dot", ["expression", "name"]);
|
||||||
|
var AST_Call_Node = DEFINE_NODE_CLASS("call", ["function", "arguments"]);
|
||||||
|
|
||||||
|
var AST_Lambda_Node = DEFINE_NODE_CLASS(null, ["name", "arguments", "body"])
|
||||||
|
var AST_Function_Node = DEFINE_NODE_CLASS("function", null, AST_Lambda_Node);
|
||||||
|
var AST_Defun_Node = DEFINE_NODE_CLASS("defun", null, AST_Lambda_Node);
|
||||||
|
|
||||||
|
var AST_If_Node = DEFINE_NODE_CLASS("if", ["condition", "then", "else"]);
|
1339
node_modules/uglify-js/lib/parse-js.js
generated
vendored
Normal file
1339
node_modules/uglify-js/lib/parse-js.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2002
node_modules/uglify-js/lib/process.js
generated
vendored
Normal file
2002
node_modules/uglify-js/lib/process.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
69
node_modules/uglify-js/lib/squeeze-more.js
generated
vendored
Normal file
69
node_modules/uglify-js/lib/squeeze-more.js
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
var jsp = require("./parse-js"),
|
||||||
|
pro = require("./process"),
|
||||||
|
slice = jsp.slice,
|
||||||
|
member = jsp.member,
|
||||||
|
curry = jsp.curry,
|
||||||
|
MAP = pro.MAP,
|
||||||
|
PRECEDENCE = jsp.PRECEDENCE,
|
||||||
|
OPERATORS = jsp.OPERATORS;
|
||||||
|
|
||||||
|
function ast_squeeze_more(ast) {
|
||||||
|
var w = pro.ast_walker(), walk = w.walk, scope;
|
||||||
|
function with_scope(s, cont) {
|
||||||
|
var save = scope, ret;
|
||||||
|
scope = s;
|
||||||
|
ret = cont();
|
||||||
|
scope = save;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
function _lambda(name, args, body) {
|
||||||
|
return [ this[0], name, args, with_scope(body.scope, curry(MAP, body, walk)) ];
|
||||||
|
};
|
||||||
|
return w.with_walkers({
|
||||||
|
"toplevel": function(body) {
|
||||||
|
return [ this[0], with_scope(this.scope, curry(MAP, body, walk)) ];
|
||||||
|
},
|
||||||
|
"function": _lambda,
|
||||||
|
"defun": _lambda,
|
||||||
|
"new": function(ctor, args) {
|
||||||
|
if (ctor[0] == "name") {
|
||||||
|
if (ctor[1] == "Array" && !scope.has("Array")) {
|
||||||
|
if (args.length != 1) {
|
||||||
|
return [ "array", args ];
|
||||||
|
} else {
|
||||||
|
return walk([ "call", [ "name", "Array" ], args ]);
|
||||||
|
}
|
||||||
|
} else if (ctor[1] == "Object" && !scope.has("Object")) {
|
||||||
|
if (!args.length) {
|
||||||
|
return [ "object", [] ];
|
||||||
|
} else {
|
||||||
|
return walk([ "call", [ "name", "Object" ], args ]);
|
||||||
|
}
|
||||||
|
} else if ((ctor[1] == "RegExp" || ctor[1] == "Function" || ctor[1] == "Error") && !scope.has(ctor[1])) {
|
||||||
|
return walk([ "call", [ "name", ctor[1] ], args]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"call": function(expr, args) {
|
||||||
|
if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
|
||||||
|
// foo.toString() ==> foo+""
|
||||||
|
return [ "binary", "+", expr[1], [ "string", "" ]];
|
||||||
|
}
|
||||||
|
if (expr[0] == "name") {
|
||||||
|
if (expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
|
||||||
|
return [ "array", args ];
|
||||||
|
}
|
||||||
|
if (expr[1] == "Object" && !args.length && !scope.has("Object")) {
|
||||||
|
return [ "object", [] ];
|
||||||
|
}
|
||||||
|
if (expr[1] == "String" && !scope.has("String")) {
|
||||||
|
return [ "binary", "+", args[0], [ "string", "" ]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, function() {
|
||||||
|
return walk(pro.ast_add_scope(ast));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.ast_squeeze_more = ast_squeeze_more;
|
24
node_modules/uglify-js/package.json
generated
vendored
Normal file
24
node_modules/uglify-js/package.json
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name" : "uglify-js",
|
||||||
|
|
||||||
|
"description" : "JavaScript parser and compressor/beautifier toolkit",
|
||||||
|
|
||||||
|
"author" : {
|
||||||
|
"name" : "Mihai Bazon",
|
||||||
|
"email" : "mihai.bazon@gmail.com",
|
||||||
|
"url" : "http://mihai.bazon.net/blog"
|
||||||
|
},
|
||||||
|
|
||||||
|
"version" : "1.2.2",
|
||||||
|
|
||||||
|
"main" : "./uglify-js.js",
|
||||||
|
|
||||||
|
"bin" : {
|
||||||
|
"uglifyjs" : "./bin/uglifyjs"
|
||||||
|
},
|
||||||
|
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@github.com:mishoo/UglifyJS.git"
|
||||||
|
}
|
||||||
|
}
|
28
node_modules/uglify-js/test/beautify.js
generated
vendored
Executable file
28
node_modules/uglify-js/test/beautify.js
generated
vendored
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
|
||||||
|
global.sys = require("sys");
|
||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
|
var jsp = require("../lib/parse-js");
|
||||||
|
var pro = require("../lib/process");
|
||||||
|
|
||||||
|
var filename = process.argv[2];
|
||||||
|
fs.readFile(filename, "utf8", function(err, text){
|
||||||
|
try {
|
||||||
|
var ast = time_it("parse", function(){ return jsp.parse(text); });
|
||||||
|
ast = time_it("mangle", function(){ return pro.ast_mangle(ast); });
|
||||||
|
ast = time_it("squeeze", function(){ return pro.ast_squeeze(ast); });
|
||||||
|
var gen = time_it("generate", function(){ return pro.gen_code(ast, false); });
|
||||||
|
sys.puts(gen);
|
||||||
|
} catch(ex) {
|
||||||
|
sys.debug(ex.stack);
|
||||||
|
sys.debug(sys.inspect(ex));
|
||||||
|
sys.debug(JSON.stringify(ex));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function time_it(name, cont) {
|
||||||
|
var t1 = new Date().getTime();
|
||||||
|
try { return cont(); }
|
||||||
|
finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
|
||||||
|
};
|
403
node_modules/uglify-js/test/testparser.js
generated
vendored
Executable file
403
node_modules/uglify-js/test/testparser.js
generated
vendored
Executable file
@ -0,0 +1,403 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
|
||||||
|
var parseJS = require("../lib/parse-js");
|
||||||
|
var sys = require("sys");
|
||||||
|
|
||||||
|
// write debug in a very straightforward manner
|
||||||
|
var debug = function(){
|
||||||
|
sys.log(Array.prototype.slice.call(arguments).join(', '));
|
||||||
|
};
|
||||||
|
|
||||||
|
ParserTestSuite(function(i, input, desc){
|
||||||
|
try {
|
||||||
|
parseJS.parse(input);
|
||||||
|
debug("ok " + i + ": " + desc);
|
||||||
|
} catch(e){
|
||||||
|
debug("FAIL " + i + " " + desc + " (" + e + ")");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function ParserTestSuite(callback){
|
||||||
|
var inps = [
|
||||||
|
["var abc;", "Regular variable statement w/o assignment"],
|
||||||
|
["var abc = 5;", "Regular variable statement with assignment"],
|
||||||
|
["/* */;", "Multiline comment"],
|
||||||
|
['/** **/;', 'Double star multiline comment'],
|
||||||
|
["var f = function(){;};", "Function expression in var assignment"],
|
||||||
|
['hi; // moo\n;', 'single line comment'],
|
||||||
|
['var varwithfunction;', 'Dont match keywords as substrings'], // difference between `var withsomevar` and `"str"` (local search and lits)
|
||||||
|
['a + b;', 'addition'],
|
||||||
|
["'a';", 'single string literal'],
|
||||||
|
["'a\\n';", 'single string literal with escaped return'],
|
||||||
|
['"a";', 'double string literal'],
|
||||||
|
['"a\\n";', 'double string literal with escaped return'],
|
||||||
|
['"var";', 'string is a keyword'],
|
||||||
|
['"variable";', 'string starts with a keyword'],
|
||||||
|
['"somevariable";', 'string contains a keyword'],
|
||||||
|
['"somevar";', 'string ends with a keyword'],
|
||||||
|
['500;', 'int literal'],
|
||||||
|
['500.;', 'float literal w/o decimals'],
|
||||||
|
['500.432;', 'float literal with decimals'],
|
||||||
|
['.432432;', 'float literal w/o int'],
|
||||||
|
['(a,b,c);', 'parens and comma'],
|
||||||
|
['[1,2,abc];', 'array literal'],
|
||||||
|
['var o = {a:1};', 'object literal unquoted key'],
|
||||||
|
['var o = {"b":2};', 'object literal quoted key'], // opening curly may not be at the start of a statement...
|
||||||
|
['var o = {c:c};', 'object literal keyname is identifier'],
|
||||||
|
['var o = {a:1,"b":2,c:c};', 'object literal combinations'],
|
||||||
|
['var x;\nvar y;', 'two lines'],
|
||||||
|
['var x;\nfunction n(){; }', 'function def'],
|
||||||
|
['var x;\nfunction n(abc){; }', 'function def with arg'],
|
||||||
|
['var x;\nfunction n(abc, def){ ;}', 'function def with args'],
|
||||||
|
['function n(){ "hello"; }', 'function def with body'],
|
||||||
|
['/a/;', 'regex literal'],
|
||||||
|
['/a/b;', 'regex literal with flag'],
|
||||||
|
['/a/ / /b/;', 'regex div regex'],
|
||||||
|
['a/b/c;', 'triple division looks like regex'],
|
||||||
|
['+function(){/regex/;};', 'regex at start of function body'],
|
||||||
|
// http://code.google.com/p/es-lab/source/browse/trunk/tests/parser/parsertests.js?r=86
|
||||||
|
// http://code.google.com/p/es-lab/source/browse/trunk/tests/parser/parsertests.js?r=430
|
||||||
|
|
||||||
|
// first tests for the lexer, should also parse as program (when you append a semi)
|
||||||
|
|
||||||
|
// comments
|
||||||
|
['//foo!@#^&$1234\nbar;', 'single line comment'],
|
||||||
|
['/* abcd!@#@$* { } && null*/;', 'single line multi line comment'],
|
||||||
|
['/*foo\nbar*/;','multi line comment'],
|
||||||
|
['/*x*x*/;','multi line comment with *'],
|
||||||
|
['/**/;','empty comment'],
|
||||||
|
// identifiers
|
||||||
|
["x;",'1 identifier'],
|
||||||
|
["_x;",'2 identifier'],
|
||||||
|
["xyz;",'3 identifier'],
|
||||||
|
["$x;",'4 identifier'],
|
||||||
|
["x$;",'5 identifier'],
|
||||||
|
["_;",'6 identifier'],
|
||||||
|
["x5;",'7 identifier'],
|
||||||
|
["x_y;",'8 identifier'],
|
||||||
|
["x+5;",'9 identifier'],
|
||||||
|
["xyz123;",'10 identifier'],
|
||||||
|
["x1y1z1;",'11 identifier'],
|
||||||
|
["foo\\u00D8bar;",'12 identifier unicode escape'],
|
||||||
|
//["foo<6F>bar;",'13 identifier unicode embedded (might fail)'],
|
||||||
|
// numbers
|
||||||
|
["5;", '1 number'],
|
||||||
|
["5.5;", '2 number'],
|
||||||
|
["0;", '3 number'],
|
||||||
|
["0.0;", '4 number'],
|
||||||
|
["0.001;", '5 number'],
|
||||||
|
["1.e2;", '6 number'],
|
||||||
|
["1.e-2;", '7 number'],
|
||||||
|
["1.E2;", '8 number'],
|
||||||
|
["1.E-2;", '9 number'],
|
||||||
|
[".5;", '10 number'],
|
||||||
|
[".5e3;", '11 number'],
|
||||||
|
[".5e-3;", '12 number'],
|
||||||
|
["0.5e3;", '13 number'],
|
||||||
|
["55;", '14 number'],
|
||||||
|
["123;", '15 number'],
|
||||||
|
["55.55;", '16 number'],
|
||||||
|
["55.55e10;", '17 number'],
|
||||||
|
["123.456;", '18 number'],
|
||||||
|
["1+e;", '20 number'],
|
||||||
|
["0x01;", '22 number'],
|
||||||
|
["0XCAFE;", '23 number'],
|
||||||
|
["0x12345678;", '24 number'],
|
||||||
|
["0x1234ABCD;", '25 number'],
|
||||||
|
["0x0001;", '26 number'],
|
||||||
|
// strings
|
||||||
|
["\"foo\";", '1 string'],
|
||||||
|
["\'foo\';", '2 string'],
|
||||||
|
["\"x\";", '3 string'],
|
||||||
|
["\'\';", '4 string'],
|
||||||
|
["\"foo\\tbar\";", '5 string'],
|
||||||
|
["\"!@#$%^&*()_+{}[]\";", '6 string'],
|
||||||
|
["\"/*test*/\";", '7 string'],
|
||||||
|
["\"//test\";", '8 string'],
|
||||||
|
["\"\\\\\";", '9 string'],
|
||||||
|
["\"\\u0001\";", '10 string'],
|
||||||
|
["\"\\uFEFF\";", '11 string'],
|
||||||
|
["\"\\u10002\";", '12 string'],
|
||||||
|
["\"\\x55\";", '13 string'],
|
||||||
|
["\"\\x55a\";", '14 string'],
|
||||||
|
["\"a\\\\nb\";", '15 string'],
|
||||||
|
['";"', '16 string: semi in a string'],
|
||||||
|
['"a\\\nb";', '17 string: line terminator escape'],
|
||||||
|
// literals
|
||||||
|
["null;", "null"],
|
||||||
|
["true;", "true"],
|
||||||
|
["false;", "false"],
|
||||||
|
// regex
|
||||||
|
["/a/;", "1 regex"],
|
||||||
|
["/abc/;", "2 regex"],
|
||||||
|
["/abc[a-z]*def/g;", "3 regex"],
|
||||||
|
["/\\b/;", "4 regex"],
|
||||||
|
["/[a-zA-Z]/;", "5 regex"],
|
||||||
|
|
||||||
|
// program tests (for as far as they havent been covered above)
|
||||||
|
|
||||||
|
// regexp
|
||||||
|
["/foo(.*)/g;", "another regexp"],
|
||||||
|
// arrays
|
||||||
|
["[];", "1 array"],
|
||||||
|
["[ ];", "2 array"],
|
||||||
|
["[1];", "3 array"],
|
||||||
|
["[1,2];", "4 array"],
|
||||||
|
["[1,2,,];", "5 array"],
|
||||||
|
["[1,2,3];", "6 array"],
|
||||||
|
["[1,2,3,,,];", "7 array"],
|
||||||
|
// objects
|
||||||
|
["{};", "1 object"],
|
||||||
|
["({x:5});", "2 object"],
|
||||||
|
["({x:5,y:6});", "3 object"],
|
||||||
|
["({x:5,});", "4 object"],
|
||||||
|
["({if:5});", "5 object"],
|
||||||
|
["({ get x() {42;} });", "6 object"],
|
||||||
|
["({ set y(a) {1;} });", "7 object"],
|
||||||
|
// member expression
|
||||||
|
["o.m;", "1 member expression"],
|
||||||
|
["o['m'];", "2 member expression"],
|
||||||
|
["o['n']['m'];", "3 member expression"],
|
||||||
|
["o.n.m;", "4 member expression"],
|
||||||
|
["o.if;", "5 member expression"],
|
||||||
|
// call and invoke expressions
|
||||||
|
["f();", "1 call/invoke expression"],
|
||||||
|
["f(x);", "2 call/invoke expression"],
|
||||||
|
["f(x,y);", "3 call/invoke expression"],
|
||||||
|
["o.m();", "4 call/invoke expression"],
|
||||||
|
["o['m'];", "5 call/invoke expression"],
|
||||||
|
["o.m(x);", "6 call/invoke expression"],
|
||||||
|
["o['m'](x);", "7 call/invoke expression"],
|
||||||
|
["o.m(x,y);", "8 call/invoke expression"],
|
||||||
|
["o['m'](x,y);", "9 call/invoke expression"],
|
||||||
|
["f(x)(y);", "10 call/invoke expression"],
|
||||||
|
["f().x;", "11 call/invoke expression"],
|
||||||
|
|
||||||
|
// eval
|
||||||
|
["eval('x');", "1 eval"],
|
||||||
|
["(eval)('x');", "2 eval"],
|
||||||
|
["(1,eval)('x');", "3 eval"],
|
||||||
|
["eval(x,y);", "4 eval"],
|
||||||
|
// new expression
|
||||||
|
["new f();", "1 new expression"],
|
||||||
|
["new o;", "2 new expression"],
|
||||||
|
["new o.m;", "3 new expression"],
|
||||||
|
["new o.m(x);", "4 new expression"],
|
||||||
|
["new o.m(x,y);", "5 new expression"],
|
||||||
|
// prefix/postfix
|
||||||
|
["++x;", "1 pre/postfix"],
|
||||||
|
["x++;", "2 pre/postfix"],
|
||||||
|
["--x;", "3 pre/postfix"],
|
||||||
|
["x--;", "4 pre/postfix"],
|
||||||
|
["x ++;", "5 pre/postfix"],
|
||||||
|
["x /* comment */ ++;", "6 pre/postfix"],
|
||||||
|
["++ /* comment */ x;", "7 pre/postfix"],
|
||||||
|
// unary operators
|
||||||
|
["delete x;", "1 unary operator"],
|
||||||
|
["void x;", "2 unary operator"],
|
||||||
|
["+ x;", "3 unary operator"],
|
||||||
|
["-x;", "4 unary operator"],
|
||||||
|
["~x;", "5 unary operator"],
|
||||||
|
["!x;", "6 unary operator"],
|
||||||
|
// meh
|
||||||
|
["new Date++;", "new date ++"],
|
||||||
|
["+x++;", " + x ++"],
|
||||||
|
// expression expressions
|
||||||
|
["1 * 2;", "1 expression expressions"],
|
||||||
|
["1 / 2;", "2 expression expressions"],
|
||||||
|
["1 % 2;", "3 expression expressions"],
|
||||||
|
["1 + 2;", "4 expression expressions"],
|
||||||
|
["1 - 2;", "5 expression expressions"],
|
||||||
|
["1 << 2;", "6 expression expressions"],
|
||||||
|
["1 >>> 2;", "7 expression expressions"],
|
||||||
|
["1 >> 2;", "8 expression expressions"],
|
||||||
|
["1 * 2 + 3;", "9 expression expressions"],
|
||||||
|
["(1+2)*3;", "10 expression expressions"],
|
||||||
|
["1*(2+3);", "11 expression expressions"],
|
||||||
|
["x<y;", "12 expression expressions"],
|
||||||
|
["x>y;", "13 expression expressions"],
|
||||||
|
["x<=y;", "14 expression expressions"],
|
||||||
|
["x>=y;", "15 expression expressions"],
|
||||||
|
["x instanceof y;", "16 expression expressions"],
|
||||||
|
["x in y;", "17 expression expressions"],
|
||||||
|
["x&y;", "18 expression expressions"],
|
||||||
|
["x^y;", "19 expression expressions"],
|
||||||
|
["x|y;", "20 expression expressions"],
|
||||||
|
["x+y<z;", "21 expression expressions"],
|
||||||
|
["x<y+z;", "22 expression expressions"],
|
||||||
|
["x+y+z;", "23 expression expressions"],
|
||||||
|
["x+y<z;", "24 expression expressions"],
|
||||||
|
["x<y+z;", "25 expression expressions"],
|
||||||
|
["x&y|z;", "26 expression expressions"],
|
||||||
|
["x&&y;", "27 expression expressions"],
|
||||||
|
["x||y;", "28 expression expressions"],
|
||||||
|
["x&&y||z;", "29 expression expressions"],
|
||||||
|
["x||y&&z;", "30 expression expressions"],
|
||||||
|
["x<y?z:w;", "31 expression expressions"],
|
||||||
|
// assignment
|
||||||
|
["x >>>= y;", "1 assignment"],
|
||||||
|
["x <<= y;", "2 assignment"],
|
||||||
|
["x = y;", "3 assignment"],
|
||||||
|
["x += y;", "4 assignment"],
|
||||||
|
["x /= y;", "5 assignment"],
|
||||||
|
// comma
|
||||||
|
["x, y;", "comma"],
|
||||||
|
// block
|
||||||
|
["{};", "1 block"],
|
||||||
|
["{x;};", "2 block"],
|
||||||
|
["{x;y;};", "3 block"],
|
||||||
|
// vars
|
||||||
|
["var x;", "1 var"],
|
||||||
|
["var x,y;", "2 var"],
|
||||||
|
["var x=1,y=2;", "3 var"],
|
||||||
|
["var x,y=2;", "4 var"],
|
||||||
|
// empty
|
||||||
|
[";", "1 empty"],
|
||||||
|
["\n;", "2 empty"],
|
||||||
|
// expression statement
|
||||||
|
["x;", "1 expression statement"],
|
||||||
|
["5;", "2 expression statement"],
|
||||||
|
["1+2;", "3 expression statement"],
|
||||||
|
// if
|
||||||
|
["if (c) x; else y;", "1 if statement"],
|
||||||
|
["if (c) x;", "2 if statement"],
|
||||||
|
["if (c) {} else {};", "3 if statement"],
|
||||||
|
["if (c1) if (c2) s1; else s2;", "4 if statement"],
|
||||||
|
// while
|
||||||
|
["do s; while (e);", "1 while statement"],
|
||||||
|
["do { s; } while (e);", "2 while statement"],
|
||||||
|
["while (e) s;", "3 while statement"],
|
||||||
|
["while (e) { s; };", "4 while statement"],
|
||||||
|
// for
|
||||||
|
["for (;;) ;", "1 for statement"],
|
||||||
|
["for (;c;x++) x;", "2 for statement"],
|
||||||
|
["for (i;i<len;++i){};", "3 for statement"],
|
||||||
|
["for (var i=0;i<len;++i) {};", "4 for statement"],
|
||||||
|
["for (var i=0,j=0;;){};", "5 for statement"],
|
||||||
|
//["for (x in b; c; u) {};", "6 for statement"],
|
||||||
|
["for ((x in b); c; u) {};", "7 for statement"],
|
||||||
|
["for (x in a);", "8 for statement"],
|
||||||
|
["for (var x in a){};", "9 for statement"],
|
||||||
|
["for (var x=5 in a) {};", "10 for statement"],
|
||||||
|
["for (var x = a in b in c) {};", "11 for statement"],
|
||||||
|
["for (var x=function(){a+b;}; a<b; ++i) some;", "11 for statement, testing for parsingForHeader reset with the function"],
|
||||||
|
["for (var x=function(){for (x=0; x<15; ++x) alert(foo); }; a<b; ++i) some;", "11 for statement, testing for parsingForHeader reset with the function"],
|
||||||
|
// flow statements
|
||||||
|
["while(1){ continue; }", "1 flow statement"],
|
||||||
|
["label: while(1){ continue label; }", "2 flow statement"],
|
||||||
|
["while(1){ break; }", "3 flow statement"],
|
||||||
|
["somewhere: while(1){ break somewhere; }", "4 flow statement"],
|
||||||
|
["while(1){ continue /* comment */ ; }", "5 flow statement"],
|
||||||
|
["while(1){ continue \n; }", "6 flow statement"],
|
||||||
|
["(function(){ return; })()", "7 flow statement"],
|
||||||
|
["(function(){ return 0; })()", "8 flow statement"],
|
||||||
|
["(function(){ return 0 + \n 1; })()", "9 flow statement"],
|
||||||
|
// with
|
||||||
|
["with (e) s;", "with statement"],
|
||||||
|
// switch
|
||||||
|
["switch (e) { case x: s; };", "1 switch statement"],
|
||||||
|
["switch (e) { case x: s1;s2; default: s3; case y: s4; };", "2 switch statement"],
|
||||||
|
["switch (e) { default: s1; case x: s2; case y: s3; };", "3 switch statement"],
|
||||||
|
["switch (e) { default: s; };", "4 switch statement"],
|
||||||
|
["switch (e) { case x: s1; case y: s2; };", "5 switch statement"],
|
||||||
|
// labels
|
||||||
|
["foo : x;", " flow statement"],
|
||||||
|
// throw
|
||||||
|
["throw x;", "1 throw statement"],
|
||||||
|
["throw x\n;", "2 throw statement"],
|
||||||
|
// try catch finally
|
||||||
|
["try { s1; } catch (e) { s2; };", "1 trycatchfinally statement"],
|
||||||
|
["try { s1; } finally { s2; };", "2 trycatchfinally statement"],
|
||||||
|
["try { s1; } catch (e) { s2; } finally { s3; };", "3 trycatchfinally statement"],
|
||||||
|
// debugger
|
||||||
|
["debugger;", "debuger statement"],
|
||||||
|
// function decl
|
||||||
|
["function f(x) { e; return x; };", "1 function declaration"],
|
||||||
|
["function f() { x; y; };", "2 function declaration"],
|
||||||
|
["function f(x,y) { var z; return x; };", "3 function declaration"],
|
||||||
|
// function exp
|
||||||
|
["(function f(x) { return x; });", "1 function expression"],
|
||||||
|
["(function empty() {;});", "2 function expression"],
|
||||||
|
["(function empty() {;});", "3 function expression"],
|
||||||
|
["(function (x) {; });", "4 function expression"],
|
||||||
|
// program
|
||||||
|
["var x; function f(){;}; null;", "1 program"],
|
||||||
|
[";;", "2 program"],
|
||||||
|
["{ x; y; z; }", "3 program"],
|
||||||
|
["function f(){ function g(){;}};", "4 program"],
|
||||||
|
["x;\n/*foo*/\n ;", "5 program"],
|
||||||
|
|
||||||
|
// asi
|
||||||
|
["foo: while(1){ continue \n foo; }", "1 asi"],
|
||||||
|
["foo: while(1){ break \n foo; }", "2 asi"],
|
||||||
|
["(function(){ return\nfoo; })()", "3 asi"],
|
||||||
|
["var x; { 1 \n 2 } 3", "4 asi"],
|
||||||
|
["ab /* hi */\ncd", "5 asi"],
|
||||||
|
["ab/*\n*/cd", "6 asi (multi line multilinecomment counts as eol)"],
|
||||||
|
["foo: while(1){ continue /* wtf \n busta */ foo; }", "7 asi illegal with multi line comment"],
|
||||||
|
["function f() { s }", "8 asi"],
|
||||||
|
["function f() { return }", "9 asi"],
|
||||||
|
|
||||||
|
// use strict
|
||||||
|
// XXX: some of these should actually fail?
|
||||||
|
// no support for "use strict" yet...
|
||||||
|
['"use strict"; \'bla\'\n; foo;', "1 directive"],
|
||||||
|
['(function() { "use strict"; \'bla\';\n foo; });', "2 directive"],
|
||||||
|
['"use\\n strict";', "3 directive"],
|
||||||
|
['foo; "use strict";', "4 directive"],
|
||||||
|
|
||||||
|
// tests from http://es5conform.codeplex.com/
|
||||||
|
|
||||||
|
['"use strict"; var o = { eval: 42};', "8.7.2-3-1-s: the use of eval as property name is allowed"],
|
||||||
|
['({foo:0,foo:1});', 'Duplicate property name allowed in not strict mode'],
|
||||||
|
['function foo(a,a){}', 'Duplicate parameter name allowed in not strict mode'],
|
||||||
|
['(function foo(eval){})', 'Eval allowed as parameter name in non strict mode'],
|
||||||
|
['(function foo(arguments){})', 'Arguments allowed as parameter name in non strict mode'],
|
||||||
|
|
||||||
|
// empty programs
|
||||||
|
|
||||||
|
['', '1 Empty program'],
|
||||||
|
['// test', '2 Empty program'],
|
||||||
|
['//test\n', '3 Empty program'],
|
||||||
|
['\n// test', '4 Empty program'],
|
||||||
|
['\n// test\n', '5 Empty program'],
|
||||||
|
['/* */', '6 Empty program'],
|
||||||
|
['/*\ns,fd\n*/', '7 Empty program'],
|
||||||
|
['/*\ns,fd\n*/\n', '8 Empty program'],
|
||||||
|
[' ', '9 Empty program'],
|
||||||
|
[' /*\nsmeh*/ \n ', '10 Empty program'],
|
||||||
|
|
||||||
|
// trailing whitespace
|
||||||
|
|
||||||
|
['a ', '1 Trailing whitespace'],
|
||||||
|
['a /* something */', '2 Trailing whitespace'],
|
||||||
|
['a\n // hah', '3 Trailing whitespace'],
|
||||||
|
['/abc/de//f', '4 Trailing whitespace'],
|
||||||
|
['/abc/de/*f*/\n ', '5 Trailing whitespace'],
|
||||||
|
|
||||||
|
// things the parser tripped over at one point or the other (prevents regression bugs)
|
||||||
|
['for (x;function(){ a\nb };z) x;', 'for header with function body forcing ASI'],
|
||||||
|
['c=function(){return;return};', 'resetting noAsi after literal'],
|
||||||
|
['d\nd()', 'asi exception causing token overflow'],
|
||||||
|
['for(;;){x=function(){}}', 'function expression in a for header'],
|
||||||
|
['for(var k;;){}', 'parser failing due to ASI accepting the incorrect "for" rule'],
|
||||||
|
['({get foo(){ }})', 'getter with empty function body'],
|
||||||
|
['\nreturnr', 'eol causes return statement to ignore local search requirement'],
|
||||||
|
[' / /', '1 whitespace before regex causes regex to fail?'],
|
||||||
|
['/ // / /', '2 whitespace before regex causes regex to fail?'],
|
||||||
|
['/ / / / /', '3 whitespace before regex causes regex to fail?'],
|
||||||
|
|
||||||
|
['\n\t// Used for trimming whitespace\n\ttrimLeft = /^\\s+/;\n\ttrimRight = /\\s+$/;\t\n','turned out this didnt crash (the test below did), but whatever.'],
|
||||||
|
['/[\\/]/;', 'escaped forward slash inside class group (would choke on fwd slash)'],
|
||||||
|
['/[/]/;', 'also broke but is valid in es5 (not es3)'],
|
||||||
|
['({get:5});','get property name thats not a getter'],
|
||||||
|
['({set:5});','set property name thats not a setter'],
|
||||||
|
['l !== "px" && (d.style(h, c, (k || 1) + l), j = (k || 1) / f.cur() * j, d.style(h, c, j + l)), i[1] && (k = (i[1] === "-=" ? -1 : 1) * k + j), f.custom(j, k, l)', 'this choked regex/div at some point'],
|
||||||
|
['(/\'/g, \'\\\\\\\'\') + "\'";', 'the sequence of escaped characters confused the tokenizer'],
|
||||||
|
['if (true) /=a/.test("a");', 'regexp starting with "=" in not obvious context (not implied by preceding token)']
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var i=0; i<inps.length; ++i) {
|
||||||
|
callback(i, inps[i][0], inps[i][1]);
|
||||||
|
};
|
||||||
|
};
|
1
node_modules/uglify-js/test/unit/compress/expected/array1.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/array1.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[],Array(1),[1,2,3]
|
1
node_modules/uglify-js/test/unit/compress/expected/array2.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/array2.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(function(){var a=function(){};return new a(1,2,3,4)})()
|
1
node_modules/uglify-js/test/unit/compress/expected/array3.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/array3.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(function(){function a(){}return new a(1,2,3,4)})()
|
1
node_modules/uglify-js/test/unit/compress/expected/array4.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/array4.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(function(){function a(){}(function(){return new a(1,2,3)})()})()
|
1
node_modules/uglify-js/test/unit/compress/expected/assignment.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/assignment.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a=1,b=a,c=1,d=b,e=d,longname=2;if(longname+1){x=3;if(x)var z=7}z=1,y=1,x=1,g+=1,h=g,++i,j=i,i++,j=i+17
|
1
node_modules/uglify-js/test/unit/compress/expected/concatstring.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/concatstring.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=a+"a"+"b"+1+c,b=a+"c"+"ds"+123+c,c=a+"c"+123+d+"ds"+c
|
1
node_modules/uglify-js/test/unit/compress/expected/const.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/const.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=13,b=1/3
|
1
node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function bar(){return--x}function foo(){while(bar());}function mak(){for(;;);}var x=5
|
1
node_modules/uglify-js/test/unit/compress/expected/forstatement.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/forstatement.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a=func(),b=z;for(a++;i<10;i++)alert(i);var z=1;g=2;for(;i<10;i++)alert(i);var a=2;for(var i=1;i<10;i++)alert(i)
|
1
node_modules/uglify-js/test/unit/compress/expected/if.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/if.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=1;a==1?a=2:a=17
|
1
node_modules/uglify-js/test/unit/compress/expected/ifreturn.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/ifreturn.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function a(a){return a==1?2:17}
|
1
node_modules/uglify-js/test/unit/compress/expected/ifreturn2.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/ifreturn2.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function x(a){return typeof a=="object"?a:a===42?0:a*2}function y(a){return typeof a=="object"?a:null}
|
1
node_modules/uglify-js/test/unit/compress/expected/issue10.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue10.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function f(){var a;return(a="a")?a:a}f()
|
1
node_modules/uglify-js/test/unit/compress/expected/issue11.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue11.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
new(A,B),new(A||B),new(X?A:B)
|
1
node_modules/uglify-js/test/unit/compress/expected/issue13.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue13.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=/^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#])(?::(\d))?)?(..?$|(?:[^?#\/]\/))([^?#]*)(?:\?([^#]))?(?:#(.))?/
|
1
node_modules/uglify-js/test/unit/compress/expected/issue14.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue14.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"}
|
1
node_modules/uglify-js/test/unit/compress/expected/issue16.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue16.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=3250441966
|
1
node_modules/uglify-js/test/unit/compress/expected/issue17.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue17.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=function(b){b(),a()}
|
1
node_modules/uglify-js/test/unit/compress/expected/issue20.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue20.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
1
node_modules/uglify-js/test/unit/compress/expected/issue21.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue21.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=0;switch(a){case 0:a++}
|
1
node_modules/uglify-js/test/unit/compress/expected/issue25.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue25.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a:break a;console.log(1)
|
1
node_modules/uglify-js/test/unit/compress/expected/issue27.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue27.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(a?b:c)?d:e
|
1
node_modules/uglify-js/test/unit/compress/expected/issue28.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue28.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
o={".5":.5},o={.5:.5},o={.5:.5}
|
1
node_modules/uglify-js/test/unit/compress/expected/issue29.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue29.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
result=function(){return 1}()
|
1
node_modules/uglify-js/test/unit/compress/expected/issue30.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue30.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=8,b=4,c=4
|
1
node_modules/uglify-js/test/unit/compress/expected/issue34.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue34.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a={};a["this"]=1,a.that=2
|
1
node_modules/uglify-js/test/unit/compress/expected/issue4.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue4.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=2e3,b=.002,c=2e-5
|
1
node_modules/uglify-js/test/unit/compress/expected/issue48.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue48.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var s,i;s="",i=0
|
1
node_modules/uglify-js/test/unit/compress/expected/issue50.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue50.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function bar(a){try{foo()}catch(b){alert("Exception caught (foo not defined)")}alert(a)}bar(10)
|
1
node_modules/uglify-js/test/unit/compress/expected/issue53.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue53.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
x=(y,z)
|
1
node_modules/uglify-js/test/unit/compress/expected/issue54.1.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue54.1.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo+"",a.toString(16),b.toString.call(c)
|
1
node_modules/uglify-js/test/unit/compress/expected/issue68.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue68.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function f(){function b(){}if(a)return;b()}
|
1
node_modules/uglify-js/test/unit/compress/expected/issue69.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue69.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[(a,b)]
|
1
node_modules/uglify-js/test/unit/compress/expected/issue9.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/issue9.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a={a:1,b:2}
|
1
node_modules/uglify-js/test/unit/compress/expected/mangle.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/mangle.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(function(){var a=function b(a,b,c){return b}})()
|
1
node_modules/uglify-js/test/unit/compress/expected/null_string.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/null_string.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var nullString="\0"
|
1
node_modules/uglify-js/test/unit/compress/expected/strict-equals.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/strict-equals.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
typeof a=="string",b+""!=c+"",d<e==f<g
|
1
node_modules/uglify-js/test/unit/compress/expected/var.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/var.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a=1,b=2
|
1
node_modules/uglify-js/test/unit/compress/expected/whitespace.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/whitespace.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function id(a){return a}
|
1
node_modules/uglify-js/test/unit/compress/expected/with.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/expected/with.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
with({});
|
3
node_modules/uglify-js/test/unit/compress/test/array1.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/array1.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
new Array();
|
||||||
|
new Array(1);
|
||||||
|
new Array(1, 2, 3);
|
4
node_modules/uglify-js/test/unit/compress/test/array2.js
generated
vendored
Normal file
4
node_modules/uglify-js/test/unit/compress/test/array2.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(function(){
|
||||||
|
var Array = function(){};
|
||||||
|
return new Array(1, 2, 3, 4);
|
||||||
|
})();
|
4
node_modules/uglify-js/test/unit/compress/test/array3.js
generated
vendored
Normal file
4
node_modules/uglify-js/test/unit/compress/test/array3.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(function(){
|
||||||
|
return new Array(1, 2, 3, 4);
|
||||||
|
function Array() {};
|
||||||
|
})();
|
6
node_modules/uglify-js/test/unit/compress/test/array4.js
generated
vendored
Normal file
6
node_modules/uglify-js/test/unit/compress/test/array4.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
(function(){
|
||||||
|
(function(){
|
||||||
|
return new Array(1, 2, 3);
|
||||||
|
})();
|
||||||
|
function Array(){};
|
||||||
|
})();
|
20
node_modules/uglify-js/test/unit/compress/test/assignment.js
generated
vendored
Normal file
20
node_modules/uglify-js/test/unit/compress/test/assignment.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
a=1;
|
||||||
|
b=a;
|
||||||
|
c=1;
|
||||||
|
d=b;
|
||||||
|
e=d;
|
||||||
|
longname=2;
|
||||||
|
if (longname+1) {
|
||||||
|
x=3;
|
||||||
|
if (x) var z = 7;
|
||||||
|
}
|
||||||
|
z=1,y=1,x=1
|
||||||
|
|
||||||
|
g+=1;
|
||||||
|
h=g;
|
||||||
|
|
||||||
|
++i;
|
||||||
|
j=i;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
j=i+17;
|
3
node_modules/uglify-js/test/unit/compress/test/concatstring.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/concatstring.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
var a = a + "a" + "b" + 1 + c;
|
||||||
|
var b = a + "c" + "ds" + 123 + c;
|
||||||
|
var c = a + "c" + 123 + d + "ds" + c;
|
5
node_modules/uglify-js/test/unit/compress/test/const.js
generated
vendored
Normal file
5
node_modules/uglify-js/test/unit/compress/test/const.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// test that the calculation is fold to 13
|
||||||
|
var a = 1 + 2 * 6;
|
||||||
|
|
||||||
|
// test that it isn't replaced with 0.3333 because that is more characters
|
||||||
|
var b = 1/3;
|
4
node_modules/uglify-js/test/unit/compress/test/empty-blocks.js
generated
vendored
Normal file
4
node_modules/uglify-js/test/unit/compress/test/empty-blocks.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
var x = 5;
|
||||||
|
function bar() { return --x; }
|
||||||
|
function foo() { while (bar()); }
|
||||||
|
function mak() { for(;;); }
|
10
node_modules/uglify-js/test/unit/compress/test/forstatement.js
generated
vendored
Normal file
10
node_modules/uglify-js/test/unit/compress/test/forstatement.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
a=func();
|
||||||
|
b=z;
|
||||||
|
for (a++; i < 10; i++) { alert(i); }
|
||||||
|
|
||||||
|
var z=1;
|
||||||
|
g=2;
|
||||||
|
for (; i < 10; i++) { alert(i); }
|
||||||
|
|
||||||
|
var a = 2;
|
||||||
|
for (var i = 1; i < 10; i++) { alert(i); }
|
6
node_modules/uglify-js/test/unit/compress/test/if.js
generated
vendored
Normal file
6
node_modules/uglify-js/test/unit/compress/test/if.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
var a = 1;
|
||||||
|
if (a == 1) {
|
||||||
|
a = 2;
|
||||||
|
} else {
|
||||||
|
a = 17;
|
||||||
|
}
|
9
node_modules/uglify-js/test/unit/compress/test/ifreturn.js
generated
vendored
Normal file
9
node_modules/uglify-js/test/unit/compress/test/ifreturn.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function a(b) {
|
||||||
|
if (b == 1) {
|
||||||
|
return 2;
|
||||||
|
} else {
|
||||||
|
return 17;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 3;
|
||||||
|
}
|
16
node_modules/uglify-js/test/unit/compress/test/ifreturn2.js
generated
vendored
Normal file
16
node_modules/uglify-js/test/unit/compress/test/ifreturn2.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
function x(a) {
|
||||||
|
if (typeof a === 'object')
|
||||||
|
return a;
|
||||||
|
|
||||||
|
if (a === 42)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return a * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function y(a) {
|
||||||
|
if (typeof a === 'object')
|
||||||
|
return a;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
1
node_modules/uglify-js/test/unit/compress/test/issue10.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue10.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function f() { var a; if (a = 'a') { return a; } else { return a; } }; f();
|
3
node_modules/uglify-js/test/unit/compress/test/issue11.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/issue11.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
new (A, B)
|
||||||
|
new (A || B)
|
||||||
|
new (X ? A : B)
|
1
node_modules/uglify-js/test/unit/compress/test/issue13.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue13.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a = /^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#])(?::(\d))?)?(..?$|(?:[^?#\/]\/))([^?#]*)(?:\?([^#]))?(?:#(.))?/;
|
1
node_modules/uglify-js/test/unit/compress/test/issue14.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue14.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'};
|
1
node_modules/uglify-js/test/unit/compress/test/issue16.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue16.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a = 0xC1BDCEEE;
|
4
node_modules/uglify-js/test/unit/compress/test/issue17.js
generated
vendored
Normal file
4
node_modules/uglify-js/test/unit/compress/test/issue17.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
var a = function(b) {
|
||||||
|
b();
|
||||||
|
a()
|
||||||
|
}
|
1
node_modules/uglify-js/test/unit/compress/test/issue20.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue20.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{a: 1}
|
6
node_modules/uglify-js/test/unit/compress/test/issue21.js
generated
vendored
Normal file
6
node_modules/uglify-js/test/unit/compress/test/issue21.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
var a = 0;
|
||||||
|
switch(a) {
|
||||||
|
case 0:
|
||||||
|
a++;
|
||||||
|
break;
|
||||||
|
}
|
7
node_modules/uglify-js/test/unit/compress/test/issue25.js
generated
vendored
Normal file
7
node_modules/uglify-js/test/unit/compress/test/issue25.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
label1 : {
|
||||||
|
label2 : {
|
||||||
|
break label2;
|
||||||
|
console.log(2);
|
||||||
|
}
|
||||||
|
console.log(1);
|
||||||
|
}
|
1
node_modules/uglify-js/test/unit/compress/test/issue27.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue27.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(a ? b : c) ? d : e
|
3
node_modules/uglify-js/test/unit/compress/test/issue28.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/issue28.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
o = {'.5':.5}
|
||||||
|
o = {'0.5':.5}
|
||||||
|
o = {0.5:.5}
|
1
node_modules/uglify-js/test/unit/compress/test/issue29.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue29.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
result=(function(){ return 1;})()
|
3
node_modules/uglify-js/test/unit/compress/test/issue30.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/issue30.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
var a = 1 << 3;
|
||||||
|
var b = 8 >> 1;
|
||||||
|
var c = 8 >>> 1;
|
3
node_modules/uglify-js/test/unit/compress/test/issue34.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/issue34.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
var a = {};
|
||||||
|
a["this"] = 1;
|
||||||
|
a["that"] = 2;
|
3
node_modules/uglify-js/test/unit/compress/test/issue4.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/issue4.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
var a = 2e3;
|
||||||
|
var b = 2e-3;
|
||||||
|
var c = 2e-5;
|
1
node_modules/uglify-js/test/unit/compress/test/issue48.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue48.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var s, i; s = ''; i = 0;
|
9
node_modules/uglify-js/test/unit/compress/test/issue50.js
generated
vendored
Normal file
9
node_modules/uglify-js/test/unit/compress/test/issue50.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function bar(a) {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(e) {
|
||||||
|
alert("Exception caught (foo not defined)");
|
||||||
|
}
|
||||||
|
alert(a); // 10 in FF, "[object Error]" in IE
|
||||||
|
}
|
||||||
|
bar(10);
|
1
node_modules/uglify-js/test/unit/compress/test/issue53.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue53.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
x = (y, z)
|
3
node_modules/uglify-js/test/unit/compress/test/issue54.1.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/issue54.1.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
foo.toString();
|
||||||
|
a.toString(16);
|
||||||
|
b.toString.call(c);
|
5
node_modules/uglify-js/test/unit/compress/test/issue68.js
generated
vendored
Normal file
5
node_modules/uglify-js/test/unit/compress/test/issue68.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function f() {
|
||||||
|
if (a) return;
|
||||||
|
g();
|
||||||
|
function g(){}
|
||||||
|
};
|
1
node_modules/uglify-js/test/unit/compress/test/issue69.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/issue69.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[(a,b)]
|
4
node_modules/uglify-js/test/unit/compress/test/issue9.js
generated
vendored
Normal file
4
node_modules/uglify-js/test/unit/compress/test/issue9.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
var a = {
|
||||||
|
a: 1,
|
||||||
|
b: 2, // <-- trailing comma
|
||||||
|
};
|
5
node_modules/uglify-js/test/unit/compress/test/mangle.js
generated
vendored
Normal file
5
node_modules/uglify-js/test/unit/compress/test/mangle.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(function() {
|
||||||
|
var x = function fun(a, fun, b) {
|
||||||
|
return fun;
|
||||||
|
};
|
||||||
|
}());
|
1
node_modules/uglify-js/test/unit/compress/test/null_string.js
generated
vendored
Normal file
1
node_modules/uglify-js/test/unit/compress/test/null_string.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var nullString = "\0"
|
3
node_modules/uglify-js/test/unit/compress/test/strict-equals.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/strict-equals.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
typeof a === 'string'
|
||||||
|
b + "" !== c + ""
|
||||||
|
d < e === f < g
|
3
node_modules/uglify-js/test/unit/compress/test/var.js
generated
vendored
Normal file
3
node_modules/uglify-js/test/unit/compress/test/var.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// var declarations after each other should be combined
|
||||||
|
var a = 1;
|
||||||
|
var b = 2;
|
21
node_modules/uglify-js/test/unit/compress/test/whitespace.js
generated
vendored
Normal file
21
node_modules/uglify-js/test/unit/compress/test/whitespace.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
function id(a) {
|
||||||
|
// Form-Feed
|
||||||
|
// Vertical Tab
|
||||||
|
// No-Break Space
|
||||||
|
// Mongolian Vowel Separator
|
||||||
|
// En quad
|
||||||
|
// Em quad
|
||||||
|
// En space
|
||||||
|
// Em space
|
||||||
|
// Three-Per-Em Space
|
||||||
|
// Four-Per-Em Space
|
||||||
|
// Six-Per-Em Space
|
||||||
|
// Figure Space
|
||||||
|
// Punctuation Space
|
||||||
|
// Thin Space
|
||||||
|
// Hair Space
|
||||||
|
// Narrow No-Break Space
|
||||||
|
// Medium Mathematical Space
|
||||||
|
// Ideographic Space
|
||||||
|
return a;
|
||||||
|
}
|
2
node_modules/uglify-js/test/unit/compress/test/with.js
generated
vendored
Normal file
2
node_modules/uglify-js/test/unit/compress/test/with.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
with({}) {
|
||||||
|
};
|
55
node_modules/uglify-js/test/unit/scripts.js
generated
vendored
Normal file
55
node_modules/uglify-js/test/unit/scripts.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
var fs = require('fs'),
|
||||||
|
uglify = require('uglify-js'),
|
||||||
|
jsp = uglify.parser,
|
||||||
|
nodeunit = require('nodeunit'),
|
||||||
|
path = require('path'),
|
||||||
|
pro = uglify.uglify;
|
||||||
|
|
||||||
|
var Script = process.binding('evals').Script;
|
||||||
|
|
||||||
|
var scriptsPath = __dirname;
|
||||||
|
|
||||||
|
function compress(code) {
|
||||||
|
var ast = jsp.parse(code);
|
||||||
|
ast = pro.ast_mangle(ast);
|
||||||
|
ast = pro.ast_squeeze(ast, { no_warnings: true });
|
||||||
|
ast = pro.ast_squeeze_more(ast);
|
||||||
|
return pro.gen_code(ast);
|
||||||
|
};
|
||||||
|
|
||||||
|
var testDir = path.join(scriptsPath, "compress", "test");
|
||||||
|
var expectedDir = path.join(scriptsPath, "compress", "expected");
|
||||||
|
|
||||||
|
function getTester(script) {
|
||||||
|
return function(test) {
|
||||||
|
var testPath = path.join(testDir, script);
|
||||||
|
var expectedPath = path.join(expectedDir, script);
|
||||||
|
var content = fs.readFileSync(testPath, 'utf-8');
|
||||||
|
var outputCompress = compress(content);
|
||||||
|
|
||||||
|
// Check if the noncompressdata is larger or same size as the compressed data
|
||||||
|
test.ok(content.length >= outputCompress.length);
|
||||||
|
|
||||||
|
// Check that a recompress gives the same result
|
||||||
|
var outputReCompress = compress(content);
|
||||||
|
test.equal(outputCompress, outputReCompress);
|
||||||
|
|
||||||
|
// Check if the compressed output is what is expected
|
||||||
|
var expected = fs.readFileSync(expectedPath, 'utf-8');
|
||||||
|
test.equal(outputCompress, expected.replace(/(\r?\n)+$/, ""));
|
||||||
|
|
||||||
|
test.done();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var tests = {};
|
||||||
|
|
||||||
|
var scripts = fs.readdirSync(testDir);
|
||||||
|
for (var i in scripts) {
|
||||||
|
var script = scripts[i];
|
||||||
|
if (/\.js$/.test(script)) {
|
||||||
|
tests[script] = getTester(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = nodeunit.testCase(tests);
|
17
node_modules/uglify-js/uglify-js.js
generated
vendored
Normal file
17
node_modules/uglify-js/uglify-js.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//convienence function(src, [options]);
|
||||||
|
function uglify(orig_code, options){
|
||||||
|
options || (options = {});
|
||||||
|
var jsp = uglify.parser;
|
||||||
|
var pro = uglify.uglify;
|
||||||
|
|
||||||
|
var ast = jsp.parse(orig_code, options.strict_semicolons); // parse code and get the initial AST
|
||||||
|
ast = pro.ast_mangle(ast, options.mangle_options); // get a new AST with mangled names
|
||||||
|
ast = pro.ast_squeeze(ast, options.squeeze_options); // get an AST with compression optimizations
|
||||||
|
var final_code = pro.gen_code(ast, options.gen_options); // compressed code here
|
||||||
|
return final_code;
|
||||||
|
};
|
||||||
|
|
||||||
|
uglify.parser = require("./lib/parse-js");
|
||||||
|
uglify.uglify = require("./lib/process");
|
||||||
|
|
||||||
|
module.exports = uglify
|
@ -7,11 +7,12 @@
|
|||||||
Given the absolute path of a srcModule, and a relative reference to a dstModule, return the fully resolved module name
|
Given the absolute path of a srcModule, and a relative reference to a dstModule, return the fully resolved module name
|
||||||
*/
|
*/
|
||||||
function resolveModuleName(srcModule,dstModule) {
|
function resolveModuleName(srcModule,dstModule) {
|
||||||
|
console.log("Resolving " + dstModule + " in the context of " + srcModule);
|
||||||
var src = srcModule.split("/"),
|
var src = srcModule.split("/"),
|
||||||
dst = dstModule.split("/"),
|
dst = dstModule.split("/"),
|
||||||
c;
|
c;
|
||||||
// If the destination starts with / or ./ then it's a reference to an ordinary module
|
// If the destination starts with ./ then it's a relative reference to an ordinary module
|
||||||
if(dstModule.substr(0,1) === "/" || dstModule.substr(0,2) === "./" ) {
|
if(dstModule.substr(0,2) === "./" ) {
|
||||||
// Remove the filename part of the src path
|
// Remove the filename part of the src path
|
||||||
src.splice(src.length-1,1);
|
src.splice(src.length-1,1);
|
||||||
// Process the destination path bit by bit
|
// Process the destination path bit by bit
|
||||||
@ -29,6 +30,9 @@ function resolveModuleName(srcModule,dstModule) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return src.join("/");
|
return src.join("/");
|
||||||
|
// If the destination starts with "/" then it's an absolute path
|
||||||
|
} else if(dstModule.substr(0,1) === "/") {
|
||||||
|
return dst.join("/");
|
||||||
} else {
|
} else {
|
||||||
// If there was no / or ./ then it's a built in module and the name doesn't need resolving
|
// If there was no / or ./ then it's a built in module and the name doesn't need resolving
|
||||||
return dstModule;
|
return dstModule;
|
||||||
@ -46,14 +50,14 @@ function executeModule(modName,modRoot) {
|
|||||||
exports = {},
|
exports = {},
|
||||||
module = modules[name];
|
module = modules[name];
|
||||||
if(!module) {
|
if(!module) {
|
||||||
throw new Error("Cannot find module named '" + modName + "' required by module '" + modRoot + "'");
|
throw new Error("Cannot find module named '" + modName + "' required by module '" + modRoot + "', resolved to " + name);
|
||||||
}
|
}
|
||||||
if(module.exports) {
|
if(module.exports) {
|
||||||
return module.exports;
|
return module.exports;
|
||||||
} else {
|
} else {
|
||||||
module.module(require,exports);
|
module.exports = {};
|
||||||
module.exports = exports;
|
module.module(require,module.exports,module);
|
||||||
return exports;
|
return module.exports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,15 @@ jsmodule: ../js/Navigators.js
|
|||||||
jsmodule: ../js/StoryNavigator.js
|
jsmodule: ../js/StoryNavigator.js
|
||||||
jsmodule: ../js/Main.js
|
jsmodule: ../js/Main.js
|
||||||
|
|
||||||
|
jsmodule: ../node_modules/uglify-js/lib/parse-js.js
|
||||||
|
title: lib/parse-js
|
||||||
|
jsmodule: ../node_modules/uglify-js/lib/process.js
|
||||||
|
title: lib/process
|
||||||
|
jsmodule: ../node_modules/uglify-js/lib/squeeze-more.js
|
||||||
|
title: lib/squeeze-more
|
||||||
|
jsmodule: ../node_modules/uglify-js/uglify-js.js
|
||||||
|
title: uglify-js
|
||||||
|
|
||||||
jsbootstart: BootStart.js
|
jsbootstart: BootStart.js
|
||||||
jsbootend: BootLoader.js
|
jsbootend: BootLoader.js
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user