Skip to content

Commit dfb9a63

Browse files
committed
Consolidate null, Boolean, and String values
1 parent cab739c commit dfb9a63

File tree

4 files changed

+2614
-1
lines changed

4 files changed

+2614
-1
lines changed

README.org

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ Supported options:
187187
- =-q= or =--quote-keys= --- quote keys in literal objects (by default,
188188
only keys that cannot be identifier names will be quotes).
189189

190+
- =-c= or =----consolidate-primitive-values= --- consolidates null, Boolean,
191+
and String values. Known as aliasing in the Closure Compiler. Worsens the
192+
data compression ratio of gzip.
193+
190194
- =--ascii= --- pass this argument to encode non-ASCII characters as
191195
=\uXXXX= sequences. By default UglifyJS won't bother to do it and will
192196
output Unicode characters instead. (the output is always encoded in UTF8,

bin/uglifyjs

+9
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
55
var fs = require("fs");
66
var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
7+
consolidator = uglify.consolidator,
78
jsp = uglify.parser,
89
pro = uglify.uglify;
910

1011
var options = {
1112
ast: false,
13+
consolidate: false,
1214
mangle: true,
1315
mangle_toplevel: false,
1416
no_mangle_functions: false,
@@ -46,6 +48,10 @@ out: while (args.length > 0) {
4648
case "--beautify":
4749
options.codegen_options.beautify = true;
4850
break;
51+
case "-c":
52+
case "--consolidate-primitive-values":
53+
options.consolidate = true;
54+
break;
4955
case "-i":
5056
case "--indent":
5157
options.codegen_options.indent_level = args.shift();
@@ -278,6 +284,9 @@ function squeeze_it(code) {
278284
}
279285
try {
280286
var ast = time_it("parse", function(){ return jsp.parse(code); });
287+
if (options.consolidate) ast = time_it("consolidate", function(){
288+
return consolidator.ast_consolidate(ast);
289+
});
281290
if (options.lift_vars) {
282291
ast = time_it("lift", function(){ return pro.ast_lift_variables(ast); });
283292
}

0 commit comments

Comments
 (0)