-
Notifications
You must be signed in to change notification settings - Fork 10
/
README.html
367 lines (302 loc) · 10.6 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?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>cl-uglify-js -- JavaScript compressor/beautifier for Common Lisp</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2011-01-24 00:09:50 EET"/>
<meta name="author" content="Mihai Bazon"/>
<meta name="description" content="JavaScript compressor/beautifier for Common Lisp"/>
<meta name="keywords" content="javascript, js, parser, compiler, compressor, mangle, minify, minifier, common lisp"/>
<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; }
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; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
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="content">
<h1 class="title">cl-uglify-js – JavaScript compressor/beautifier for Common Lisp</h1>
<p>This is a Common Lisp version of <a href="http://github.com/mishoo/UglifyJS">UglifyJS</a>. It works on data produced by
<a href="http://marijn.haverbeke.nl/parse-js/">parse-js</a> to generate a “minified” version of the code. Currently
it can:
</p>
<ul>
<li>
reduce variable names (usually to single letters)
</li>
<li>
join consecutive <b>var</b> statements
</li>
<li>
resolve simple binary expressions
</li>
<li>
group most consecutive statements using the “sequence” operator (comma)
</li>
<li>
remove unnecessary blocks
</li>
<li>
convert IF expressions in various ways that result in smaller code
</li>
<li>
remove some unreachable code
</li>
</ul>
<p>It's faster than YUI Compressor, Google Closure <i>and</i> UglifyJS, and almost
as good as (and a bit safer than) Google Closure in terms of compressed code
size.
</p>
<p>
See the <a href="http://github.com/mishoo/UglifyJS">UglifyJS</a> page for more information.
</p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Dependencies </a></li>
<li><a href="#sec-2">2 API </a>
<ul>
<li><a href="#sec-2_1">2.1 ast-squeeze (ast &key (sequences T) (dead-code T)) </a></li>
<li><a href="#sec-2_2">2.2 ast-mangle (ast &key toplevel) </a></li>
<li><a href="#sec-2_3">2.3 ast-gen-code (ast &key (beautify T) (indent-level 4) (indent-start 0) quote-keys) </a></li>
<li><a href="#sec-2_4">2.4 split-code (code &optional (maxlen (* 32 1024))) </a></li>
</ul>
</li>
<li><a href="#sec-3">3 Compress one file </a></li>
<li><a href="#sec-4">4 License </a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-3">
<h3 id="sec-1"><span class="section-number-3">1</span> Dependencies </h3>
<div class="outline-text-3" id="text-1">
<ul>
<li>
<a href="http://marijn.haverbeke.nl/parse-js/">parse-js</a>
</li>
<li>
<a href="http://weitz.de/cl-ppcre/">cl-ppcre</a>
</li>
<li>
<a href="http://www.cliki.net/PARSE-NUMBER">parse-number</a>
</li>
<li>
<a href="http://common-lisp.net/project/iterate/">iterate</a>
</li>
</ul>
<p>I only tested it on SBCL.
</p>
</div>
</div>
<div id="outline-container-2" class="outline-3">
<h3 id="sec-2"><span class="section-number-3">2</span> API </h3>
<div class="outline-text-3" id="text-2">
<p>
The following functions are exported:
</p>
</div>
<div id="outline-container-2_1" class="outline-4">
<h4 id="sec-2_1"><span class="section-number-4">2.1</span> ast-squeeze (ast &key (sequences T) (dead-code T)) </h4>
<div class="outline-text-4" id="text-2_1">
<p>
Applies various compression techniques. It expects an AST (as returned by
<a href="http://marijn.haverbeke.nl/parse-js/">parse-js</a>) and returns a new, compatible AST (possibly sharing structure with
the original one!).
</p>
<p>
Optional keyword arguments:
</p>
<ul>
<li>
<code>sequences</code> (default <code>T</code>) — set this to <code>NIL</code> to disable grouping
consecutive statements into a sequence using the “comma operator”.
</li>
<li>
<code>dead-code</code> (default <code>T</code>) — if you pass <code>NIL</code> it will not attempt to
remove unreachable code.
</li>
</ul>
<p>When it encounters unreachable code and <code>dead-code</code> is <b>true</b>, this function
will <code>warn</code> about it. The warnings go to <code>*error-output*</code>, so rebind that
if you want to catch the messages.
</p>
</div>
</div>
<div id="outline-container-2_2" class="outline-4">
<h4 id="sec-2_2"><span class="section-number-4">2.2</span> ast-mangle (ast &key toplevel) </h4>
<div class="outline-text-4" id="text-2_2">
<p>
“Mangles” variable names (renames all variables to shorter version). This
function is careful not to affect the semantics of the code. It will avoid
renaming undeclared variables (which could possibly be defined in some other
script), and avoid renaming names that are under the influence of a <b>with</b>
block, or within the context of an <b>eval</b> call.
</p>
<p>
Optional keyword arguments:
</p>
<ul>
<li>
<code>toplevel</code> (default <code>NIL</code>) — pass <b>true</b> here if you want to mangle the
toplevel scope. By default we don't.
</li>
</ul>
<p>Note that this function returns a somewhat incompatible AST. Literal names
(which are normally strings) are replaced with lambda-s that would return
the mangled version. <code>ast-gen-code</code> knows how to deal with this.
</p>
</div>
</div>
<div id="outline-container-2_3" class="outline-4">
<h4 id="sec-2_3"><span class="section-number-4">2.3</span> ast-gen-code (ast &key (beautify T) (indent-level 4) (indent-start 0) quote-keys) </h4>
<div class="outline-text-4" id="text-2_3">
<p>
Given an abstract syntax tree, this function returns the corresponding
JavaScript code (as a string).
</p>
<p>
Optional keyword arguments:
</p>
<ul>
<li>
<code>beautify</code> (default <b>true</b>). By default ast-gen-code returns nicely
indented code. If you want to compress, pass <code>:beautify NIL</code>.
</li>
</ul>
<p>The other arguments only make sense if <code>beautify</code> is <b>true</b>:
</p>
<ul>
<li>
<code>indent-level</code>: number of spaces to use for indentation. Note that
case/default statements are indented to half of this number, so better
pass an even one.
</li>
<li>
<code>indent-start</code>: the whole code will be indented by this number of spaces
(default 0).
</li>
<li>
<code>quote-keys</code>: by default, we only quote keys that cannot be used otherwise
(i.e. reserved words such as "while"). Pass this <b>true</b> to quote all keys
regardless.
</li>
</ul>
</div>
</div>
<div id="outline-container-2_4" class="outline-4">
<h4 id="sec-2_4"><span class="section-number-4">2.4</span> split-code (code &optional (maxlen (* 32 1024))) </h4>
<div class="outline-text-4" id="text-2_4">
<p>
Given `code' (a string) it will split it by adding a newline every `maxlen'
(or so) characters. I found both Firefox and Chrome croak with weird errors
when the whole code was on a single 680K line, so even if it adds a few more
bytes this step should be done for safety. The default `maxlen' is 32K.
</p>
</div>
</div>
</div>
<div id="outline-container-3" class="outline-3">
<h3 id="sec-3"><span class="section-number-3">3</span> Compress one file </h3>
<div class="outline-text-3" id="text-3">
<p>
To compress one file, you would do something like this:
</p>
<pre class="src src-lisp">(ast-gen-code
(ast-mangle
(ast-squeeze
(<span style="color: #afeeee; font-weight: bold;">with-open-file</span> (in <span style="color: #87cefa;">"/path/to/file.js"</span>)
(parse-js:parse-js in)))) <span style="color: #7fffd4;">:beautify</span> nil)
</pre>
<p>
Some simplified API will be available at some point, though I'm not sure it
would be really useful.
</p>
</div>
</div>
<div id="outline-container-4" class="outline-3">
<h3 id="sec-4"><span class="section-number-3">4</span> License </h3>
<div class="outline-text-3" id="text-4">
<pre class="example">Copyright 2010 (c) Mihai Bazon <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
</pre>
</div>
</div>
<div id="postamble">
<p class="author"> Author: Mihai Bazon
</p>
<p class="date"> Date: 2011-01-24 00:09:50 EET</p>
<p class="creator">HTML generated by org-mode 7.01trans in emacs 23</p>
</div>
</div>
</body>
</html>