#+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
* NEW: UglifyJS2
I started working on UglifyJS's successor, version 2. It's almost a full
rewrite (except for the parser which is heavily modified, everything else
starts from scratch). I've detailed my reasons in the README, see the
project page.
[[https://github.com/mishoo/UglifyJS2][https://github.com/mishoo/UglifyJS2]]
Version 1 will continue to be maintained for fixing show-stopper bugs, but
no new features should be expected.
* 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@1= should
do the job.
*NOTE:* The NPM package has been upgraded to UglifyJS2. If you need to
install version 1.x you need to add `@1` to the command, as I did above. I
strongly suggest you to try to upgrade, though this might not be simple (v2
has a completely different AST structure and API).
** 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).
- =-c= or =----consolidate-primitive-values= --- consolidates null, Boolean,
and String values. Known as aliasing in the Closure Compiler. Worsens the
data compression ratio of gzip.
- =--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 ma
没有合适的资源?快使用搜索试试~ 我知道了~
ASP实例开发源码-series iis node server engine v1.0.432.zip
共1328个文件
png:719个
js:363个
json:59个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 2 浏览量
2022-11-15
14:49:48
上传
评论
收藏 2.85MB ZIP 举报
温馨提示
ASP实例开发源码—series iis node server engine v1.0.432.zip ASP实例开发源码—series iis node server engine v1.0.432.zip ASP实例开发源码—series iis node server engine v1.0.432.zip
资源推荐
资源详情
资源评论
收起资源包目录
ASP实例开发源码-series iis node server engine v1.0.432.zip (1328个子文件)
Series.asp 203KB
Series.asp 203KB
Series.min.asp 82KB
Series.min.asp 64KB
default.asp 543B
LICENSE.BSD 1KB
web.config 575B
color-brewer.css 3KB
hybrid.css 3KB
default.css 3KB
railscasts.css 3KB
sunburst.css 2KB
monokai_sublime.css 2KB
xcode.css 2KB
obsidian.css 2KB
arta.css 2KB
googlecode.css 2KB
monokai.css 2KB
school_book.css 2KB
magula.css 2KB
zenburn.css 2KB
docco.css 2KB
atelier-lakeside.light.css 2KB
far.css 2KB
atelier-lakeside.dark.css 2KB
atelier-seaside.light.css 2KB
atelier-seaside.dark.css 2KB
atelier-forest.light.css 2KB
idea.css 2KB
atelier-forest.dark.css 2KB
atelier-heath.light.css 2KB
atelier-heath.dark.css 2KB
atelier-dune.light.css 2KB
atelier-dune.dark.css 2KB
brown_paper.css 2KB
github.css 2KB
dark.css 2KB
tomorrow-night-blue.css 2KB
tomorrow-night.css 2KB
pojoaque.css 2KB
solarized_light.css 2KB
solarized_dark.css 2KB
foundation.css 2KB
tomorrow-night-eighties.css 2KB
vs.css 2KB
tomorrow-night-bright.css 2KB
kimbie.light.css 2KB
kimbie.dark.css 2KB
codepen-embed.css 2KB
paraiso.light.css 2KB
paraiso.dark.css 2KB
ir_black.css 1KB
rainbow.css 1KB
tomorrow.css 1KB
mono-blue.css 995B
ascetic.css 842B
style.css 32B
index.ejs 3KB
index.ejs 648B
comments.ejs 387B
rmWhitespace.ejs 353B
menu_preprocessor.ejs 251B
menu.ejs 222B
menu_var.ejs 183B
newlines.mixed.ejs 131B
no.semicolons.ejs 131B
include-abspath.ejs 114B
literal.ejs 114B
include.ejs 98B
newlines.ejs 90B
no.newlines.ejs 90B
include_preprocessor.ejs 80B
messed.ejs 72B
error.ejs 63B
include_preprocessor.css.ejs 62B
include.css.ejs 60B
consecutive-tags.ejs 47B
no.newlines.error.ejs 47B
include-simple.ejs 44B
include_preprocessor_cache.ejs 43B
double-quote.ejs 41B
item.ejs 39B
fail.ejs 35B
bom.ejs 35B
single-quote.ejs 34B
include_cache.ejs 33B
menu-item.ejs 33B
user-no-with.ejs 28B
pet.ejs 25B
user.ejs 21B
hello-world.ejs 20B
para.ejs 11B
include.ejs 10B
include_preprocessor.ejs 10B
renderFile.ejs 10B
backslash.ejs 5B
expandTabs 324B
.gitignore 141B
rmWhitespace.html 227B
comments.html 179B
共 1328 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论
毕业_设计
- 粉丝: 1924
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功