Permalink
Browse files

Consolidate null, Boolean, and String values

  • Loading branch information...
1 parent cab739c commit dfb9a63ae88dd6b079e5d1a108815f80a2a5b68e @RGustBardon RGustBardon committed Feb 28, 2012
Showing with 2,614 additions and 1 deletion.
  1. +4 −0 README.org
  2. +9 −0 bin/uglifyjs
  3. +2,599 −0 lib/consolidator.js
  4. +2 −1 uglify-js.js
View
@@ -187,6 +187,10 @@ Supported options:
- =-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,
View
@@ -4,11 +4,13 @@
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
+ consolidator = uglify.consolidator,
jsp = uglify.parser,
pro = uglify.uglify;
var options = {
ast: false,
+ consolidate: false,
mangle: true,
mangle_toplevel: false,
no_mangle_functions: false,
@@ -46,6 +48,10 @@ out: while (args.length > 0) {
case "--beautify":
options.codegen_options.beautify = true;
break;
+ case "-c":
+ case "--consolidate-primitive-values":
+ options.consolidate = true;
+ break;
case "-i":
case "--indent":
options.codegen_options.indent_level = args.shift();
@@ -278,6 +284,9 @@ function squeeze_it(code) {
}
try {
var ast = time_it("parse", function(){ return jsp.parse(code); });
+ if (options.consolidate) ast = time_it("consolidate", function(){
+ return consolidator.ast_consolidate(ast);
+ });
if (options.lift_vars) {
ast = time_it("lift", function(){ return pro.ast_lift_variables(ast); });
}
Oops, something went wrong.

0 comments on commit dfb9a63

Please sign in to comment.