uglify-js
Advanced tools
Comparing version 2.2.2 to 2.2.3
@@ -343,19 +343,21 @@ /*********************************************************************** | ||
function DEFPRINT(nodetype, generator) { | ||
nodetype.DEFMETHOD("print", function(stream, force_parens){ | ||
var self = this; | ||
stream.push_node(self); | ||
if (force_parens || self.needs_parens(stream)) { | ||
stream.with_parens(function(){ | ||
self.add_comments(stream); | ||
self.add_source_map(stream); | ||
generator(self, stream); | ||
}); | ||
} else { | ||
nodetype.DEFMETHOD("_codegen", generator); | ||
}; | ||
AST_Node.DEFMETHOD("print", function(stream, force_parens){ | ||
var self = this, generator = self._codegen; | ||
stream.push_node(self); | ||
if (force_parens || self.needs_parens(stream)) { | ||
stream.with_parens(function(){ | ||
self.add_comments(stream); | ||
self.add_source_map(stream); | ||
generator(self, stream); | ||
} | ||
stream.pop_node(); | ||
}); | ||
}; | ||
}); | ||
} else { | ||
self.add_comments(stream); | ||
self.add_source_map(stream); | ||
generator(self, stream); | ||
} | ||
stream.pop_node(); | ||
}); | ||
@@ -730,3 +732,3 @@ AST_Node.DEFMETHOD("print_to_string", function(options){ | ||
if (!self.body) | ||
return output.semicolon(); | ||
return output.force_semicolon(); | ||
if (self.body instanceof AST_Do | ||
@@ -755,3 +757,3 @@ && output.option("ie_proof")) { | ||
} | ||
self.body.print(output); | ||
force_statement(self.body, output); | ||
}; | ||
@@ -908,3 +910,3 @@ DEFPRINT(AST_If, function(self, output){ | ||
output.space(); | ||
AST_Call.prototype.print.call(self, output); | ||
AST_Call.prototype._codegen(self, output); | ||
}); | ||
@@ -911,0 +913,0 @@ |
@@ -884,7 +884,10 @@ /*********************************************************************** | ||
var function_ = function(in_statement, ctor) { | ||
var name = is("name") ? as_symbol(in_statement | ||
? AST_SymbolDefun | ||
: ctor === AST_Accessor | ||
? AST_SymbolAccessor | ||
: AST_SymbolLambda) : null; | ||
var is_accessor = ctor === AST_Accessor; | ||
var name = (is("name") ? as_symbol(in_statement | ||
? AST_SymbolDefun | ||
: is_accessor | ||
? AST_SymbolAccessor | ||
: AST_SymbolLambda) | ||
: is_accessor && (is("string") || is("num")) ? as_atom_node() | ||
: null); | ||
if (in_statement && !name) | ||
@@ -891,0 +894,0 @@ unexpected(); |
@@ -87,5 +87,8 @@ /*********************************************************************** | ||
var save_scope = node.parent_scope = scope; | ||
var save_labels = labels; | ||
++nesting; | ||
scope = node; | ||
labels = new Dictionary(); | ||
descend(); | ||
labels = save_labels; | ||
scope = save_scope; | ||
@@ -344,2 +347,3 @@ --nesting; | ||
eval : false, | ||
sort : false | ||
}); | ||
@@ -365,8 +369,12 @@ }); | ||
if (node instanceof AST_Scope) { | ||
var p = tw.parent(); | ||
var p = tw.parent(), a = []; | ||
node.variables.each(function(symbol){ | ||
if (options.except.indexOf(symbol.name) < 0) { | ||
to_mangle.push(symbol); | ||
a.push(symbol); | ||
} | ||
}); | ||
if (options.sort) a.sort(function(a, b){ | ||
return b.references.length - a.references.length; | ||
}); | ||
to_mangle.push.apply(to_mangle, a); | ||
return; | ||
@@ -373,0 +381,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"main": "tools/node.js", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"engines": { "node" : ">=0.4.0" }, | ||
@@ -9,0 +9,0 @@ "maintainers": [{ |
@@ -82,2 +82,3 @@ UglifyJS 2 | ||
-v, --verbose Verbose [boolean] | ||
-V, --version Print version number and exits. [boolean] | ||
@@ -134,3 +135,3 @@ Specify `--output` (`-o`) to declare the output file. Otherwise the output | ||
To enable the mangler you need to pass `--mangle` (`-m`). Optionally you | ||
can pass `-m sort` (we'll possibly have other flags in the future) in order | ||
can pass `-m sort=true` (we'll possibly have other flags in the future) in order | ||
to assign shorter names to most frequently used variables. This saves a few | ||
@@ -218,2 +219,3 @@ hundred bytes on jQuery before gzip, but the output is _bigger_ after gzip | ||
<a name="codegen-options"></a> | ||
## Beautifier options | ||
@@ -372,5 +374,15 @@ | ||
- `warnings` (default `false`) — pass `true` to display compressor warnings. | ||
- `fromString` (default `false`) — if you pass `true` then you can pass | ||
JavaScript source code, rather than file names. | ||
- `mangle` — pass `false` to skip mangling names. | ||
- `output` (default `null`) — pass an object if you wish to specify | ||
additional [output options][codegen]. The defaults are optimized | ||
for best compression. | ||
- `compress` (default `{}`) — pass `false` to skip compressing entirely. | ||
Pass an object to specify custom [compressor options][compressor]. | ||
We could add more options to `UglifyJS.minify` — if you need additional | ||
@@ -523,1 +535,3 @@ functionality please suggest! | ||
[sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit | ||
[codegen]: http://lisperator.net/uglifyjs/codegen | ||
[compressor]: http://lisperator.net/uglifyjs/compress |
@@ -59,2 +59,5 @@ var path = require("path"); | ||
warnings : false, | ||
mangle : {}, | ||
output : null, | ||
compress : {} | ||
}); | ||
@@ -77,12 +80,16 @@ if (typeof files == "string") | ||
// 2. compress | ||
toplevel.figure_out_scope(); | ||
var sq = UglifyJS.Compressor({ | ||
warnings: options.warnings, | ||
}); | ||
toplevel = toplevel.transform(sq); | ||
if (options.compress) { | ||
var compress = { warnings: options.warnings }; | ||
UglifyJS.merge(compress, options.compress); | ||
toplevel.figure_out_scope(); | ||
var sq = UglifyJS.Compressor(compress); | ||
toplevel = toplevel.transform(sq); | ||
} | ||
// 3. mangle | ||
toplevel.figure_out_scope(); | ||
toplevel.compute_char_frequency(); | ||
toplevel.mangle_names(); | ||
if (options.mangle) { | ||
toplevel.figure_out_scope(); | ||
toplevel.compute_char_frequency(); | ||
toplevel.mangle_names(options.mangle); | ||
} | ||
@@ -100,3 +107,7 @@ // 4. output | ||
}); | ||
var stream = UglifyJS.OutputStream({ source_map: map }); | ||
var output = { source_map: map }; | ||
if (options.output) { | ||
UglifyJS.merge(output, options.output); | ||
} | ||
var stream = UglifyJS.OutputStream(output); | ||
toplevel.print(stream); | ||
@@ -103,0 +114,0 @@ return { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
320645
7816
533