{
  "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.5",
  "main": "./uglify-js.js",
  "bin": {
    "uglifyjs": "./bin/uglifyjs"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com:mishoo/UglifyJS.git"
  },
  "readme": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n               \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\"\nlang=\"en\" xml:lang=\"en\">\n<head>\n<title>UglifyJS &ndash; a JavaScript parser/compressor/beautifier</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<meta name=\"generator\" content=\"Org-mode\"/>\n<meta name=\"generated\" content=\"2011-12-09 14:59:08 EET\"/>\n<meta name=\"author\" content=\"Mihai Bazon\"/>\n<meta name=\"description\" content=\"a JavaScript parser/compressor/beautifier in JavaScript\"/>\n<meta name=\"keywords\" content=\"javascript, js, parser, compiler, compressor, mangle, minify, minifier\"/>\n<style type=\"text/css\">\n <!--/*--><![CDATA[/*><!--*/\n  html { font-family: Times, serif; font-size: 12pt; }\n  .title  { text-align: center; }\n  .todo   { color: red; }\n  .done   { color: green; }\n  .tag    { background-color: #add8e6; font-weight:normal }\n  .target { }\n  .timestamp { color: #bebebe; }\n  .timestamp-kwd { color: #5f9ea0; }\n  .right  {margin-left:auto; margin-right:0px;  text-align:right;}\n  .left   {margin-left:0px;  margin-right:auto; text-align:left;}\n  .center {margin-left:auto; margin-right:auto; text-align:center;}\n  p.verse { margin-left: 3% }\n  pre {\n\tborder: 1pt solid #AEBDCC;\n\tbackground-color: #F3F5F7;\n\tpadding: 5pt;\n\tfont-family: courier, monospace;\n        font-size: 90%;\n        overflow:auto;\n  }\n  table { border-collapse: collapse; }\n  td, th { vertical-align: top;  }\n  th.right  { text-align:center;  }\n  th.left   { text-align:center;   }\n  th.center { text-align:center; }\n  td.right  { text-align:right;  }\n  td.left   { text-align:left;   }\n  td.center { text-align:center; }\n  dt { font-weight: bold; }\n  div.figure { padding: 0.5em; }\n  div.figure p { text-align: center; }\n  div.inlinetask {\n    padding:10px;\n    border:2px solid gray;\n    margin:10px;\n    background: #ffffcc;\n  }\n  textarea { overflow-x: auto; }\n  .linenr { font-size:smaller }\n  .code-highlighted {background-color:#ffff00;}\n  .org-info-js_info-navigation { border-style:none; }\n  #org-info-js_console-label { font-size:10px; font-weight:bold;\n                               white-space:nowrap; }\n  .org-info-js_search-highlight {background-color:#ffff00; color:#000000;\n                                 font-weight:bold; }\n  /*]]>*/-->\n</style>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"docstyle.css\" />\n<script type=\"text/javascript\">\n<!--/*--><![CDATA[/*><!--*/\n function CodeHighlightOn(elem, id)\n {\n   var target = document.getElementById(id);\n   if(null != target) {\n     elem.cacheClassElem = elem.className;\n     elem.cacheClassTarget = target.className;\n     target.className = \"code-highlighted\";\n     elem.className   = \"code-highlighted\";\n   }\n }\n function CodeHighlightOff(elem, id)\n {\n   var target = document.getElementById(id);\n   if(elem.cacheClassElem)\n     elem.className = elem.cacheClassElem;\n   if(elem.cacheClassTarget)\n     target.className = elem.cacheClassTarget;\n }\n/*]]>*///-->\n</script>\n\n</head>\n<body>\n\n<div id=\"preamble\">\n\n</div>\n\n<div id=\"content\">\n<h1 class=\"title\">UglifyJS &ndash; a JavaScript parser/compressor/beautifier</h1>\n\n\n<div id=\"table-of-contents\">\n<h2>Table of Contents</h2>\n<div id=\"text-table-of-contents\">\n<ul>\n<li><a href=\"#sec-1\">1 UglifyJS &mdash; a JavaScript parser/compressor/beautifier </a>\n<ul>\n<li><a href=\"#sec-1-1\">1.1 Unsafe transformations </a>\n<ul>\n<li><a href=\"#sec-1-1-1\">1.1.1 Calls involving the global Array constructor </a></li>\n<li><a href=\"#sec-1-1-2\">1.1.2 <code>obj.toString()</code> ==&gt; <code>obj+“”</code> </a></li>\n</ul>\n</li>\n<li><a href=\"#sec-1-2\">1.2 Install (NPM) </a></li>\n<li><a href=\"#sec-1-3\">1.3 Install latest code from GitHub </a></li>\n<li><a href=\"#sec-1-4\">1.4 Usage </a>\n<ul>\n<li><a href=\"#sec-1-4-1\">1.4.1 API </a></li>\n<li><a href=\"#sec-1-4-2\">1.4.2 Beautifier shortcoming &ndash; no more comments </a></li>\n<li><a href=\"#sec-1-4-3\">1.4.3 Use as a code pre-processor </a></li>\n</ul>\n</li>\n<li><a href=\"#sec-1-5\">1.5 Compression &ndash; how good is it? </a></li>\n<li><a href=\"#sec-1-6\">1.6 Bugs? </a></li>\n<li><a href=\"#sec-1-7\">1.7 Links </a></li>\n<li><a href=\"#sec-1-8\">1.8 License </a></li>\n</ul>\n</li>\n</ul>\n</div>\n</div>\n\n<div id=\"outline-container-1\" class=\"outline-2\">\n<h2 id=\"sec-1\"><span class=\"section-number-2\">1</span> UglifyJS &mdash; a JavaScript parser/compressor/beautifier </h2>\n<div class=\"outline-text-2\" id=\"text-1\">\n\n\n<p>\nThis package implements a general-purpose JavaScript\nparser/compressor/beautifier toolkit.  It is developed on <a href=\"http://nodejs.org/\">NodeJS</a>, but it\nshould work on any JavaScript platform supporting the CommonJS module system\n(and if your platform of choice doesn't support CommonJS, you can easily\nimplement it, or discard the <code>exports.*</code> lines from UglifyJS sources).\n</p>\n<p>\nThe tokenizer/parser generates an abstract syntax tree from JS code.  You\ncan then traverse the AST to learn more about the code, or do various\nmanipulations on it.  This part is implemented in <a href=\"../lib/parse-js.js\">parse-js.js</a> and it's a\nport 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>.\n</p>\n<p>\n( See <a href=\"http://github.com/mishoo/cl-uglify-js\">cl-uglify-js</a> if you're looking for the Common Lisp version of\nUglifyJS. )\n</p>\n<p>\nThe second part of this package, implemented in <a href=\"../lib/process.js\">process.js</a>, inspects and\nmanipulates the AST generated by the parser to provide the following:\n</p>\n<ul>\n<li>ability to re-generate JavaScript code from the AST.  Optionally\n  indented&mdash;you can use this if you want to “beautify” a program that has\n  been compressed, so that you can inspect the source.  But you can also run\n  our code generator to print out an AST without any whitespace, so you\n  achieve compression as well.\n\n</li>\n<li>shorten variable names (usually to single characters).  Our mangler will\n  analyze the code and generate proper variable names, depending on scope\n  and usage, and is smart enough to deal with globals defined elsewhere, or\n  with <code>eval()</code> calls or <code>with{}</code> statements.  In short, if <code>eval()</code> or\n  <code>with{}</code> are used in some scope, then all variables in that scope and any\n  variables in the parent scopes will remain unmangled, and any references\n  to such variables remain unmangled as well.\n\n</li>\n<li>various small optimizations that may lead to faster code but certainly\n  lead to smaller code.  Where possible, we do the following:\n\n<ul>\n<li>foo[\"bar\"]  ==&gt;  foo.bar\n\n</li>\n<li>remove block brackets <code>{}</code>\n\n</li>\n<li>join consecutive var declarations:\n    var a = 10; var b = 20; ==&gt; var a=10,b=20;\n\n</li>\n<li>resolve simple constant expressions: 1 +2 * 3 ==&gt; 7.  We only do the\n    replacement if the result occupies less bytes; for example 1/3 would\n    translate to 0.333333333333, so in this case we don't replace it.\n\n</li>\n<li>consecutive statements in blocks are merged into a sequence; in many\n    cases, this leaves blocks with a single statement, so then we can remove\n    the block brackets.\n\n</li>\n<li>various optimizations for IF statements:\n\n<ul>\n<li>if (foo) bar(); else baz(); ==&gt; foo?bar():baz();\n</li>\n<li>if (!foo) bar(); else baz(); ==&gt; foo?baz():bar();\n</li>\n<li>if (foo) bar(); ==&gt; foo&amp;&amp;bar();\n</li>\n<li>if (!foo) bar(); ==&gt; foo||bar();\n</li>\n<li>if (foo) return bar(); else return baz(); ==&gt; return foo?bar():baz();\n</li>\n<li>if (foo) return bar(); else something(); ==&gt; {if(foo)return bar();something()}\n\n</li>\n</ul>\n\n</li>\n<li>remove some unreachable code and warn about it (code that follows a\n    <code>return</code>, <code>throw</code>, <code>break</code> or <code>continue</code> statement, except\n    function/variable declarations).\n\n</li>\n<li>act a limited version of a pre-processor (c.f. the pre-processor of\n    C/C++) to allow you to safely replace selected global symbols with\n    specified values.  When combined with the optimisations above this can\n    make UglifyJS operate slightly more like a compilation process, in\n    that when certain symbols are replaced by constant values, entire code\n    blocks may be optimised away as unreachable.\n</li>\n</ul>\n\n</li>\n</ul>\n\n\n\n</div>\n\n<div id=\"outline-container-1-1\" class=\"outline-3\">\n<h3 id=\"sec-1-1\"><span class=\"section-number-3\">1.1</span> <span class=\"target\">Unsafe transformations</span>  </h3>\n<div class=\"outline-text-3\" id=\"text-1-1\">\n\n\n<p>\nThe following transformations can in theory break code, although they're\nprobably safe in most practical cases.  To enable them you need to pass the\n<code>--unsafe</code> flag.\n</p>\n\n</div>\n\n<div id=\"outline-container-1-1-1\" class=\"outline-4\">\n<h4 id=\"sec-1-1-1\"><span class=\"section-number-4\">1.1.1</span> Calls involving the global Array constructor </h4>\n<div class=\"outline-text-4\" id=\"text-1-1-1\">\n\n\n<p>\nThe following transformations occur:\n</p>\n\n\n\n<pre class=\"src src-js\"><span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(1, 2, 3, 4)  =&gt; [1,2,3,4]\nArray(a, b, c)         =&gt; [a,b,c]\n<span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(5)           =&gt; Array(5)\n<span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(a)           =&gt; Array(a)\n</pre>\n\n\n<p>\nThese are all safe if the Array name isn't redefined.  JavaScript does allow\none to globally redefine Array (and pretty much everything, in fact) but I\npersonally don't see why would anyone do that.\n</p>\n<p>\nUglifyJS does handle the case where Array is redefined locally, or even\nglobally but with a <code>function</code> or <code>var</code> declaration.  Therefore, in the\nfollowing cases UglifyJS <b>doesn't touch</b> calls or instantiations of Array:\n</p>\n\n\n\n<pre class=\"src src-js\"><span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">case 1.  globally declared variable</span>\n  <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">Array</span>;\n  <span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(1, 2, 3);\n  Array(a, b);\n\n  <span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">or (can be declared later)</span>\n  <span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(1, 2, 3);\n  <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">Array</span>;\n\n  <span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">or (can be a function)</span>\n  <span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(1, 2, 3);\n  <span class=\"org-keyword\">function</span> <span class=\"org-function-name\">Array</span>() { ... }\n\n<span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">case 2.  declared in a function</span>\n  (<span class=\"org-keyword\">function</span>(){\n    a = <span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(1, 2, 3);\n    b = Array(5, 6);\n    <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">Array</span>;\n  })();\n\n  <span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">or</span>\n  (<span class=\"org-keyword\">function</span>(<span class=\"org-variable-name\">Array</span>){\n    <span class=\"org-keyword\">return</span> Array(5, 6, 7);\n  })();\n\n  <span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">or</span>\n  (<span class=\"org-keyword\">function</span>(){\n    <span class=\"org-keyword\">return</span> <span class=\"org-keyword\">new</span> <span class=\"org-type\">Array</span>(1, 2, 3, 4);\n    <span class=\"org-keyword\">function</span> <span class=\"org-function-name\">Array</span>() { ... }\n  })();\n\n  <span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">etc.</span>\n</pre>\n\n\n</div>\n\n</div>\n\n<div id=\"outline-container-1-1-2\" class=\"outline-4\">\n<h4 id=\"sec-1-1-2\"><span class=\"section-number-4\">1.1.2</span> <code>obj.toString()</code> ==&gt; <code>obj+“”</code> </h4>\n<div class=\"outline-text-4\" id=\"text-1-1-2\">\n\n\n</div>\n</div>\n\n</div>\n\n<div id=\"outline-container-1-2\" class=\"outline-3\">\n<h3 id=\"sec-1-2\"><span class=\"section-number-3\">1.2</span> Install (NPM) </h3>\n<div class=\"outline-text-3\" id=\"text-1-2\">\n\n\n<p>\nUglifyJS is now available through NPM &mdash; <code>npm install uglify-js</code> should do\nthe job.\n</p>\n</div>\n\n</div>\n\n<div id=\"outline-container-1-3\" class=\"outline-3\">\n<h3 id=\"sec-1-3\"><span class=\"section-number-3\">1.3</span> Install latest code from GitHub </h3>\n<div class=\"outline-text-3\" id=\"text-1-3\">\n\n\n\n\n\n<pre class=\"src src-sh\"><span class=\"org-comment-delimiter\">## </span><span class=\"org-comment\">clone the repository</span>\nmkdir -p /where/you/wanna/put/it\n<span class=\"org-builtin\">cd</span> /where/you/wanna/put/it\ngit clone git://github.com/mishoo/UglifyJS.git\n\n<span class=\"org-comment-delimiter\">## </span><span class=\"org-comment\">make the module available to Node</span>\nmkdir -p ~/.node_libraries/\n<span class=\"org-builtin\">cd</span> ~/.node_libraries/\nln -s /where/you/wanna/put/it/UglifyJS/uglify-js.js\n\n<span class=\"org-comment-delimiter\">## </span><span class=\"org-comment\">and if you want the CLI script too:</span>\nmkdir -p ~/bin\n<span class=\"org-builtin\">cd</span> ~/bin\nln -s /where/you/wanna/put/it/UglifyJS/bin/uglifyjs\n  <span class=\"org-comment-delimiter\"># </span><span class=\"org-comment\">(then add ~/bin to your $PATH if it's not there already)</span>\n</pre>\n\n\n</div>\n\n</div>\n\n<div id=\"outline-container-1-4\" class=\"outline-3\">\n<h3 id=\"sec-1-4\"><span class=\"section-number-3\">1.4</span> Usage </h3>\n<div class=\"outline-text-3\" id=\"text-1-4\">\n\n\n<p>\nThere is a command-line tool that exposes the functionality of this library\nfor your shell-scripting needs:\n</p>\n\n\n\n<pre class=\"src src-sh\">uglifyjs [ options... ] [ filename ]\n</pre>\n\n\n<p>\n<code>filename</code> should be the last argument and should name the file from which\nto read the JavaScript code.  If you don't specify it, it will read code\nfrom STDIN.\n</p>\n<p>\nSupported options:\n</p>\n<ul>\n<li><code>-b</code> or <code>--beautify</code> &mdash; output indented code; when passed, additional\n  options control the beautifier:\n\n<ul>\n<li><code>-i N</code> or <code>--indent N</code> &mdash; indentation level (number of spaces)\n\n</li>\n<li><code>-q</code> or <code>--quote-keys</code> &mdash; quote keys in literal objects (by default,\n    only keys that cannot be identifier names will be quotes).\n\n</li>\n</ul>\n\n</li>\n<li><code>--ascii</code> &mdash; pass this argument to encode non-ASCII characters as\n  <code>\\uXXXX</code> sequences.  By default UglifyJS won't bother to do it and will\n  output Unicode characters instead.  (the output is always encoded in UTF8,\n  but if you pass this option you'll only get ASCII).\n\n</li>\n<li><code>-nm</code> or <code>--no-mangle</code> &mdash; don't mangle names.\n\n</li>\n<li><code>-nmf</code> or <code>--no-mangle-functions</code> &ndash; in case you want to mangle variable\n  names, but not touch function names.\n\n</li>\n<li><code>-ns</code> or <code>--no-squeeze</code> &mdash; don't call <code>ast_squeeze()</code> (which does various\n  optimizations that result in smaller, less readable code).\n\n</li>\n<li><code>-mt</code> or <code>--mangle-toplevel</code> &mdash; mangle names in the toplevel scope too\n  (by default we don't do this).\n\n</li>\n<li><code>--no-seqs</code> &mdash; when <code>ast_squeeze()</code> is called (thus, unless you pass\n  <code>--no-squeeze</code>) it will reduce consecutive statements in blocks into a\n  sequence.  For example, \"a = 10; b = 20; foo();\" will be written as\n  \"a=10,b=20,foo();\".  In various occasions, this allows us to discard the\n  block brackets (since the block becomes a single statement).  This is ON\n  by default because it seems safe and saves a few hundred bytes on some\n  libs that I tested it on, but pass <code>--no-seqs</code> to disable it.\n\n</li>\n<li><code>--no-dead-code</code> &mdash; by default, UglifyJS will remove code that is\n  obviously unreachable (code that follows a <code>return</code>, <code>throw</code>, <code>break</code> or\n  <code>continue</code> statement and is not a function/variable declaration).  Pass\n  this option to disable this optimization.\n\n</li>\n<li><code>-nc</code> or <code>--no-copyright</code> &mdash; by default, <code>uglifyjs</code> will keep the initial\n  comment tokens in the generated code (assumed to be copyright information\n  etc.).  If you pass this it will discard it.\n\n</li>\n<li><code>-o filename</code> or <code>--output filename</code> &mdash; put the result in <code>filename</code>.  If\n  this isn't given, the result goes to standard output (or see next one).\n\n</li>\n<li><code>--overwrite</code> &mdash; if the code is read from a file (not from STDIN) and you\n  pass <code>--overwrite</code> then the output will be written in the same file.\n\n</li>\n<li><code>--ast</code> &mdash; pass this if you want to get the Abstract Syntax Tree instead\n  of JavaScript as output.  Useful for debugging or learning more about the\n  internals.\n\n</li>\n<li><code>-v</code> or <code>--verbose</code> &mdash; output some notes on STDERR (for now just how long\n  each operation takes).\n\n</li>\n<li><code>-d SYMBOL[=VALUE]</code> or <code>--define SYMBOL[=VALUE]</code> &mdash; will replace\n  all instances of the specified symbol where used as an identifier\n  (except where symbol has properly declared by a var declaration or\n  use as function parameter or similar) with the specified value. This\n  argument may be specified multiple times to define multiple\n  symbols - if no value is specified the symbol will be replaced with\n  the value <code>true</code>, or you can specify a numeric value (such as\n  <code>1024</code>), a quoted string value (such as =\"object\"= or\n  ='https://github.com'<code>), or the name of another symbol or keyword   (such as =null</code> or <code>document</code>).\n  This allows you, for example, to assign meaningful names to key\n  constant values but discard the symbolic names in the uglified\n  version for brevity/efficiency, or when used wth care, allows\n  UglifyJS to operate as a form of <b>conditional compilation</b>\n  whereby defining appropriate values may, by dint of the constant\n  folding and dead code removal features above, remove entire\n  superfluous code blocks (e.g. completely remove instrumentation or\n  trace code for production use).\n  Where string values are being defined, the handling of quotes are\n  likely to be subject to the specifics of your command shell\n  environment, so you may need to experiment with quoting styles\n  depending on your platform, or you may find the option\n  <code>--define-from-module</code> more suitable for use.\n\n</li>\n<li><code>-define-from-module SOMEMODULE</code> &mdash; will load the named module (as\n  per the NodeJS <code>require()</code> function) and iterate all the exported\n  properties of the module defining them as symbol names to be defined\n  (as if by the <code>--define</code> option) per the name of each property\n  (i.e. without the module name prefix) and given the value of the\n  property. This is a much easier way to handle and document groups of\n  symbols to be defined rather than a large number of <code>--define</code>\n  options.\n\n</li>\n<li><code>--unsafe</code> &mdash; enable other additional optimizations that are known to be\n  unsafe in some contrived situations, but could still be generally useful.\n  For now only these:\n\n<ul>\n<li>foo.toString()  ==&gt;  foo+\"\"\n</li>\n<li>new Array(x,&hellip;)  ==&gt; [x,&hellip;]\n</li>\n<li>new Array(x) ==&gt; Array(x)\n\n</li>\n</ul>\n\n</li>\n<li><code>--max-line-len</code> (default 32K characters) &mdash; add a newline after around\n  32K characters.  I've seen both FF and Chrome croak when all the code was\n  on a single line of around 670K.  Pass &ndash;max-line-len 0 to disable this\n  safety feature.\n\n</li>\n<li><code>--reserved-names</code> &mdash; some libraries rely on certain names to be used, as\n  pointed out in issue #92 and #81, so this option allow you to exclude such\n  names from the mangler.  For example, to keep names <code>require</code> and <code>$super</code>\n  intact you'd specify &ndash;reserved-names \"require,$super\".\n\n</li>\n<li><code>--inline-script</code> &ndash; when you want to include the output literally in an\n  HTML <code>&lt;script&gt;</code> tag you can use this option to prevent <code>&lt;/script</code> from\n  showing up in the output.\n\n</li>\n<li><code>--lift-vars</code> &ndash; when you pass this, UglifyJS will apply the following\n  transformations (see the notes in API, <code>ast_lift_variables</code>):\n\n<ul>\n<li>put all <code>var</code> declarations at the start of the scope\n</li>\n<li>make sure a variable is declared only once\n</li>\n<li>discard unused function arguments\n</li>\n<li>discard unused inner (named) functions\n</li>\n<li>finally, try to merge assignments into that one <code>var</code> declaration, if\n    possible.\n</li>\n</ul>\n\n</li>\n</ul>\n\n\n\n</div>\n\n<div id=\"outline-container-1-4-1\" class=\"outline-4\">\n<h4 id=\"sec-1-4-1\"><span class=\"section-number-4\">1.4.1</span> API </h4>\n<div class=\"outline-text-4\" id=\"text-1-4-1\">\n\n\n<p>\nTo use the library from JavaScript, you'd do the following (example for\nNodeJS):\n</p>\n\n\n\n<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;\n<span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">pro</span> = require(<span class=\"org-string\">\"uglify-js\"</span>).uglify;\n\n<span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">orig_code</span> = <span class=\"org-string\">\"... JS code here\"</span>;\n<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>\nast = pro.ast_mangle(ast); <span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">get a new AST with mangled names</span>\nast = pro.ast_squeeze(ast); <span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">get an AST with compression optimizations</span>\n<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>\n</pre>\n\n\n<p>\nThe above performs the full compression that is possible right now.  As you\ncan see, there are a sequence of steps which you can apply.  For example if\nyou want compressed output but for some reason you don't want to mangle\nvariable names, you would simply skip the line that calls\n<code>pro.ast_mangle(ast)</code>.\n</p>\n<p>\nSome of these functions take optional arguments.  Here's a description:\n</p>\n<ul>\n<li><code>jsp.parse(code, strict_semicolons)</code> &ndash; parses JS code and returns an AST.\n  <code>strict_semicolons</code> is optional and defaults to <code>false</code>.  If you pass\n  <code>true</code> then the parser will throw an error when it expects a semicolon and\n  it doesn't find it.  For most JS code you don't want that, but it's useful\n  if you want to strictly sanitize your code.\n\n</li>\n<li><code>pro.ast_lift_variables(ast)</code> &ndash; merge and move <code>var</code> declarations to the\n  scop of the scope; discard unused function arguments or variables; discard\n  unused (named) inner functions.  It also tries to merge assignments\n  following the <code>var</code> declaration into it.\n\n<p>\n  If your code is very hand-optimized concerning <code>var</code> declarations, this\n  lifting variable declarations might actually increase size.  For me it\n  helps out.  On jQuery it adds 865 bytes (243 after gzip).  YMMV.  Also\n  note that (since it's not enabled by default) this operation isn't yet\n  heavily tested (please report if you find issues!).\n</p>\n<p>\n  Note that although it might increase the image size (on jQuery it gains\n  865 bytes, 243 after gzip) it's technically more correct: in certain\n  situations, dead code removal might drop variable declarations, which\n  would not happen if the variables are lifted in advance.\n</p>\n<p>\n  Here's an example of what it does:\n</p></li>\n</ul>\n\n\n\n\n\n<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>) {\n    <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">q</span>;\n    <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">w</span>;\n    w = 10;\n    q = 20;\n    <span class=\"org-keyword\">for</span> (<span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">i</span> = 1; i &lt; 10; ++i) {\n        <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">boo</span> = foo(a);\n    }\n    <span class=\"org-keyword\">for</span> (<span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">i</span> = 0; i &lt; 1; ++i) {\n        <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">boo</span> = bar(c);\n    }\n    <span class=\"org-keyword\">function</span> <span class=\"org-function-name\">foo</span>(){ ... }\n    <span class=\"org-keyword\">function</span> <span class=\"org-function-name\">bar</span>(){ ... }\n    <span class=\"org-keyword\">function</span> <span class=\"org-function-name\">baz</span>(){ ... }\n}\n\n<span class=\"org-comment-delimiter\">// </span><span class=\"org-comment\">transforms into ==&gt;</span>\n\n<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>) {\n    <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;\n    <span class=\"org-keyword\">for</span> (i = 1; i &lt; 10; ++i) {\n        boo = foo(a);\n    }\n    <span class=\"org-keyword\">for</span> (i = 0; i &lt; 1; ++i) {\n        boo = bar(c);\n    }\n    <span class=\"org-keyword\">function</span> <span class=\"org-function-name\">foo</span>() { ... }\n    <span class=\"org-keyword\">function</span> <span class=\"org-function-name\">bar</span>() { ... }\n}\n</pre>\n\n\n<ul>\n<li><code>pro.ast_mangle(ast, options)</code> &ndash; generates a new AST containing mangled\n  (compressed) variable and function names.  It supports the following\n  options:\n\n<ul>\n<li><code>toplevel</code> &ndash; mangle toplevel names (by default we don't touch them).\n</li>\n<li><code>except</code> &ndash; an array of names to exclude from compression.\n</li>\n<li><code>defines</code> &ndash; an object with properties named after symbols to\n    replace (see the <code>--define</code> option for the script) and the values\n    representing the AST replacement value.\n\n</li>\n</ul>\n\n</li>\n<li><code>pro.ast_squeeze(ast, options)</code> &ndash; employs further optimizations designed\n  to reduce the size of the code that <code>gen_code</code> would generate from the\n  AST.  Returns a new AST.  <code>options</code> can be a hash; the supported options\n  are:\n\n<ul>\n<li><code>make_seqs</code> (default true) which will cause consecutive statements in a\n    block to be merged using the \"sequence\" (comma) operator\n\n</li>\n<li><code>dead_code</code> (default true) which will remove unreachable code.\n\n</li>\n</ul>\n\n</li>\n<li><code>pro.gen_code(ast, options)</code> &ndash; generates JS code from the AST.  By\n  default it's minified, but using the <code>options</code> argument you can get nicely\n  formatted output.  <code>options</code> is, well, optional :-) and if you pass it it\n  must be an object and supports the following properties (below you can see\n  the default values):\n\n<ul>\n<li><code>beautify: false</code> &ndash; pass <code>true</code> if you want indented output\n</li>\n<li><code>indent_start: 0</code> (only applies when <code>beautify</code> is <code>true</code>) &ndash; initial\n    indentation in spaces\n</li>\n<li><code>indent_level: 4</code> (only applies when <code>beautify</code> is <code>true</code>) --\n    indentation level, in spaces (pass an even number)\n</li>\n<li><code>quote_keys: false</code> &ndash; if you pass <code>true</code> it will quote all keys in\n    literal objects\n</li>\n<li><code>space_colon: false</code> (only applies when <code>beautify</code> is <code>true</code>) &ndash; wether\n    to put a space before the colon in object literals\n</li>\n<li><code>ascii_only: false</code> &ndash; pass <code>true</code> if you want to encode non-ASCII\n    characters as <code>\\uXXXX</code>.\n</li>\n<li><code>inline_script: false</code> &ndash; pass <code>true</code> to escape occurrences of\n    <code>&lt;/script</code> in strings\n</li>\n</ul>\n\n</li>\n</ul>\n\n\n</div>\n\n</div>\n\n<div id=\"outline-container-1-4-2\" class=\"outline-4\">\n<h4 id=\"sec-1-4-2\"><span class=\"section-number-4\">1.4.2</span> Beautifier shortcoming &ndash; no more comments </h4>\n<div class=\"outline-text-4\" id=\"text-1-4-2\">\n\n\n<p>\nThe beautifier can be used as a general purpose indentation tool.  It's\nuseful when you want to make a minified file readable.  One limitation,\nthough, is that it discards all comments, so you don't really want to use it\nto reformat your code, unless you don't have, or don't care about, comments.\n</p>\n<p>\nIn fact it's not the beautifier who discards comments &mdash; they are dumped at\nthe parsing stage, when we build the initial AST.  Comments don't really\nmake sense in the AST, and while we could add nodes for them, it would be\ninconvenient because we'd have to add special rules to ignore them at all\nthe processing stages.\n</p>\n</div>\n\n</div>\n\n<div id=\"outline-container-1-4-3\" class=\"outline-4\">\n<h4 id=\"sec-1-4-3\"><span class=\"section-number-4\">1.4.3</span> Use as a code pre-processor </h4>\n<div class=\"outline-text-4\" id=\"text-1-4-3\">\n\n\n<p>\nThe <code>--define</code> option can be used, particularly when combined with the\nconstant folding logic, as a form of pre-processor to enable or remove\nparticular constructions, such as might be used for instrumenting\ndevelopment code, or to produce variations aimed at a specific\nplatform.\n</p>\n<p>\nThe code below illustrates the way this can be done, and how the\nsymbol replacement is performed.\n</p>\n\n\n\n<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>) {\n    DEVMODE = <span class=\"org-constant\">true</span>;\n}\n\n<span class=\"org-function-name\">CLAUSE2</span>: <span class=\"org-keyword\">function</span> init() {\n    <span class=\"org-keyword\">if</span> (DEVMODE) {\n        console.log(<span class=\"org-string\">\"init() called\"</span>);\n    }\n    ....\n    DEVMODE &amp;amp;&amp;amp; console.log(<span class=\"org-string\">\"init() complete\"</span>);\n}\n\n<span class=\"org-function-name\">CLAUSE3</span>: <span class=\"org-keyword\">function</span> reportDeviceStatus(<span class=\"org-variable-name\">device</span>) {\n    <span class=\"org-keyword\">var</span> <span class=\"org-variable-name\">DEVMODE</span> = device.mode, <span class=\"org-variable-name\">DEVNAME</span> = device.name;\n    <span class=\"org-keyword\">if</span> (DEVMODE === <span class=\"org-string\">'open'</span>) {\n        ....\n    }\n}\n</pre>\n\n\n<p>\nWhen the above code is normally executed, the undeclared global\nvariable <code>DEVMODE</code> will be assigned the value <b>true</b> (see <code>CLAUSE1</code>)\nand so the <code>init()</code> function (<code>CLAUSE2</code>) will write messages to the\nconsole log when executed, but in <code>CLAUSE3</code> a locally declared\nvariable will mask access to the <code>DEVMODE</code> global symbol.\n</p>\n<p>\nIf the above code is processed by UglifyJS with an argument of\n<code>--define DEVMODE=false</code> then UglifyJS will replace <code>DEVMODE</code> with the\nboolean constant value <b>false</b> within <code>CLAUSE1</code> and <code>CLAUSE2</code>, but it\nwill leave <code>CLAUSE3</code> as it stands because there <code>DEVMODE</code> resolves to\na validly declared variable.\n</p>\n<p>\nAnd more so, the constant-folding features of UglifyJS will recognise\nthat the <code>if</code> condition of <code>CLAUSE1</code> is thus always false, and so will\nremove the test and body of <code>CLAUSE1</code> altogether (including the\notherwise slightly problematical statement <code>false = true;</code> which it\nwill have formed by replacing <code>DEVMODE</code> in the body).  Similarly,\nwithin <code>CLAUSE2</code> both calls to <code>console.log()</code> will be removed\naltogether.\n</p>\n<p>\nIn this way you can mimic, to a limited degree, the functionality of\nthe C/C++ pre-processor to enable or completely remove blocks\ndepending on how certain symbols are defined - perhaps using UglifyJS\nto generate different versions of source aimed at different\nenvironments\n</p>\n<p>\nIt is recommmended (but not made mandatory) that symbols designed for\nthis purpose are given names consisting of <code>UPPER_CASE_LETTERS</code> to\ndistinguish them from other (normal) symbols and avoid the sort of\nclash that <code>CLAUSE3</code> above illustrates.\n</p>\n</div>\n</div>\n\n</div>\n\n<div id=\"outline-container-1-5\" class=\"outline-3\">\n<h3 id=\"sec-1-5\"><span class=\"section-number-3\">1.5</span> Compression &ndash; how good is it? </h3>\n<div class=\"outline-text-3\" id=\"text-1-5\">\n\n\n<p>\nHere are updated statistics.  (I also updated my Google Closure and YUI\ninstallations).\n</p>\n<p>\nWe're still a lot better than YUI in terms of compression, though slightly\nslower.  We're still a lot faster than Closure, and compression after gzip\nis comparable.\n</p>\n<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">\n<caption></caption>\n<colgroup><col class=\"left\" /><col class=\"left\" /><col class=\"right\" /><col class=\"left\" /><col class=\"right\" /><col class=\"left\" /><col class=\"right\" />\n</colgroup>\n<thead>\n<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>\n</thead>\n<tbody>\n<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>\n<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>\n<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>\n<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>\n</tbody>\n</table>\n\n\n</div>\n\n</div>\n\n<div id=\"outline-container-1-6\" class=\"outline-3\">\n<h3 id=\"sec-1-6\"><span class=\"section-number-3\">1.6</span> Bugs? </h3>\n<div class=\"outline-text-3\" id=\"text-1-6\">\n\n\n<p>\nUnfortunately, for the time being there is no automated test suite.  But I\nran the compressor manually on non-trivial code, and then I tested that the\ngenerated code works as expected.  A few hundred times.\n</p>\n<p>\nDynarchLIB was started in times when there was no good JS minifier.\nTherefore I was quite religious about trying to write short code manually,\nand 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\n= 10 : b = 20”, though the more readable version would clearly be to use\n“if/else”.\n</p>\n<p>\nSince the parser/compressor runs fine on DL and jQuery, I'm quite confident\nthat it's solid enough for production use.  If you can identify any bugs,\nI'd love to hear about them (<a href=\"http://groups.google.com/group/uglifyjs\">use the Google Group</a> or email me directly).\n</p>\n</div>\n\n</div>\n\n<div id=\"outline-container-1-7\" class=\"outline-3\">\n<h3 id=\"sec-1-7\"><span class=\"section-number-3\">1.7</span> Links </h3>\n<div class=\"outline-text-3\" id=\"text-1-7\">\n\n\n<ul>\n<li>Twitter: <a href=\"http://twitter.com/UglifyJS\">@UglifyJS</a>\n</li>\n<li>Project at GitHub: <a href=\"http://github.com/mishoo/UglifyJS\">http://github.com/mishoo/UglifyJS</a>\n</li>\n<li>Google Group: <a href=\"http://groups.google.com/group/uglifyjs\">http://groups.google.com/group/uglifyjs</a>\n</li>\n<li>Common Lisp JS parser: <a href=\"http://marijn.haverbeke.nl/parse-js/\">http://marijn.haverbeke.nl/parse-js/</a>\n</li>\n<li>JS-to-Lisp compiler: <a href=\"http://github.com/marijnh/js\">http://github.com/marijnh/js</a>\n</li>\n<li>Common Lisp JS uglifier: <a href=\"http://github.com/mishoo/cl-uglify-js\">http://github.com/mishoo/cl-uglify-js</a>\n</li>\n</ul>\n\n\n</div>\n\n</div>\n\n<div id=\"outline-container-1-8\" class=\"outline-3\">\n<h3 id=\"sec-1-8\"><span class=\"section-number-3\">1.8</span> License </h3>\n<div class=\"outline-text-3\" id=\"text-1-8\">\n\n\n<p>\nUglifyJS is released under the BSD license:\n</p>\n\n\n\n<pre class=\"example\">Copyright 2010 (c) Mihai Bazon &lt;mihai.bazon@gmail.com&gt;\nBased on parse-js (http://marijn.haverbeke.nl/parse-js/).\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions\nare met:\n\n    * Redistributions of source code must retain the above\n      copyright notice, this list of conditions and the following\n      disclaimer.\n\n    * Redistributions in binary form must reproduce the above\n      copyright notice, this list of conditions and the following\n      disclaimer in the documentation and/or other materials\n      provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY\nEXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE\nLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\nOR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\nPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\nTORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\nTHE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGE.\n</pre>\n\n\n<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes: </h2>\n<div id=\"text-footnotes\">\n<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\n    <a href=\"http://marijn.haverbeke.nl/parse-js/\">parse-js</a> library, and Marijn pushed fixes literally in minutes.\n</p></div>\n</div>\n</div>\n\n</div>\n</div>\n</div>\n\n<div id=\"postamble\">\n<p class=\"date\">Date: 2011-12-09 14:59:08 EET</p>\n<p class=\"author\">Author: Mihai Bazon</p>\n<p class=\"creator\">Org version 7.7 with Emacs version 23</p>\n<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>\n\n</div>\n</body>\n</html>\n",
  "readmeFilename": "README.html",
  "_id": "uglify-js@1.2.5",
  "_from": "uglify-js@1.2.5"
}
